码迷,mamicode.com
首页 > 其他好文 > 详细

Struts中取得Request和Response、Session的方法

时间:2015-02-02 10:43:50      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

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的方法

标签:

原文地址:http://www.cnblogs.com/keryang/p/4250560.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!