一、struts2:
/**
* 获取 Request 对象
* @return
*/
protected HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
/**
* 获取 Response 对象
* @return current response
*/
protected HttpServletResponse getResponse() {
return ServletActionContext.getResponse();
}
/**
* 获取Application 对象
* @return
*/
protected ServletContext getApplication() {
return ServletActionContext.getServletContext();
}
/**
* 获取Session对象
*
*/
protected HttpSession getSession() {
return getRequest().getSession();
}
二、servlet:
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
ServletContext sc = req.getSession().getServletContext();
}