首页 > 代码库 > 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的方法