Struts2_009_Servlet API耦合的访问方式值之ServletXxxAware
来源:互联网 发布:php爱奇艺vip解析源码 编辑:程序博客网 时间:2024/05/17 07:02
概述
- 通过实现 ServletRequestAware, ServletContextAware 等接口的方式
- 步骤
1.实现ServletXxxAware接口
2.实现其中的方法,并将参数存储为成员变量(会自动的被调用)
3.使用成员变量
测试代码
TestServletXxxAware.java
package top.itcourse.aware;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.struts2.interceptor.ServletRequestAware;import org.apache.struts2.interceptor.ServletResponseAware;import org.apache.struts2.util.ServletContextAware;/* * 解耦方式访问web资源之ServletXxxAware: * 1.实现ServletXxxAware接口 * 2.实现其中的方法,并将参数存储为成员变量(会自动的被调用) * 3.使用成员变量 */// 1.实现ServletXxxAware接口 public class TestServletXxxAware implements ServletRequestAware,ServletContextAware,ServletResponseAware{ private HttpServletRequest request; private ServletContext application; private HttpServletResponse response; // action方法 public String execute() { // 3.使用成员变量 System.out.println("request: " + request); System.out.println("application: " + application); System.out.println("response: " + response); // 其它能从request中获取的东西都可以获取,比如session、参数等等 System.out.println("session: " + request.getSession()); return "success"; } // 2.实现其中的方法,并将参数存储为成员变量 @Override public void setServletRequest(HttpServletRequest request) { this.request = request; } @Override public void setServletContext(ServletContext application) { this.application = application; } @Override public void setServletResponse(HttpServletResponse response) { this.response = response; }}
结果
其它
- 源码下载
关注下方公众号,回复:struts2_course.code
欢迎加入交流群:451826376
更多信息:www.itcourse.top
阅读全文
0 0
- Struts2_009_Servlet API耦合的访问方式值之ServletXxxAware
- Struts2_008_Servlet API耦合的访问方式值之ServletActionContext
- Struts2 与Servlet API解耦,耦合的访问方式
- struts 和servlet APi的耦合方式
- servlet API 解耦访问和耦合访问的区别
- Structs2通过耦合的方式访问WEB资源
- 电路的耦合方式
- 干扰的耦合方式
- struts2中耦合访问servlet- API
- struts2中耦合访问servlet- API
- Hbase访问方式之Java API
- Hbase访问方式之Java API
- 示波器的输入耦合方式
- struts2耦合和非耦合设置值和获取的方式
- HDFS的Java API的访问方式
- Servlet API解耦的访问方式
- restful api 的HTTP认证访问方式
- api访问方式
- 微信小程序开发 scroll-view 实现锚点标记
- 华为宣布与法国创业公司 Chronocam 签订 Face ID 技术合作协议
- 频频发力 5G,英特尔在下一代技术上都做了什么?
- 在数据即将成为核心资源的时代, 英特尔准备了这样一个杀手锏
- 解决:No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency
- Struts2_009_Servlet API耦合的访问方式值之ServletXxxAware
- Android开发之Socket通信
- Java多线程编程-(16)-等待/通知模式接口Condition接口深入分析
- 推动云基础设施创新,英特尔与阿里云的“软硬合唱”
- 传三星S9将采用苹果的Face ID面部识别解锁技术
- 亚马逊拟进军运动服饰领域,将与台湾两家代工商合作
- C语言:数据类型,char,int
- 朴素贝叶斯分类
- java学习记录——类和对象的练习2