struts2将servlet对象注入到Action中

 在struts2框架中,可以通过IoC方式将servlet对象注入到Action中,通常需要Action实现以下接口:
  a. ServletRequestAware:
  实现该接口的Action可以直接访问Request对象,该接口中提供void setServletRequest(HttpServletRequest request)
  方法,实现此接口的Action控制类通过setServletRequestHttpServlet(HttpServlet request)方法将request对象注入到Action中。

  b. ServletResponseAware:
  Action类通过实现ServletResponseAware接口可以直接访问Response对象,与ServletRequestAware接口相似该接口通过提供void setServletResponse(HttpServlet resonse)将response对象注入到Action中,以便于可以直接使用。

  c. SessionAware:
  实现该接口的Action可以直接访问session对象,该接口中提供void setSession(Map map)方法,注入原理与request和response原理相同,都是通过实现对应接口的set方法将session对象注入到Action中。
原文地址:https://www.cnblogs.com/wdnnccey/p/5994713.html