javax.servlet.http.HttpServletRequest interface

This interface extends ServletRequest interface and provides the client request information for Http Servlet. The Servlet engine creates an object that implements HttpServletRequest and passes it as an argument to the servlet’s servicing methods. List of important methods in this interface

•     String getMethod(): – It returns the name of the HTTP method with which this request is made.

•     String getQueryString(): – Returns the query string that is contained in the request URL after the path. This method returns null if the URL does not have a query string.

•     HttpSession getSession(): – Returns the current session associated with the request.

•     void setAttribute(String name, Object value): – It stores an attribute in the request object.

•     Object getAttribute(String name): -Returns the value of the named attribute as an Object, or null if the request has no attributes.

•     Enumeration getAttributeNames(): – Returns an Enumeration containing the names of the attributes available in this request. This method returns an empty Enumeration if there are no attributes for the request object.

•     boolean isRequestedSessionldFromCookie(): – It returns true if the session id came in as a cookie; otherwise, false.

•     boolean isRequestedSessionIdFromURL(): – It returns true if the session id came in as a part of URL; otherwise, false.

•     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 query string.

•     Cookie[] getCookies(): – Returns an array containing all of the Cookie objects the client sent with this request. This method returns null if no cookies are sent.

•     String getHeader(String header): – Returns the value of the specified request header as a String. If the request does not include a header of the specified name, this method returns null.

•     Enumeration getHeaderNames(): – Returns an enumeration of all the header names this request contains.

•     int getContentLength(): – Returns the length, in bytes, of the request body made available by the input stream. Returns -1 if the length is not known.

•     String getContentType(): – Returns the MIME type of the body of the request, or null if the type is not known.

•     String getParameter(String name): – Returns the value of the request parameter as String, or null if the parameter does not exist.

•     Enumeration getParameterNames(): – Returns an Enumeration of String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty Enumeration.

•     String getProtocol(): – Returns the name and version of the protocol the request uses in the form protocol/major version.minor version, for example, HTTP/1.1

•     String getServerName(): -Returns the host name of the server to which the request was sent. It is the value of the part before ":" in the Host header, if any, or the resolved server name or the server IP address.

•     String getRemoteHost: – Returns the fully qualified name of the client or the last proxy that sent the request. If the container cannot or chooses not to resolve the hostname, this method returns the dotted-string form of the IP address.

•     int getServerPort(): – Returns the port number to which the request was sent.