标签:
1.通过ActionContext类(拿到的不是真正的servlet api,而是一个map)
ActionContext context = ActionContext.getContext();
context.getSession();
context.getApplication();
2.通过ServletActionContext类(拿到的是真正的servlet api)
ServletActionContext.getRequest();
ServletActionContext.getResponse();
ServletActionContext.getPageContext();
3.通过注入方式获取(拿到的是真正的servlet api)
* ServletContextAware、ServletRequestAware、ServletResponseAware接口
(1) 实现对应的接口:implements ServletRequestAware
(2) 声明私有属性例如 private HttpServletRequest request;
(3) 复写接口方法setsetServletRequest
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
struts2中在Action中如何获取servlet的api?
标签:
原文地址:http://www.cnblogs.com/zyh1994/p/5399495.html