ServletRequest

ServletRequest Interface

  • An object of ServletRequest is used to provide the client request information to a servlet.
  • Example: content type, content length, parameter names and values, header information, attributes, etc.


  • Methods:
    • public String getParameter(String name): is used to obtain the value of a parameter by name.
    • public String[] getParameterValues(String name): returns an array of String containing all values of the given parameter name. It is mainly used to obtain values of a Multi-select list box.
    • java.util.Enumeration getParameterNames():Returns an enumeration of all of the request parameter names.
    • public int getContentLength(): Returns the size of the request entity data, or -1 if not known.
    • public String getCharacterEncoding(): Returns the character set encoding for the input of this request.
    • public String getContentType(): Returns the Internet Media Type of the request entity data, or null if not known.
    • public ServletInputStream getInputStream() throws IOException:Returns an input stream for reading binary data in the request body.
    • public abstract String getServerName(): Returns the hostname of the server that received the request.
    • public int getServerPort(): Returns the port number on which this request was received.

  • Example: To display the name of the user
    • Step 01: Create .html page & write this code.
    • Step 02: Create servlet class & write this code.
    • Step 03: Run .html page.
    • Step 04: Final output:

Thanks a lot for query or your valuable suggestions related to the topic.

Previous Post Next Post

Contact Form