初学积累

来源:互联网 发布:华懋科技知乎 编辑:程序博客网 时间:2024/05/29 14:32

一、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();
}