Action访问Servlet API:
非直接获得:
ActionContext类:http://struts.apache.org/release/2.3.x/index.html
通过静态方法获取实例:ActionContext ac = ActionContext.getContext();
ActionContext访问以下范围的属性:
Request: ac.put(“name”,”设置的属性值”);
Session: ac.getSession().put(“name”,”设置的属性值”);
Application: ac.getApplication().put(“name”,”设置的属性值”);
直接访问1:
实现以下接口可获得对应的范围:
ServletRequestAware:访问HttpServletRequest
ServletResponseAware:访问HttpServletResponse
ServletContextAware:访问ServletContext
Action中HttpServletResponse用以直接对客户端响应没有意义!Action只是业务控制器。
如:response.getWriter().println(“------”);
直接访问2:
使用ServletActionContext工具类
包含静态方法:
本文介绍Struts2框架下Action组件如何访问Servlet API。主要通过ActionContext类间接获取请求、会话和应用范围的数据,也可通过实现特定接口或使用ServletActionContext工具类直接访问。
512

被折叠的 条评论
为什么被折叠?



