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 语言基 ...
随机推荐
- 【mybatis深度历险系列】mybatis的框架原理+入门程序解析
在前面的博文中,小编介绍了springmvc的相关知识点,在今天这篇博文中,小编将介绍一下mybatis的框架原理,以及mybatis的入门程序,实现用户的增删改查,她有什么优缺点以及mybatis和 ...
- 1、win10下连接本地系统上的Linux操作系统(分别以Nat方式和桥接模式实现)
1.win10下连接本地系统上的Linux操作系统(分别以Nat方式和桥接模式实现) 一.准备知识:win10下打开Administrator的方式 在win10操作系统中,Administrator ...
- 两个无序数组分别叫A和B,长度分别是m和n,求中位数,要求时间复杂度O(m+n),空间复杂度O(1) 。
#include <iostream> using namespace std; /*函数作用:取待排序序列中low.mid.high三个位置上数据,选取他们中间的那个数据作为枢轴*/ i ...
- 28 自定义View侧滑栏
ScrollMenuView.java package com.qf.sxy.customview03.widget; import android.content.Context; import a ...
- Android捕获全局异常
Android捕获全局异常 程序避免不了出现bug,导致程序崩溃,为了尽量不影响用户体验,可以全局捕获异常 效果图 异常捕获处理前 异常捕获处理后(将程序重新启动) 捕获异常的工具类 package ...
- 仿爱奇艺视频,腾讯视频,搜狐视频首页推荐位轮播图(二)之SuperIndicator源码分析
转载请把头部出处链接和尾部二维码一起转载,本文出自逆流的鱼:http://blog.csdn.net/hejjunlin/article/details/52510431 背景:仿爱奇艺视频,腾讯视频 ...
- hbase高性能读取数据
有时需要从hbase中一次读取大量的数据,同时对实时性有较高的要求.可以从两方面进行考虑:1.hbase提供的get方法提供了批量获取数据方法,通过组装一个list<Get> gets即可 ...
- MAMP显示文件列表
背景 MAMP是Mac下的一个PHP+Nginx+MySQL的集成环境,支持多站点,不同版本PHP. 今天有人请教MAMP如何显示文件列表的问题,这里记录一下. 知识补充 一个网站为了安全考虑,默认是 ...
- 开源框架Slidingmenu的基本使用
转载本博客请标明出处:点击打开链接 http://blog.csdn.net/qq_32059827/article/details/52464262 侧滑菜单在开发中经常用到,而Slidi ...
- android自定义view实现progressbar的效果
一键清理是很多Launcher都会带有的功能,其效果也比较美观.实现方式也许有很多中,其中常见的是使用图片drawable来完成的,具体可以参考这篇文章:模仿实现360桌面水晶球式的一键清理特效.本文 ...