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() ...
随机推荐
- Go 模板语法
Sprig the useful template functions for Go templates (http://masterminds.github.io/sprig/) Github - ...
- Yii和ThinkPHP对比杂谈
关于ThinkPHP(以下简称TP)和Yii Framework(以下简称Yii)的背景.作者和速度方面就不涉及了.因为速度是一个很复杂的问题,牵扯的因素很多.我不得不承认ThinkPHP是 一个是国 ...
- 1.mysql导论
虽然之前用过mysql一年多,但大多只是会用,深入了解的不多.所以想利用平时时间 系统的总结总结. 一.什么是数据库:(数据库软件) 1).什么是数据库(软件):数据库(DB:DataBase ...
- 十分钟让你明白Objective-C的语法(和Java、C++的对比)
很多想开发iOS,或者正在开发iOS的程序员以前都做过Java或者C++,当第一次看到Objective-C的代码时都会头疼,Objective-C的代码在语法上和Java, C++有着很大的区别,有 ...
- Java -- 利用反射 操作任意数组,包括对象数组 和 基本数据类型的数组
items为任意数组
- strip_tags--php
函数剥去字符串中的 HTML.XML 以及 PHP 的标签 strip_tags(string,allow) 参数 描述 string 必需.规定要检查的字符串. allow 可选.规定允许的标签.这 ...
- Linux命令之awk_1
简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再 ...
- 测试通过!为何线上还有很多BUG?
质量控制 大多数测试人员认为测试工作是发现bug,虽然这是测试的主要任务,但其实测试最重要的任务是质量控制,而发现bug和验证bug只是质量控制的一个重要环节而已. 我想很多测试人员都经历过这样的场景 ...
- 重写ddt的mk_test_name方法
一. 测试用例名字的问题 使用ddt做测试,得到的测试报告中,测试用例的名字默认以_01, _02, _03...递增的形式结尾,这时我希望用例名能够以_api_name结尾,比如注册模块,希望看到的 ...
- uva 10453 dp/LCS变形
https://vjudge.net/problem/UVA-10453 给出一个字符串,问最少添加几个字符使其变为回文串,并输出任意一种答案.就是一个类似于LCS的题目,而且简化了一下,只会出现三种 ...
