• 在Action 中, 可以通过以下方式访问web 的 HttpSession, HttpServletRequest,HttpServletResponse 等资源

  • 与 Servlet API 解耦的访问方式

    • 通过: com.opensymphony.xwork2.ActionContext

    • 通过Action 实现如下接口:

      • org.apache.struts2.interceptor.ApplicationAware
      • org.apache.struts2.interceptor.RequestAware
      • org.apache.struts2.interceptor.SessionAware
    • 特点:只能访问有限的Servlet API对象,且只能访问有限的方法(读取请求参数、读写域对象属性、使session失效等)。

  • 与Servlet API 耦合的访问方式

    • 通过:com.opensymphony.xwork2.ActionContext

    • 通过实现对应的XxxAware 接口

    • 特点:访问更多的Servlet API对象,且可以调用原生的方法。


其它


Struts2_005_访问 web 资源

相关文章: