I am a Solivagant
Lofter    Posts     新文章     文章管理     新日记     日记管理

Servlet Classes and their methods.

一.HttpServletRequest

Cookie[] getCookies()
Returns an array containing all of the Cookie objects the client sent with this request.

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.lang.String changeSessionId()
Changes the session ID of the session associated with this request.

4.返回纯粹的URI
getRequestURI
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 [!其中?a=b就是其中的query string]
To reconstruct an URL with a scheme and host, use getRequestURL().

Returns:
a String containing the part of the URL from the protocol name up to the query string(见上三行注释).
See Also:
getRequestURL()

getRequestURL
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 StringBuffer object containing the reconstructed URL

6.getRequestedSessionId
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 String specifying the session ID, or null if the request did not specify a session ID

7.boolean isRequestedSessionIdValid()
Checks whether the requested session ID is still valid.
Returns:
true if this request has an id for a valid session in the current session context; false otherwise

8.isRequestedSessionIdFromCookie
boolean isRequestedSessionIdFromCookie()
Checks whether the requested session ID came in as a cookie.
Returns:
true if the session ID came in as a cookie; otherwise, false

9.boolean isRequestedSessionIdFromURL()
Checks whether the requested session ID came in as part of the request URL.
Returns:
true if the session ID came in as part of a URL; otherwise, false

10.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 String containing 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.

11.java.lang.String getQueryString()
Gets the request's query string. The query string is the part of the request that follows the '?'.
This is the same as the CGI request metadata QUERY_STRING.
Returns:

posted @ 2018-05-06 14:23  宛如ZZ  阅读(121)  评论(0编辑  收藏  举报