Struts2访问servlet API的方法
来源:互联网 发布:大数据 adhoc 编辑:程序博客网 时间:2024/05/21 11:05
1、通过ActionContext类访问
ActionContext是执行时的上下文。上下文可以看作是一个容器,它存放的是Action在执行时需要用到的对象。Action运行期间所用到的数据都保存在ActionContext中。这种方式不能直接过去Servlet API实例,对于Servlet API,可以通过以下方式访问:
ActionContext context = ActionContext.getContext();context.put("name","faker"); //在request中存放context.getSession().put("name","faker"); //在session中存放context.getApplication().put("name","faker"); //在application中存放
2、通过特定的XXXAware接口访问
这种方式能够直接访问servlet API实例
有三种接口:
- ServletContextAware:实现该接口的Action可直接访问web应用的ServletContext实例
- ServletRequestAware:实现该接口的Action可直接访问用户请求的ServletRequestContext实例
- ServletResponseAware:实现该接口的Action可直接访问服务器响应的ServletResponseContext实例
//先实现接口private HttpServletRequest request;在方法中request.setAttribute("name","string");
3、通过ServletActionContext类直接访问
ServletActionContext中的方法都是静态的方法,如下:
- static PageContext getPageContext() //用于访问web应用的PageContext对象,对应JSP的内置对象page
- static HttpServletRequest getRequest() //用于访问web应用的HttpServletRequest对象
- static HttpServletResponse getResponse() //用于访问web应用的HttpServletResponse对象
- static ServletContext getServletCOntext() //用于访问web应用的ServletContext对象
ServletActionContext.getRequest().setAttribute("message","Message");
阅读全文
0 0
- Struts2访问servlet API的方法
- struts2访问servlet的API
- Struts2中Action访问Servlet API的两种方法
- Struts2中Action访问Servlet API的两种方法
- Struts2中Action访问Servlet API的三种方法
- Struts2中Action访问Servlet API的三种方法
- Struts2中Action访问Servlet API的两种方法
- struts2中访问servlet API的一些方法
- struts2中访问servlet API 的方法以及优劣性
- Struts2 访问 Servlet API 的三种方法
- Struts2中Action访问Servlet API的三种方法
- Struts2中Action访问Servlet API的三种方法
- Struts2中Action访问Servlet API的三种方法
- 关于struts2访问servlet API的三种方法详解
- Struts2访问Servlet API
- struts2访问servlet API
- Struts2访问Servlet API
- Struts2:访问Servlet API
- Python简化类例二:实现变量的私有化,Python没有真正的私有变量,而简化类可以真正实现变量的私有
- c语言*数组
- laravel envoy详解
- 我的心得
- springboot 开发入门,及问题汇总
- Struts2访问servlet API的方法
- 先进先出页面置换算法c语言源码
- Hive数据倾斜问题总结
- codeforces893 A-D
- Python简化类例三:实现类实例的事件定义
- localStorage存储
- 牛客网wannafly 4,b题(小AA的数列
- JAVA 类声明中关键字public的作用
- 《基础网页制作》div加float实现一个简单的首页