标签:struts2 ioc actioncontext servletrequestaware servletresponseaware
在struts2中访问servletAPI,通俗点也就是使用servlet中的两个对象request对象和response对象。
前几天看到一个CRM项目的源码,里面使用request对象和response对象方式和我以前使用的方式有点不同,于是便上网查询一些相关资料。特此记录于此,有兴趣的也可以参考参考。
我贴上代码来看看吧。
ServletRequestAware,ServletResponseAware
package cn.crm.web.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.interceptor.ServletRequestAware; import org.apache.struts2.interceptor.ServletResponseAware; import com.opensymphony.xwork2.ActionSupport; public class BaseAction extends ActionSupport implements ServletRequestAware,ServletResponseAware{ protected HttpServletRequest request; protected HttpServletResponse response; @Override public void setServletResponse(HttpServletResponse response) { // TODO Auto-generated method stub this.response=response; } @Override public void setServletRequest(HttpServletRequest request) { // TODO Auto-generated method stub this.request=request; } }ActionContext
ActionContext context = ActionContext.getContext(); Map params = context.getParameters(); String username = (String) params.get("username");
HttpServletRequest request = ServletActionContext. getRequest(); HttpSession session = ServletActionContext. getRequest().getSession();
标签:struts2 ioc actioncontext servletrequestaware servletresponseaware
原文地址:http://blog.csdn.net/u013239111/article/details/39738473