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所定位的資源的封裝。請求轉發!
forward和include
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,image/* 說明瀏覽器接受的數據類型(即傳說中的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 客戶端計算機時間