/** * 通过和Servlet解耦的方式获取web资源,例如:ServletContext,Session,request,parameter的Map属性集合 * 1、通过ActionContext获取 * 2、通过实现xxxAware接口的方式 */ ActionContext actionContext = ActionContext.getContext(); //获取application(ServletContext) Map<String, Object> applicationMap = actionContext.getApplication(); //获取session Map<String, Object> sessionMap = actionContext.getSession(); //获取request Map<String, Object> requestMap = (Map<String, Object>) actionContext.get("request"); //获取parameter 返回的是参数数组 Map<String, Object> parameterMap = actionContext.getParameters();
implements RequestAware,ApplicationAware,SessionAware,ParameterAware private Map<String, Object> sessionMap; private Map<String, Object> applicationMap; private Map<String, Object> requestMap; private Map<String, String[]> parameterMap; @Override public void setSession(Map<String, Object> sessionMap) { this.sessionMap = sessionMap; } @Override public void setApplication(Map<String, Object> applicationMap) { this.applicationMap = applicationMap; } @Override public void setRequest(Map<String, Object> requestMap) { this.requestMap = requestMap; } @Override public void setParameters(Map<String, String[]> parameterMap) { this.parameterMap = parameterMap; }
/** * 通过和Servlet耦合的方式获取web资源 * 1、通过ServletActionContext获取 * 2、通过实现ServletxxxAware获取 */ ServletContext servletContext = ServletActionContext.getServletContext(); HttpServletRequest servletRequest = ServletActionContext.getRequest(); HttpServletResponse httpServletResponse = ServletActionContext.getResponse();
implements ServletContextAware,ServletRequestAware,ServletResponseAware @Override public void setServletResponse(HttpServletResponse response) { } @Override public void setServletRequest(HttpServletRequest request) { } @Override public void setServletContext(ServletContext context) { }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。