Struts2与Servlet实现耦合的方法
1、使用 ActionContext
ActionContext.getContext().getSession().setAttribute(key,value)
或
ActionContext.getContext().put(key,value)
HttpServletRequest setAttribute getAttribute getParameters
对应
ActionContext set put getParameterMap
2、通过实现以下接口
ServletContextAware
org.apache.struts2.util.ServletContextAware(接口)
ServletRequestAware(接口)中的setRequest方法
ServletResponseAware(接口)中的setResponse方法
3、通过类 ServletActionContext
其中的方法都是static方法
例: getRequest(), getResponse(), getActionContext()
首选ActionContext 单元测试最方便
其次ServletActionContext
最后ServletRequestAware、ServletResponseAware、ServletContextAware