This article is a mirror article of machine translation, please click here to jump to the original article.

View: 32847|Reply: 2

[Source] The ServletRequest and HttpServletRequest interfaces in Java

[Copy link]
Posted on 10/26/2021 3:58:25 PM | | | |
ServletRequest interface

When a client sends a request to a web server, the servlet container creates ServletRequest and ServletResponse objects and passes them as parameters to the servlet's service() method. The requesting object provides access to the requested information, such as the header and body information of the requested data.

This interface is used to get data from the client to the servlet of the service request. Define an object to provide client-side request information to the servlet. The servlet container creates a ServletRequest object and passes it as a parameter to the servlet's service method. The data provided by the ServletRequest object includes parameter names and values, attributes, and input streams. Extending the ServletRequest's interface can provide additional protocol-specific data.

ServletRequest interface

  • getAttribute(String): It returns the value of the requested named property, or null if the property does not exist.
  • getAttributeNames(): It returns an enumeration of the property names included in this request.
  • getCharacterEncoding(): Returns the character set encoding entered for this request.
  • getContentLength(): It returns the size of the requested entity data, or -1 if unknown.
  • getContentType(): It returns the type of Internet media requesting entity data, or null if it is not known.
  • getInputstream(): It returns an input stream that reads the binary data in the request body.
  • getParameter(String): It returns a string containing a unique value for the specified parameter, and if the parameter does not exist, it returns null.
  • getParameterNames(): It returns the parameter name of this request in the form of a string enum, and an empty enum if there are no parameters or the input stream is empty.
  • getParameterValues(String): It returns the value of the requested specified parameter as an array of strings, or null if the named parameter does not exist.
  • getProtocol(): It returns the requested protocol and version as <protocol>a string in the form of /<major version>.<minor version>.
  • getReader(): It returns a buffer reader that reads the text in the body of the request.
  • getRealPath(String): Applies an alias rule to the specified virtual path and returns the corresponding real path, returning null if the conversion cannot be performed for some reason.
  • getRemoteAddr(): It returns the IP address of the proxy that sent the request.
  • getRemoteHost(): It returns the fully qualified hostname of the proxy that sent the request.
  • getScheme(): It returns the scheme of the URL used in this request.
  • getServerName(): It returns the hostname of the server that received the request.
  • getServerPort(): It returns the port number that received this request.
  • setAttribute(String, Object): It stores a property in the context of the request; These properties will be reset between requests.


HttpServletRequest interface

It extends the ServletRequest interface to provide request information for HTTP servlets. The servlet container creates an HttpServletRequest object and passes it as a parameter to the servlet's service method (doGet, doPost, etc.).



HttpServletRequest interface

  • getContextPath(): It returns the part of the request URI that indicates the context of the request.
  • getCookies(): It returns an array containing all the cookie objects that the client sent with this request.
  • getQuesryString(): It helps to return the query string contained in the request URL after the path.
  • getSession(): It returns the current HttpSession associated with this request.
  • getMethod(): It returns the name of the HTTP method that made this request.
  • getPart(String name): It helps to get parts with a given name.
  • getPathInfo(): It returns any additional path information associated with the URL.
  • getServletPath(): It helps to return the part of the request URL that called the servlet.






Previous:Docker deploys war applications to Tomcat containers
Next:Test the basic parameter information of your Linux server with one click
 Landlord| Posted on 10/27/2021 2:16:11 PM |
Get the request header information

Posted on 10/29/2021 11:41:48 PM |
Another week passed。。。。。
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com