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.
|