struts2 Action中获取request, response对象的 几种 方法
struts2 Action中获取request, response对象的方法
第一种方法:
ActionContext ctx = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST); HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE); //ServletActionContext.APPLICATION; //ServletActionContext.SESSION; //ServletActionContext.PAGE_CONTEXT;
public class TestAction implements ServletRequestAware{ /**---*/ public void setServletRequest(HttpServletRequest request) {// 要复写这个方法request.setAttribute("key","value"); }}HttpServletRequest request = ServletActionContext.getRequest();