拉面菜鸟笔记——Struct2中获取request
?
1. ActionContext
在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息,甚至需要直接对JavaServlet Http的请求(HttpServletRequest),响应(HttpServletResponse)操作. 我们需要在Action中取得request请求参数"username"的值:
public class UserAction extends ActionSupport implements SessionAware, ServletRequestAware, ServletResponseAware { private HttpServletRequest request; private HttpServletResponse response; public void setServletRequest(HttpServletRequest request) { this.request = request; } public void setServletResponse(HttpServletResponse response) { this.response = response; } public String execute() { HttpSession session = request.getSession(); return SUCCESS; } }
?转载自:http://blog.csdn.net/tianlingai/archive/2010/07/02/5708433.aspx
?