Java-ServletRequestWrapper
- /**
- *
- * Provides a convenient implementation of the ServletRequest interface that
- * can be subclassed by developers wishing to adapt the request to a Servlet.
- * This class implements the Wrapper or Decorator pattern. Methods default to
- * calling through to the wrapped request object.
- * @since v 2.3
- *
- *
- *
- * @see javax.servlet.ServletRequest
- *
- */
- //实现了ServletRequest接口
- public class ServletRequestWrapper implements ServletRequest {
- private ServletRequest request;
- /**
- * Creates a ServletRequest adaptor wrapping the given request object.
- * @throws java.lang.IllegalArgumentException if the request is null
- */
- //构造函数,ServletRequest适配器
- public ServletRequestWrapper(ServletRequest request) {
- if (request == null) {
- throw new IllegalArgumentException("Request cannot be null");
- }
- this.request = request;
- }
- /**
- * Return the wrapped request object.
- */
- //获得Request
- public ServletRequest getRequest() {
- return this.request;
- }
- /**
- * Sets the request object being wrapped.
- * @throws java.lang.IllegalArgumentException if the request is null.
- */
- //设置ServletRequest
- public void setRequest(ServletRequest request) {
- if (request == null) {
- throw new IllegalArgumentException("Request cannot be null");
- }
- this.request = request;
- }
- /**
- * The default behavior of this method is to call getAttribute(String name)
- * on the wrapped request object.
- */
- //获取ServletRequest的name属性
- public Object getAttribute(String name) {
- return this.request.getAttribute(name);
- }
- /**
- * The default behavior of this method is to return getAttributeNames()
- * on the wrapped request object.
- */
- //获得所有属性name的枚举
- public Enumeration getAttributeNames() {
- return this.request.getAttributeNames();
- }
- /**
- * The default behavior of this method is to return getCharacterEncoding()
- * on the wrapped request object.
- */
- //获得字符类型
- public String getCharacterEncoding() {
- return this.request.getCharacterEncoding();
- }
- /**
- * The default behavior of this method is to set the character encoding
- * on the wrapped request object.
- */
- //设置字符类型
- public void setCharacterEncoding(String enc) throws java.io.UnsupportedEncodingException {
- this.request.setCharacterEncoding(enc);
- }
- /**
- * The default behavior of this method is to return getContentLength()
- * on the wrapped request object.
- */
- //获得Request请求body的二进制数据的长度
- public int getContentLength() {
- return this.request.getContentLength();
- }
- /**
- * The default behavior of this method is to return getContentType()
- * on the wrapped request object.
- */
- //获得Request请求body的文件类型
- public String getContentType() {
- return this.request.getContentType();
- }
- /**
- * The default behavior of this method is to return getInputStream()
- * on the wrapped request object.
- */
- //获得InputStream
- public ServletInputStream getInputStream() throws IOException {
- return this.request.getInputStream();
- }
- /**
- * The default behavior of this method is to return getParameter(String name)
- * on the wrapped request object.
- */
- //获得参数name
- public String getParameter(String name) {
- return this.request.getParameter(name);
- }
- /**
- * The default behavior of this method is to return getParameterMap()
- * on the wrapped request object.
- */
- public Map getParameterMap() {
- return this.request.getParameterMap();
- }
- /**
- * The default behavior of this method is to return getParameterNames()
- * on the wrapped request object.
- */
- //获得属性name的枚举
- public Enumeration getParameterNames() {
- return this.request.getParameterNames();
- }
- /**
- * The default behavior of this method is to return getParameterValues(String name)
- * on the wrapped request object.
- */
- //获得属性name的所有值
- public String[] getParameterValues(String name) {
- return this.request.getParameterValues(name);
- }
- /**
- * The default behavior of this method is to return getProtocol()
- * on the wrapped request object.
- */
- //获取协议
- public String getProtocol() {
- return this.request.getProtocol();
- }
- /**
- * The default behavior of this method is to return getScheme()
- * on the wrapped request object.
- */
- //返回协议名称 http、https、ftp
- public String getScheme() {
- return this.request.getScheme();
- }
- /**
- * The default behavior of this method is to return getServerName()
- * on the wrapped request object.
- */
- //获得请求发送的服务器名称
- public String getServerName() {
- return this.request.getServerName();
- }
- /**
- * The default behavior of this method is to return getServerPort()
- * on the wrapped request object.
- */
- //获得请求发送的端口
- public int getServerPort() {
- return this.request.getServerPort();
- }
- /**
- * The default behavior of this method is to return getReader()
- * on the wrapped request object.
- */
- //检索请求body数据作为字符数据使用bufferedReader
- public BufferedReader getReader() throws IOException {
- return this.request.getReader();
- }
- /**
- * The default behavior of this method is to return getRemoteAddr()
- * on the wrapped request object.
- */
- //获得远程主机IP
- public String getRemoteAddr() {
- return this.request.getRemoteAddr();
- }
- /**
- * The default behavior of this method is to return getRemoteHost()
- * on the wrapped request object.
- */
- //获得发送请求的主机名或最后一次代理的主机名
- public String getRemoteHost() {
- return this.request.getRemoteHost();
- }
- /**
- * The default behavior of this method is to return setAttribute(String name, Object o)
- * on the wrapped request object.
- */
- //在请求中设置一个属性
- public void setAttribute(String name, Object o) {
- this.request.setAttribute(name, o);
- }
- /**
- * The default behavior of this method is to call removeAttribute(String name)
- * on the wrapped request object.
- */
- //删除请求的属性name
- public void removeAttribute(String name) {
- this.request.removeAttribute(name);
- }
- /**
- * The default behavior of this method is to return getLocale()
- * on the wrapped request object.
- */
- public Locale getLocale() {
- return this.request.getLocale();
- }
- /**
- * The default behavior of this method is to return getLocales()
- * on the wrapped request object.
- */
- public Enumeration getLocales() {
- return this.request.getLocales();
- }
- /**
- * The default behavior of this method is to return isSecure()
- * on the wrapped request object.
- */
- //判断是否使用的安全协议https
- public boolean isSecure() {
- return this.request.isSecure();
- }
- /**
- * The default behavior of this method is to return getRequestDispatcher(String path)
- * on the wrapped request object.
- */
- //获得path的分发器
- public RequestDispatcher getRequestDispatcher(String path) {
- return this.request.getRequestDispatcher(path);
- }
- /**
- * The default behavior of this method is to return getRealPath(String path)
- * on the wrapped request object.
- */
- public String getRealPath(String path) {
- return this.request.getRealPath(path);
- }
- /**
- * The default behavior of this method is to return
- * getRemotePort() on the wrapped request object.
- *
- * @since 2.4
- */
- //端口
- public int getRemotePort(){
- return this.request.getRemotePort();
- }
- /**
- * The default behavior of this method is to return
- * getLocalName() on the wrapped request object.
- *
- * @since 2.4
- */
- //获得Request的服务器名
- public String getLocalName(){
- return this.request.getLocalName();
- }
- /**
- * The default behavior of this method is to return
- * getLocalAddr() on the wrapped request object.
- *
- * @since 2.4
- */
- //获得Request的服务器IP地址
- public String getLocalAddr(){
- return this.request.getLocalAddr();
- }
- /**
- * The default behavior of this method is to return
- * getLocalPort() on the wrapped request object.
- *
- * @since 2.4
- */
- //端口
- public int getLocalPort(){
- return this.request.getLocalPort();
- }
- }
Java-ServletRequestWrapper的更多相关文章
- Spark案例分析
一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...
- java.lang.ClassCastException: $Proxy0 cannot be cast to javax.servlet.ServletRequestWrapper
我是在myeclipse 8.5使用代理的时候遇到这个问题的.因为我是跟着视频敲的,所以按道理代码是不会有问题..最后经过我百折不挠的折腾,我发现问题的根源 是 myeclipse自带的tomcat. ...
- java web学习总结(十八) -------------------过滤器的高级使用
在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装饰器)模式对request.response对象进行包装,再把包装对象传给目 ...
- Java程序员学习之路
1. Java语言基础 谈到Java语 言基础学习的书籍,大家肯定会推荐Bruce Eckel的<Thinking in Java>.它是一本写的相当深刻的技术书籍,Java语言基础部分基 ...
- [javaweb]Java过滤器与包装设计模式的实用案例.
在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装饰器)模式对request.response对象进行包装,再把包装对象传给目 ...
- 【转】学习JAVA的步骤
好东西大家分享: JAVA学习的一些重点 . Java语言基础 谈到Java语言基础学习的书籍,大家肯定会推荐Bruce Eckel的<Thinking in Java>.它是一本写的 ...
- java web servlet
一.什么是Servlet Servlet是一种小型的Java程序,它扩展了Web服务器的功能.作为一种服务器端的应用,他是运行在Servlet容器当中,例如Tomcat就是一种流行的Servlet容器 ...
- java专业规划(转载)
1. Java语言基础 谈到Java语言基础学习的书籍,大家肯定会推荐Bruce Eckel的<Thinking in Java>.它是一本写的相当深刻的技术书籍,Java语言基础 ...
- 【转】安卓必备Java基础
[转]http://www.zhihu.com/question/19937886(里面提到的知识点的链接) 1. Java 语言基础 谈到Java 语言基础学习的书籍,大家肯定会推荐Bruce Ec ...
- java学习书籍推荐
1. Java 语言基础 谈到Java 语言基础学习的书籍,大家肯定会推荐Bruce Eckel 的<Thinking in Java >.它是一本写的相当深刻的技术书籍,Java 语言基 ...
随机推荐
- Matlab to OpenCV Mat
convert Matlab matrix to OpenCV Mat. Support CV_32FC3 only currently. The Code int matlab2opencv(cv: ...
- Why Doesn't Python Have Switch/Case?
Why Doesn't Python Have Switch/Case? Tuesday, June 09, 2015 (permalink) Unlike every other programmi ...
- Android初级教程:如何自定义一个状态选择器
有这样一种场景:点击一下某个按钮或者图片(view),改变了样式(一般改变背景颜色).这个时候一种解决方案,可能就是状态选择器.接下来就介绍如何实现状态选择器: 步骤: 一.新建这样的文件夹:res/ ...
- 指令汇B新闻客户端开发(五) ShareSdk的使用
ShareSdk是一个分享按钮的开源框架,我们首先可以去mob的官网下载这个控件.mob官网,然后找到sdk下载那一栏, 下载下来之后点击这个.jar文件就会有一个弹窗,填写自己的应用包名和要哪些分享 ...
- Oracle 执行计划(Explain Plan) 说明
如果要分析某条SQL的性能问题,通常我们要先看SQL的执行计划,看看SQL的每一步执行是否存在问题. 如果一条SQL平时执行的好好的,却有一天突然性能很差,如果排除了系统资源和阻塞的原因,那么基本可以 ...
- Matlab:如何查找给定目录下的文件
我们有很多目录,每个目录下都有些有用的文件,比如图像文件,如何自动的扫描这些文件呢? 可以使用dir函数来完成这个任务. 比如假设给定目录 baseDir,它是一个字符串,包含的是某个目录,例如'./ ...
- Python读取JSON数据,并解决字符集不匹配问题
今天来谈一谈Python解析JSON数据,并写入到本地文件的一个小例子. – 思路如下 从一个返回JSON天气数据的网站获取到目标JSON数据串 使用Python解析出需要的部分 写入到本地文件,供其 ...
- 13 SQLiteOpenHelper SQLiteDatabase详解
创建数据库: 1. 创建一个类继承SQLiteOpenHelper 2. 创建继承对象 new SQLiteOpenHelper() 3. 用创建的对象获取可写或者可读的SQLiteDatabase ...
- String&StringBuilder&StringBuffer总结
一.String的JVM内存分配测试与分析 String a="a"; String b="b"; String c="ab&qu ...
- Git工程迁移方法总结(命令行)
Git工程迁移方法总结 Git工程迁移方法总结 Git最近准备迁移一下位置,这里采用命令行的方式,做如下操作. 1.git init 初始化git仓库,这个时候发现本地文件夹多了个.git的文件夹. ...