Sring  getAuthType()  -->返回包含用来保护servlet身份验证方案的名称

String  getContextPath()  -->返回web工程路径(即斜杆加工程名) 

Cookie[]  getCookies()  -->返回所有 Cookie

Long  getDateHeader(String name)  -->返回表示时间的请求头

String  getHeader(String name)  -->返回指定名称的特定请求的值

Enumeration  getHeaders(String name)  -->返回所有请求头的Enumeration

Enumeration  getHeaderNames()  -->返回的所有请求头名称的Enumeration

Int  getIntHeader(String name)  -->返回int 类型的请求头

String  getMethod() -->返回HTTP请求的的方法名

String  getPathInfo()  -->字符串包含与客户端发送请求的URL相关的额外信息

String  getPathTranslated()  -->返回一个表示在服务器文件系统上PathInfol转换成的路径

String  getQueryString()  -->返回URL上的参数部分的字符串,必须是GET的请求才有效

String  getRemoteUser()  -->返回登录信息

String  getRequestedSessionId()  -->返回客户端指定的Session id

String  getRequestURI()  -->返回URI(统一资源定位符)

StringBuffer  getRequestURL()  -->返回客户请求的URL地址

String  getServletPath()  -->返回服务路径(即工程之后到参数之前的部分)

HttpSession  getSession()  -->返回当前HttpSession对象

HttpSession  getSession(boolean create)  -->返回当前HttpSession对象,如果没有,true创建并返回一个新的HttpSession对象;false返回null

Principal  getUserPrincipal()  -->返回一个Principal对象,包含当前认证用户的用户名

boolean  isRequestedSessionIdFromCookie()  -->检查Session id是否以Cookie形式传过来的

boolean  isRequestedSessionIdFromURL()  -->检查Session id是否由URL传过来的

boolean  isRequestedSessionIdValid()  -->检查Session id是否有效

boolean  isUserInRole(String role)  -->验证的用户是否是包含在特定的逻辑"role"中

 

httpservletrequest继承ServletRequest的常用方法

 

getAttribute  

           public Object getAttribute(String name)   

      返回以name为名字的属性的值。如果该属性不存在,这个方法将返回null。

getAttributeNames  

         public Enumeration getAttributeNames()   

     返回请求中所有可用的属性的名字。如果在请求中没有属性,这个方法将返回一个空的枚举集合

removeAttribute  

         public void removeAttribute(String name)  

         移除请求中名字为name的属性。  

setAttribute  

         public void setAttribute(String name,Object o)  

     在请求中保存名字为name的属性。  

getCharacterEncoding  

         public String getCharacterEncoding()   

     返回请求正文使用的字符编码的名字。

getContentLength  

         public int getContentLength()   

         以字节为单位,返回请求正文的长度。如果长度不可知,这个方法将返回-1。 

getContentType  

         public String getContentType()   

         返回请求正文的MIME类型。如果类型不可知,这个方法将返回null。

getInputStream  

         public ServletInputStream getInputStream()

         返回一个输入流,使用该输入流以二进制方式读取请求正文的内容。

getLocalAddr  

         public String getLocalAddr()   

         返回接收到请求的网络接口的IP地址,这个方法是在Servlet 2.4规范中新增的方法。 

getLocalPort   

         public int getLocalPort()   

         返回接收到请求的网络接口的IP端口号,这个方法是在Servlet 2.4规范中新增的方法。

getLocalName

         public String getLocalName()

         返回接收到请求的IP接口的主机名,这个方法是在Servlet 2.4规范中新增的方法。  

getParameter  

         public String getParameter(String name)   

     返回请求中name参数的值。如果name参数有多个值,那么这个方法将返回值列表中的第一个值。

getParameterNames  

         public Enumeration getParameterNames()   

     返回请求中包含的所有的参数的名字。如果请求中没有参数,这个方法将返回一个空的枚举集合。

getParameterValues   

         public String[ ] getParameterValues(String name)   

     返回请求中name参数所有的值。

getReader   

         public BufferedReader getReader() throws IOException   

         返回BufferedReader对象,以字节数据方式读取请求正文。  

getRemoteHost   

         public java.lang.String getRemoteHost()   

         返回发送请求的客户端或最后一个代理服务器的完整限定名。  

getRemotePort   

         public int getRemotePort()  

     返回发送请求的客户端或者最后一个代理服务器的IP源端口,这个方法是在Servlet 2.4规范中新增的方法。  

getRequestDispatcher    

         public RequestDispatcher getRequestDispatcher(String path)     

         返回RequestDispatcher对象,作为path所定位的资源的封装。请求转发! 

          forwardinclude

           forward转发,web容器会清空response的数据,并且转发,当前Servlet无法再写入数据。

           include包含,web容器会让两个Servlet的数据都写入response。

getServerName    

         public String getServerName()     

         返回请求发送到的服务器的主机名。  

getServerPort     

         public int getServerPort()    

         返回请求发送到的服务器的端口号。  

setCharacterEncoding    

         public void setCharacterEncoding(String env)throws UnsupportedEncodingException   

         覆盖在请求正文中所使用的字符编码的名字。

 

 

一个常用的获得服务器地址的连接字符串是:String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";

 

请求消息头及示例:

Accept: text/html,p_w_picpath/*                   说明浏览器接受的数据类型(即传说中的MIME类型)

Accept-Charset: ISO-8859-1                      说明浏览器使用的字符编码

Accept-Encoding: gzip,compress      说明浏览器支持的压缩格式

Accept-Language: en-us,zh-cn        说明浏览器的语言环境

Host: www.it315.org:80             说明浏览器要访问的主机名和端口号

If-Modified-Since: Tue, 11 Jul 2000 18:23:51 GMT           文件的修改时间,用于做缓存

Referer: http://hi.baidu.com/wjy9/home    说明请求来自哪里

User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0) 说明浏览器内核

Cookie                                                                                 向服务器发送Cookie

Connection: close/Keep-Alive       说明连接状态

Date: Tue, 11 Jul 2000 18:23:51 GMT    客户端计算机时间