| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
11年前发布

Struts2中获取http请求对象的各种方法

import java.util.Map;  import javax.servlet.ServletContext;  import javax.servlet.http.HttpServletRequest;  import javax.servlet.http.HttpServletResponse;  import javax.servlet.http.HttpSession;  import org.apache.struts2.ServletActionContext;  import org.apache.struts2.interceptor.ApplicationAware;  import org.apache.struts2.interceptor.RequestAware;  import org.apache.struts2.interceptor.ServletRequestAware;  import org.apache.struts2.interceptor.ServletResponseAware;  import org.apache.struts2.interceptor.SessionAware;  import org.apache.struts2.util.ServletContextAware;    import com.opensymphony.xwork2.ActionContext;  import com.opensymphony.xwork2.ActionSupport;    @SuppressWarnings( { "serial", "unused", "unchecked" })  public class GetHttp extends ActionSupport implements ServletRequestAware,    ServletResponseAware, RequestAware, SessionAware, ServletContextAware,    ApplicationAware {     private HttpServletRequest request;     private HttpServletResponse response;     private HttpSession session;     private Map<String, Object> requestMap, sessionMap, contextMap;     private ServletContext context;     @Override   public String execute() throws Exception {    this.request = ServletActionContext.getRequest();    this.request = (HttpServletRequest) ActionContext.getContext().get(      ServletActionContext.HTTP_REQUEST);      this.session = this.request.getSession();    this.sessionMap = ActionContext.getContext().getSession();    this.sessionMap = ServletActionContext.getContext().getSession();// 调用父类ActionContext的方法    this.sessionMap = (Map<String, Object>) ActionContext.getContext().get(      ServletActionContext.SESSION);      this.response = ServletActionContext.getResponse();    this.response = (HttpServletResponse) ActionContext.getContext().get(      ServletActionContext.HTTP_RESPONSE);      this.context = this.session.getServletContext();    this.context = ServletActionContext.getServletContext();    this.context = (ServletContext) ActionContext.getContext().get(      ServletActionContext.SERVLET_CONTEXT);    this.contextMap = ActionContext.getContext().getApplication();    this.contextMap = ActionContext.getContext().getContextMap();    this.contextMap = (Map<String, Object>) ActionContext.getContext().get(      ActionContext.APPLICATION);    this.contextMap = (Map<String, Object>) ActionContext.getContext().get(      ServletActionContext.APPLICATION);      return SUCCESS;   }     public void setServletRequest(HttpServletRequest request) {    this.request = request;   }     public void setServletResponse(HttpServletResponse response) {    this.response = response;   }     public void setRequest(Map<String, Object> requestMap) {    this.requestMap = requestMap;   }     public void setSession(Map<String, Object> sessionMap) {    this.sessionMap = sessionMap;   }     public void setServletContext(ServletContext context) {    this.context = context;   }     public void setApplication(Map<String, Object> contextMap) {    this.contextMap = contextMap;   }  }

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1376032602037.html
Struts2 Web框架