struts访问web元素

一:获取Map类型的request,session,application
   继承ActionSupport
    Map request=(Map)ActionContext.getContext().get("request");
    Map session=ActionContext.getContext().getSession();
    Map Application=ActionContext.getContext().getApplication();

二:获取Map类型的request,session,application(常用)
   实现implements  RequestAware ,SessionAware,ApplicationAware
	public void setRequest(Map<String, Object> request) {
		this.request=request;
	}
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	public void setApplication(Map<String, Object> application) {
		this.Application= application;
	}


三:获取原始类型request,session,application
        HttpServletRequest request = ServletActionContext.getRequest();
    HttpSession session = request.getSession();
    ServletContext application = session.getServletContext();

四:获取原始类型request,session,application
     实现implements ServletRequestAware接口
	public void setServletRequest(HttpServletRequest request) {
		HttpServletRequest req =request;
		HttpSession session = request.getSession();
    	ServletContext application = session.getServletContext();
	}


你可能感兴趣的:(struts)