Java-API:javax.servlet.http.HttpServletRequest
| ylbtech-Java-API:javax.servlet.http.HttpServletRequest |
| 1.返回顶部 |
javax.servlet.http
Interface HttpServletRequest
- All Known Implementing Classes:
- HttpServletRequestWrapper
- public interface HttpServletRequest
- extends ServletRequest
Extends the ServletRequest interface to provide request information for HTTP servlets.
The servlet container creates an HttpServletRequest object and passes it as an argument to the servlet's service methods (doGet, doPost, etc).
| Field Summary | |
static java.lang.String |
BASIC_AUTH String identifier for Basic authentication. |
static java.lang.String |
CLIENT_CERT_AUTH String identifier for Client Certificate authentication. |
static java.lang.String |
DIGEST_AUTH String identifier for Digest authentication. |
static java.lang.String |
FORM_AUTH String identifier for Form authentication. |
| Method Summary | |
java.lang.String |
getAuthType() Returns the name of the authentication scheme used to protect the servlet. |
java.lang.String |
getContextPath() Returns the portion of the request URI that indicates the context of the request. |
Cookie[] |
getCookies() Returns an array containing all of the Cookie objects the client sent with this request. |
long |
getDateHeader(java.lang.String name) Returns the value of the specified request header as a long value that represents a Date object. |
java.lang.String |
getHeader(java.lang.String name) Returns the value of the specified request header as a String. |
java.util.Enumeration |
getHeaderNames() Returns an enumeration of all the header names this request contains. |
java.util.Enumeration |
getHeaders(java.lang.String name) Returns all the values of the specified request header as an Enumeration of String objects. |
int |
getIntHeader(java.lang.String name) Returns the value of the specified request header as an int. |
java.lang.String |
getMethod() Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. |
java.lang.String |
getPathInfo() Returns any extra path information associated with the URL the client sent when it made this request. |
java.lang.String |
getPathTranslated() Returns any extra path information after the servlet name but before the query string, and translates it to a real path. |
java.lang.String |
getQueryString() Returns the query string that is contained in the request URL after the path. |
java.lang.String |
getRemoteUser() Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated. |
java.lang.String |
getRequestedSessionId() Returns the session ID specified by the client. |
java.lang.String |
getRequestURI() Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. |
java.lang.StringBuffer |
getRequestURL() Reconstructs the URL the client used to make the request. |
java.lang.String |
getServletPath() Returns the part of this request's URL that calls the servlet. |
HttpSession |
getSession() Returns the current session associated with this request, or if the request does not have a session, creates one. |
HttpSession |
getSession(boolean create) Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session. |
java.security.Principal |
getUserPrincipal() Returns a java.security.Principal object containing the name of the current authenticated user. |
boolean |
isRequestedSessionIdFromCookie() Checks whether the requested session ID came in as a cookie. |
boolean |
isRequestedSessionIdFromUrl() Deprecated. As of Version 2.1 of the Java Servlet API, use isRequestedSessionIdFromURL() instead. |
boolean |
isRequestedSessionIdFromURL() Checks whether the requested session ID came in as part of the request URL. |
boolean |
isRequestedSessionIdValid() Checks whether the requested session ID is still valid. |
boolean |
isUserInRole(java.lang.String role) Returns a boolean indicating whether the authenticated user is included in the specified logical "role". |
| Methods inherited from interface javax.servlet.ServletRequest |
getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameter, getParameterMap,getParameterNames, getParameterValues, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, isSecure,removeAttribute, setAttribute, setCharacterEncoding |
| Field Detail |
BASIC_AUTH
public static final java.lang.String BASIC_AUTH
- String identifier for Basic authentication. Value "BASIC"
FORM_AUTH
public static final java.lang.String FORM_AUTH
- String identifier for Form authentication. Value "FORM"
CLIENT_CERT_AUTH
public static final java.lang.String CLIENT_CERT_AUTH
- String identifier for Client Certificate authentication. Value "CLIENT_CERT"
DIGEST_AUTH
public static final java.lang.String DIGEST_AUTH
- String identifier for Digest authentication. Value "DIGEST"
| Method Detail |
getAuthType
public java.lang.String getAuthType()
- Returns the name of the authentication scheme used to protect the servlet. All servlet containers support basic, form and client certificate authentication, and may additionally support digest authentication. If the servlet is not authenticated
nullis returned.Same as the value of the CGI variable AUTH_TYPE.
-
-
- Returns:
- one of the static members BASIC_AUTH, FORM_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH (suitable for == comparison) or the container-specific string indicating the authentication scheme, or
nullif the request was not authenticated.
getCookies
public Cookie[] getCookies()
- Returns an array containing all of the
Cookieobjects the client sent with this request. This method returnsnullif no cookies were sent. -
-
- Returns:
- an array of all the
Cookiesincluded with this request, ornullif the request has no cookies
getDateHeader
public long getDateHeader(java.lang.String name)
- Returns the value of the specified request header as a
longvalue that represents aDateobject. Use this method with headers that contain dates, such asIf-Modified-Since.The date is returned as the number of milliseconds since January 1, 1970 GMT. The header name is case insensitive.
If the request did not have a header of the specified name, this method returns -1. If the header can't be converted to a date, the method throws an
IllegalArgumentException. -
-
- Parameters:
name- aStringspecifying the name of the header- Returns:
- a
longvalue representing the date specified in the header expressed as the number of milliseconds since January 1, 1970 GMT, or -1 if the named header was not included with the request - Throws:
- java.lang.IllegalArgumentException - If the header value can't be converted to a date
getHeader
public java.lang.String getHeader(java.lang.String name)
- Returns the value of the specified request header as a
String. If the request did not include a header of the specified name, this method returnsnull. If there are multiple headers with the same name, this method returns the first head in the request. The header name is case insensitive. You can use this method with any request header. -
-
- Parameters:
name- aStringspecifying the header name- Returns:
- a
Stringcontaining the value of the requested header, ornullif the request does not have a header of that name
getHeaders
public java.util.Enumeration getHeaders(java.lang.String name)
- Returns all the values of the specified request header as an
EnumerationofStringobjects.Some headers, such as
Accept-Languagecan be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.If the request did not include any headers of the specified name, this method returns an empty
Enumeration. The header name is case insensitive. You can use this method with any request header. -
-
- Parameters:
name- aStringspecifying the header name- Returns:
- an
Enumerationcontaining the values of the requested header. If the request does not have any headers of that name return an empty enumeration. If the container does not allow access to header information, return null
getHeaderNames
public java.util.Enumeration getHeaderNames()
- Returns an enumeration of all the header names this request contains. If the request has no headers, this method returns an empty enumeration.
Some servlet containers do not allow servlets to access headers using this method, in which case this method returns
null -
-
- Returns:
- an enumeration of all the header names sent with this request; if the request has no headers, an empty enumeration; if the servlet container does not allow servlets to use this method,
null
getIntHeader
public int getIntHeader(java.lang.String name)
- Returns the value of the specified request header as an
int. If the request does not have a header of the specified name, this method returns -1. If the header cannot be converted to an integer, this method throws aNumberFormatException.The header name is case insensitive.
-
-
- Parameters:
name- aStringspecifying the name of a request header- Returns:
- an integer expressing the value of the request header or -1 if the request doesn't have a header of this name
- Throws:
- java.lang.NumberFormatException - If the header value can't be converted to an
int
getMethod
public java.lang.String getMethod()
- Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. Same as the value of the CGI variable REQUEST_METHOD.
-
-
- Returns:
- a
Stringspecifying the name of the method with which this request was made
getPathInfo
public java.lang.String getPathInfo()
- Returns any extra path information associated with the URL the client sent when it made this request. The extra path information follows the servlet path but precedes the query string and will start with a "/" character.
This method returns
nullif there was no extra path information.Same as the value of the CGI variable PATH_INFO.
-
-
- Returns:
- a
String, decoded by the web container, specifying extra path information that comes after the servlet path but before the query string in the request URL; ornullif the URL does not have any extra path information
getPathTranslated
public java.lang.String getPathTranslated()
- Returns any extra path information after the servlet name but before the query string, and translates it to a real path. Same as the value of the CGI variable PATH_TRANSLATED.
If the URL does not have any extra path information, this method returns
nullor the servlet container cannot translate the virtual path to a real path for any reason (such as when the web application is executed from an archive). The web container does not decode this string. -
-
- Returns:
- a
Stringspecifying the real path, ornullif the URL does not have any extra path information
getContextPath
public java.lang.String getContextPath()
- Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". The container does not decode this string.
-
-
- Returns:
- a
Stringspecifying the portion of the request URI that indicates the context of the request
getQueryString
public java.lang.String getQueryString()
- Returns the query string that is contained in the request URL after the path. This method returns
nullif the URL does not have a query string. Same as the value of the CGI variable QUERY_STRING. -
-
- Returns:
- a
Stringcontaining the query string ornullif the URL contains no query string. The value is not decoded by the container.
getRemoteUser
public java.lang.String getRemoteUser()
- Returns the login of the user making this request, if the user has been authenticated, or
nullif the user has not been authenticated. Whether the user name is sent with each subsequent request depends on the browser and type of authentication. Same as the value of the CGI variable REMOTE_USER. -
-
- Returns:
- a
Stringspecifying the login of the user making this request, ornullif the user login is not known
isUserInRole
public boolean isUserInRole(java.lang.String role)
- Returns a boolean indicating whether the authenticated user is included in the specified logical "role". Roles and role membership can be defined using deployment descriptors. If the user has not been authenticated, the method returns
false. -
-
- Parameters:
role- aStringspecifying the name of the role- Returns:
- a
booleanindicating whether the user making this request belongs to a given role;falseif the user has not been authenticated
getUserPrincipal
public java.security.Principal getUserPrincipal()
- Returns a
java.security.Principalobject containing the name of the current authenticated user. If the user has not been authenticated, the method returnsnull. -
-
- Returns:
- a
java.security.Principalcontaining the name of the user making this request;nullif the user has not been authenticated
getRequestedSessionId
public java.lang.String getRequestedSessionId()
- Returns the session ID specified by the client. This may not be the same as the ID of the current valid session for this request. If the client did not specify a session ID, this method returns
null. -
-
- Returns:
- a
Stringspecifying the session ID, ornullif the request did not specify a session ID - See Also:
isRequestedSessionIdValid()
getRequestURI
public java.lang.String getRequestURI()
- Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. The web container does not decode this String. For example:
First line of HTTP request Returned Value POST /some/path.html HTTP/1.1 /some/path.html GET http://foo.bar/a.html HTTP/1.0 /a.html HEAD /xyz?a=b HTTP/1.1 /xyz To reconstruct an URL with a scheme and host, use
HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest). -
-
- Returns:
- a
Stringcontaining the part of the URL from the protocol name up to the query string - See Also:
HttpUtils.getRequestURL(javax.servlet.http.HttpServletRequest)
getRequestURL
public java.lang.StringBuffer getRequestURL()
- Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.
Because this method returns a
StringBuffer, not a string, you can modify the URL easily, for example, to append query parameters.This method is useful for creating redirect messages and for reporting errors.
-
-
- Returns:
- a
StringBufferobject containing the reconstructed URL
getServletPath
public java.lang.String getServletPath()
- Returns the part of this request's URL that calls the servlet. This path starts with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Same as the value of the CGI variable SCRIPT_NAME.
This method will return an empty string ("") if the servlet used to process this request was matched using the "/*" pattern.
-
-
- Returns:
- a
Stringcontaining the name or path of the servlet being called, as specified in the request URL, decoded, or an empty string if the servlet used to process the request is matched using the "/*" pattern.
getSession
public HttpSession getSession(boolean create)
- Returns the current
HttpSessionassociated with this request or, if there is no current session andcreateis true, returns a new session.If
createisfalseand the request has no validHttpSession, this method returnsnull.To make sure the session is properly maintained, you must call this method before the response is committed. If the container is using cookies to maintain session integrity and is asked to create a new session when the response is committed, an IllegalStateException is thrown.
-
-
- Parameters:
create-trueto create a new session for this request if necessary;falseto returnnullif there's no current session- Returns:
- the
HttpSessionassociated with this request ornullifcreateisfalseand the request has no valid session - See Also:
getSession()
getSession
public HttpSession getSession()
- Returns the current session associated with this request, or if the request does not have a session, creates one.
-
-
- Returns:
- the
HttpSessionassociated with this request - See Also:
getSession(boolean)
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()
- Checks whether the requested session ID is still valid.
-
-
- Returns:
trueif this request has an id for a valid session in the current session context;falseotherwise- See Also:
getRequestedSessionId(),getSession(boolean),HttpSessionContext
isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()
- Checks whether the requested session ID came in as a cookie.
-
-
- Returns:
trueif the session ID came in as a cookie; otherwise,false- See Also:
getSession(boolean)
isRequestedSessionIdFromURL
public boolean isRequestedSessionIdFromURL()
- Checks whether the requested session ID came in as part of the request URL.
-
-
- Returns:
trueif the session ID came in as part of a URL; otherwise,false- See Also:
getSession(boolean)
isRequestedSessionIdFromUrl
public boolean isRequestedSessionIdFromUrl()
- Deprecated. As of Version 2.1 of the Java Servlet API, use
isRequestedSessionIdFromURL()instead.
| 2.返回顶部 |
| 3.返回顶部 |
| 4.返回顶部 |
| 5.返回顶部 |
| 6.返回顶部 |
![]() |
作者:ylbtech 出处:http://ylbtech.cnblogs.com/ 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 |
Java-API:javax.servlet.http.HttpServletRequest的更多相关文章
- Java-Class-I:javax.servlet.http.HttpServletRequest
ylbtech-Java-Class-I:javax.servlet.http.HttpServletRequest 1.返回顶部 2.返回顶部 1. package com.ylbtech.ap ...
- java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z 的解决
jetty 9 嵌入式开发时,启动正常,但是页面一浏览就报错如下: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest ...
- 【异常】idea执行Main方法出现 Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
一.异常复现步骤 1)首先得是一个Spring MVC项目 注:Spring Boot项目有内置的web 容器,不会出现该问题 2)main方法存在于使用HttpServletRequest类的类中 ...
- Caused by: java.lang.NoSuchMethodError:javax.servlet.http.HttpServletRequest.getServletContext()L
在做项目的时候,出现Caused by: java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getServletCo ...
- java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
错误信息 查看Console标签页: 这儿提示找不到HttpServletRequest类. 解决办法 规则文件更新的时候需要调用servlet-api.jar相关的类,如果您的系统环境下无法找到这个 ...
- 在Myeclipse buildpath 加server lib (server runtime)/项目导入时报错:The import javax.servlet.http.HttpServletRequest cannot be resolved
来源于:http://blog.csdn.net/dingqinghu/article/details/8805922 http://yl-fighting.iteye.com/blog/140946 ...
- 项目导入时报错:The import javax.servlet.http.HttpServletRequest cannot be resolved 解决方法
Error: The import javax.servlet cannot be resolved The import javax.servlet.http.HttpServletRequest ...
- 项目导入时报错:The import javax.servlet.http.HttpServletRequest cannot be resolved
Error: The import javax.servlet cannot be resolved The import javax.servlet.http.HttpServletRequest ...
- 【原】tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig()Ljavax/servlet/SessionCookieConfig的解决
现象: tomcat 7 启动报错:java.lang.NoSuchMethodError: javax.servlet.ServletContext.getSessionCookieConfig() ...
随机推荐
- Windows 端口和所提供的服务
一 .端口大全 端口:0 服务:Reserved 说明:通常用于分析操作系统.这一方法能够工作是因为在一些系统中“0”是无效端口,当你试图使用通常的闭合端口连接它时将产生不同的结果.一种典型的扫描,使 ...
- iOS Font
1. 非常棒的查看字体样貌网站: http://iosfonts.com 1. 查看设备支持字体: NSArray *familyNames = [NSMutableArray arrayWithAr ...
- MapReduce-从HBase读取数据处理后再写入HBase
MapReduce-从HBase读取处理后再写入HBase 代码如下 package com.hbase.mapreduce; import java.io.IOException; import o ...
- HDU 汉诺塔系列
做了这一系列题,表示对汉诺塔与这一系列递推理解加深了 经典汉诺塔:1,2,...,n表示n个盘子,数字大盘子就大,n个盘子放在第1根柱子上,按照从上到下 从小到大的顺序排放,过程中每次大盘都不能放在小 ...
- ANT+JMETER + Jenkins 集成1
新建任务注意添加invoke Ant,新建成功后运行就可以啦
- SSAS——基础--cube
SSAS——基础 一.Analysis Services Analysis Services是用于决策支持和BI解决方案的数据引擎.它提供报表和客户端中使用的分析数据. 它可在多用途数据模型中创建 ...
- 返回结果的HTTP状态码
HTTP状态码的职责是当客户端向服务器发送请求时,描述返回的请求结果. 2xx成功 2xx的响应结果表明请求被正常处理. 200 OK 请求已正常处理 204 No Content 请求处理成功,但是 ...
- 我总结的js变量、数组、对象等基础知识
我的第一篇博客 ——JS的那些基础概念 第一次写,也不知道有没有什么套路,需不需要注意文采之类的.不管了,我就直接写主要内容吧!下面是我总结的一些关于JS的基础概念: [变量]从字面上面,变量是可变的 ...
- python_判断字符串编码的方法
1. 安装chardet 在命令行中,进入Python27\Scripts目录,输入以下的命令:easy_install chardet 2. 操作 import chardet f = open(' ...
- vector map迭代器失效解决方案
vector : iter = container.erase(iter); //erase的返回值是删除元素下一个元素的迭代器 vector<int>::iterator it = ...
