/**
 *
 * 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的更多相关文章

  1. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  2. java.lang.ClassCastException: $Proxy0 cannot be cast to javax.servlet.ServletRequestWrapper

    我是在myeclipse 8.5使用代理的时候遇到这个问题的.因为我是跟着视频敲的,所以按道理代码是不会有问题..最后经过我百折不挠的折腾,我发现问题的根源 是 myeclipse自带的tomcat. ...

  3. java web学习总结(十八) -------------------过滤器的高级使用

    在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装饰器)模式对request.response对象进行包装,再把包装对象传给目 ...

  4. Java程序员学习之路

    1. Java语言基础 谈到Java语 言基础学习的书籍,大家肯定会推荐Bruce Eckel的<Thinking in Java>.它是一本写的相当深刻的技术书籍,Java语言基础部分基 ...

  5. [javaweb]Java过滤器与包装设计模式的实用案例.

    在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator(装饰器)模式对request.response对象进行包装,再把包装对象传给目 ...

  6. 【转】学习JAVA的步骤

      好东西大家分享: JAVA学习的一些重点 . Java语言基础 谈到Java语言基础学习的书籍,大家肯定会推荐Bruce Eckel的<Thinking in Java>.它是一本写的 ...

  7. java web servlet

    一.什么是Servlet Servlet是一种小型的Java程序,它扩展了Web服务器的功能.作为一种服务器端的应用,他是运行在Servlet容器当中,例如Tomcat就是一种流行的Servlet容器 ...

  8. java专业规划(转载)

    1. Java语言基础     谈到Java语言基础学习的书籍,大家肯定会推荐Bruce Eckel的<Thinking in Java>.它是一本写的相当深刻的技术书籍,Java语言基础 ...

  9. 【转】安卓必备Java基础

    [转]http://www.zhihu.com/question/19937886(里面提到的知识点的链接) 1. Java 语言基础 谈到Java 语言基础学习的书籍,大家肯定会推荐Bruce Ec ...

  10. java学习书籍推荐

    1. Java 语言基础 谈到Java 语言基础学习的书籍,大家肯定会推荐Bruce Eckel 的<Thinking in Java >.它是一本写的相当深刻的技术书籍,Java 语言基 ...

随机推荐

  1. PHP Ajax JavaScript 实现 无刷新附件上传

    普通表单 前端页面 后台处理 带有文件的表单 刷新方式 前端界面 后台页面 无刷新方式 大文件上传 POST极值 upload极值 上传细节 前端页面 后台处理 总结 对一个网站而言,有一个基本的不可 ...

  2. 【安卓开发】Android系统中Parcelable和Serializable的区别

    http://greenrobot.me/devpost/android-parcelable-serializable/ 进行Android开发的时候,我们都知道不能将对象的引用传给Activiti ...

  3. “出错了”和报告Bug的艺术

    "出错了." 没有那句话能像"出错了"一样让程序员/开发者如此沮丧,心里翻江倒海,怒火一点即燃,还要死掉一大片脑细胞. 这句生硬的开场白通常标志着让开发者恐惧的 ...

  4. activiti processEngineLifecycleListener使用

    1.1.1. 前言 实际开发中,有需求如下: 第一:项目启动部署的时候,我们需要监控activiti 工作流引擎是否真正的已经实例化启动了,这里说的是工作流引擎的启动,不是流程实例的启动,对此要特别说 ...

  5. iOS开发之UIWebView的常见一些用法

    虽然现在Xcode8已经开始使用WKWebView这个框架进行网页展示,但是UIWebView也有一些常用的方法需要知道,下面就简单展示一下,仅供大家参考 相关知识:1.设置背景透明:2.加载本地HT ...

  6. Java多线程模型

    谈到Java多线程就涉及到多线程的模型及Java线程与底层操作系统之间的关系.正如我们熟知,现代机器可以分为硬件和软件两大块,如图2-5-1-1,硬件是基础,软件提供实现不同功能的手段.而且软件可以分 ...

  7. SQL Server 索引维护(1)——如何获取索引使用情况

    前言: 在前面一文中,已经提到了三类常见的索引问题,那么问题来了,当系统出现这些问题时,该如何应对? 简单而言,需要分析现有系统的行为,然后针对性地对索引进行处理: 对于索引不足的情况:检查缺少索引的 ...

  8. 如何在Cocos2D游戏中实现A*寻路算法(二)

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;) 免责申明:本博客提供的所有翻译文章原稿均来自互联网,仅供学习交流 ...

  9. UNIX环境高级编程——信号之kill、raise、killpg、alarm、pause、abort、sleep、usleep、nanosleep和setitimer函数

    一.kill, raise, killpg 函数 int kill(pid_t pid, int sig); int raise(int sig); int killpg(int pgrp, int ...

  10. mysql filesort 的解决方案

    在explain我们所使用的sql的时候,经常会遇到using filesort这种情况,原以为是由于有相同列值的原因引起,结果昨天看到公司的一个sql,跟同事讨论了下加上自己又做了一些测试,突然发现 ...