首页 > 代码库 > Struts中取得Request和Response、Session的方法
Struts中取得Request和Response、Session的方法
Struts中取得Request和Response、Session的方法
(一)
public HttpServletRequest request = ServletActionContext.getRequest(); public HttpServletResponse response = ServletActionContext.getResponse(); public HttpSession session= request.getSession(); public ServletContext application =session.getServletContext();
(二)
private Map request; private Map session; private Map application; public String login() { request = (Map) ActionContext.getContext().get("request"); session = ActionContext.getContext().getSession(); application =ActionContext.getContext().getApplication(); request.put("name", "admin"); session.put("name", "admin"); application.put("name", "admin"); return SUCCESS; }
(三)
public class LoginAction extends ActionSupport implements RequestAware, SessionAware, ApplicationAware{ private Map<String, Object> request; private Map<String, Object> session; private Map<String, Object> application; public String login() { request.put("name", "admin"); session.put("name", "admin"); application.put("name", "admin"); return SUCCESS; } @Override public void setApplication(Map<String, Object> application) { this.application = application; } @Override public void setSession(Map<String, Object> session) { this.session = session; } @Override public void setRequest(Map<String, Object> request) { this.request = request; }}
(四)
public class LoginAction extends ActionSupport implements ServletRequestAware{ private HttpServletRequest request; private HttpSession session; private ServletContext application; public String login() { request.setAttribute("name", "admin"); session.setAttribute("name", "admin"); application.setAttribute("name", "admin"); return SUCCESS; } @Override public void setServletRequest(HttpServletRequest request) { this.request = request; this.session = request.getSession(); this.application = session.getServletContext(); }}
Struts中取得Request和Response、Session的方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。