Introduction to the
The Servletrequest is a service function created by Tomcat that is passed to the servlet and contains information about the client. HttpServletRequest is based on the HTTP protocol
Servletrequest related functions
- Object getAttribute(String name); void setAttribute(String name, Object o); Void removeAttribute(String name) Returns a domain object. This field object is similar to the context, but is called for functions in the Requestdespatcher.
- Enumeration getAttributeNames ()
- String getCharacterEncoding() Header information, encoding mode.
- Void setCharacterEncoding(String env
- Int getContentLength() retrieves the length of the content, if the length position returns -1
- The same goes for long getContentLengthLong ()
- String getContentType() Specifies the type of the content
- ServletInputStream getInputStream() gets the input stream for the request
- Enumeration getParameterNames (); String getParameter (String name); String [] getParameterValues (String name); Map
,string[]>
getParameterMap() gets query object information
- String getProtocol() Returns the protocol, for example, HTTP/1.1
- String getScheme() for example, Http
- String getServerName()
- Int getServerPort() specifies the start number
- BufferedReader getReader() opens the character input stream
- String getRemoteAddr()
- String getRemoteHost()
- Void removeAttribute (String name); Enumeration getLocales() returns the accept-language of the local message of the client if the local message is not called directly
- Boolean isSecure() Specifies whether to use a security protocol
- RequestDispatcher getRequestDispatcher(String Path) invokes the request handler
- ServletContext getServletContext() calls the environment
- AsyncContext startAsync (); AsyncContext startAsync(ServletRequest ServletRequest, ServletResponse ServletResponse) async mode
- Boolean isAsyncStarted() checks whether it is in asynchronous mode
- Boolean isAsyncSupported() Whether asynchrony is supported
- AsyncContext getAsyncContext() returns the entered async mode
- DispatcherType getDispatcherType() Is related to the dispatcher, which is related to the listener
Httpservletrequest functions
- String getAuthType() Authentication mode: There are three authentication modes: basic authentication, form authentication, client authentication, and other diagnostic authentication. If there is no authentication NULL. No study of certification, not in-depth.
- Cookie[] getCookies() : Returns cookies, there will be a topic for cookies. A cookie is a message sent by the server to the client for marking
- Long getDateHeader(String name) Returns a time object, such as if-modified-since.
- String getHeader(String name) Returns a character object whose header is name. Remember that name is case sensitive
- Enumeration getHeaders(String name) Returns objects with multiple values
- Enumeration getHeaderNames() returns all headers
- Int getIntHeader(String name) returns a positive header
- String getMethod() returns the method
- String getPathInfo() returns address information, which is used for directories with matching addresses, between the servlet address and query, starting with a slash
<servlet>
<servlet-name>xxxa</servlet-name>
<servlet-class>AServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xxxa</servlet-name>
<url-pattern>/aservlet/*</url-pattern>
</servlet-mapping>
http://localhost:8080/web11/aservlet/234234/4312
print234234/4312: /Copy the code
- Translated extra address information into real addresses. It doesn’t make any sense. For example, the above return D:\java_temp\plug1\out\artifacts\web11_war_exploded\234234\4312
- String getContextPath() returns the servlet address, or an empty String if it is the root address. There may be multiple getContextPath() objects that return different values from the context
- String getRemoteUser() Specifies the authentication name
- Boolean isUserInRole(String role) Authentication related
- Principal getUserPrincipal() Security level related to authentication
- String getRequestedSessionId() Returns the sessionID
- String getRequestURI() returns something between the protocol and query
- StringBuffer getRequestURL() returns the full URL without query information
- String getServletPath() returns the address of the servlet, starting with a slash
- HttpSession getSession(Boolean create) Returns a session, and if not, creates a new one based on the value of create
- HttpSession getSession()等同于HttpSession getSession(true)
- String changeSessionId() returns a new session
- Boolean isRequestedSessionIdValid () is related to the session
- isRequestedSessionIdFromCookie
- boolean isRequestedSessionIdFromURL()
- Boolean Authenticate (HttpServletResponse Response) authorization related
- Void logout (); void login(String username, String password)
- The Collection getParts (); Part getPart(String name) these two functions are mainly for post multipart/form-data processing.
- T upgrade(Class handlerClass) This is a protocol upgrade that returns a new object with a Class object. It doesn’t seem to help
Related classes RequestDispatcher
RequestDispatcher is a request resource scheduler that invokes related servlets and JSPS in the request. There are two functions:
- Void Forward (ServletRequest Request,ServletResponse Response) Void Forward (ServletRequest Request,ServletResponse Response) Void Forward (ServletRequest Request,ServletResponse Response) Void Forward (ServletResponse Response) Void Forward (ServletRequest Request,ServletResponse Response
- Void include(ServletRequest Request,ServletResponse Response) does not change the header or status code of the response.
URL encoding
For parameters in URL, application/ X-www-form-urlencoded method is adopted by default.
- Requestcharsettpye is set to UTF-8 (null, ISO8895 is the default if the data is read directly), the data will be garbled. Therefore, the pre-set type is mandatory
- Get command: Data is also url encoded and automatically processed by the browser and server. Parameter data is stored in the URL. However, the type data without GET does not have Application/X-www-form-urlencoded, and the encoding mode is UTF-8, so parameters can be read directly without setting. You don’t have to set this for a very strange reason. Probably utF-8, tomcat’s default setting
- Urlencode.code () URLDecode. Decode ()
- There is also the URI encoding, which differs from the URL encoding by space. The URI encoding space is %20 and the URL encoding is +