Seven HttpServletRequest Common Method Description

Source: Internet
Author: User

    //returns all Cookie objects sent by the client in this request.      Public Abstractcookie[] GetCookies (); //returns the value of the request header named name. If the request does not contain a header with the specified name, this method returns NULL.      Public Abstractstring GetHeader (string paramstring); //returns an enumeration collection of all values for the request header named name.      Public AbstractEnumeration<string>getheaders (String paramstring); //returns an enumeration collection of all header names contained in this request.      Public AbstractEnumeration<string>Getheadernames (); //returns the name of the HTTP method used for this request, for example, GET, post, or put.      Public AbstractString GetMethod (); //returns additional path information associated with the request URL sent by the client.    The additional path information is followed by the path of the servlet, before the query string, and begins with a slash (/) character. //For example, suppose that the URL to the Myservlet class map in the Web. xml file is:/myservlet/*, the URL that the user requests is:http://localhost: 8080/ch02/myservlet/test,//When we call GetPathInfo () on the HttpServletRequest object, the method returns/test. If there is no additional path information, the GetPathInfo () method returns NULL.      Public AbstractString GetPathInfo (); //converts the additional path information to the actual path. For example, in the example above, assume that the CH02 Web application is located in the D:\OpenSource\apache-tomcat-6.0.16\webapps\ch02 directory,//when the user requests http://Localhost:8080/ch02/myservlet/test, calling the GetPathTranslated () method on the Request object returns//D:\OpenSource\apache-tomcat-6.0.16\webapps\ch02\test.      Public AbstractString getpathtranslated (); //Returns the part of the request URI that represents the request context, which is the starting part of the request URI. The context path always begins with a slash (/), but ends without a slash (/).    In the default (root) context, this method returns an empty string "". //For example, the request URI is "/sample/test", and the method that is called returns the path to "/sample". //Example:http://192.168.10.145: 8888/servletdemo/hello-->servletdemo     Public AbstractString Getcontextpath (); //returns the query string in the request URL after the path. If there is no query string in the URL, the method returns NULL. For example, like the following request URL://http://localhost: The 8080/ch02/logon.jsp?action=logon call GetQueryString () method returns Action=logon.      Public AbstractString getquerystring (); //returns the portion of the request URL from the host name to the query string. For example://POST:/some/path.html http/1.1/some/path.html//GET:http://foo.bar/a.htmlhttp/1.0/a.html//HEAD:/xyz?a=b http/1.1/xyz//Example:http://192.168.10.145: 8888/servletdemo/hello-->servletdemo/hello     Public AbstractString Getrequesturi (); //reconstructs The URL that the client uses to initiate the request.    The URL returned includes the protocol, the name of the server, the port number, and the path to the server, but does not include query string parameters. //Note that if the request is forwarded to another servlet using the Requestdispatcher.forward (ServletRequest, Servletresponse) method,//so you call Getrequesturl () in this servlet, and you get the URL that was used to get the RequestDispatcher object, not the original request URL. //Example:http://192.168.10.145:8888/servletdemo/hello-->http://192.168.10.145: 8888/servletdemo/hello     Public AbstractStringBuffer Getrequesturl (); //returns the part of the request URI that called the servlet.    This part of the path starts with a slash (/), including the name or path of the servlet, but does not include additional path information and query strings. //For example, suppose that the URL to the Myservlet class map in the Web. xml file is:/myservlet/*, the URL that the user requests is:http://localhost: 8080/ch02/myservlet/test,//When we call Getservletpath () on the HttpServletRequest object, the method returns/myservlet.    If the servlet used to process the request matches the URL style "/*", this method returns an empty string (""). //Example:http://192.168.10.145: 8888/servletdemo/hello-->hello     Public AbstractString Getservletpath (); //returns the session associated with this request, if the client is not assigned a session, and the Create parameter is true,//a new session is created. If the Create parameter is false and the request does not have a valid httpsession, NULL is returned.      Public AbstractHttpSession GetSession (Booleancreate); //returns the session associated with this request, and creates a new session if the client is not assigned a session.      Public AbstractHttpSession getsession ();

Seven HttpServletRequest Common Method Description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.