World's most popular travel blog for travel bloggers.

Ques : Describe Interface HttpServletRequest

, , No Comments

The HttpServletRequest interface captures the functionality for a request object that is passed to a HTTP servlet. It provides access to an input stream and allows the servlet to read data from the client. The HttpServletRequest interface extends the ServletRequest interface.

public interface HttpServletRequest extends ServletRequest

The servlet container creates an HttpServletRequest object and passes it as an
argument to the servlet's service methods (doGet, doPost etc). The HttpServletRequest
interface has many methods. Some of the commonly used methods of HttpServletRequest are:

  1. getParameter()
    It returns the value associated with a parameter sent to the servlet as a part of a
    GET or POST request. The name argument represents the parameter name.
    public String getParameter(String name)
  1. getQueryString()
    It returns the query string that is contained in the request URL if any. This
    method returns null if the URL does not have a query string. A query string is
    defined as any information following a ? character in the URL.

public String getQueryString()

  1. getCookies()
    The getCookies() method returns an array of Cookie objects found in the client request. This method does not take any parameters and throws no exceptions. Cookies are used to uniquely identify clients to servlet. In case of no cookies in the request, an empty array is returned.

public Cookie[] getCookies()

  1. getHeader()
    It returns the value of the specified request header as a String. In case if the request did not include a header of the specified name, this method will return null. If there are multiple headers with the same name, this method returns the
    first header in the request. The header name is case insensitive.
    public String getHeader(String name)

5. getMethod
It returns the name of the HTTP method used to make the request. Typical return
values are ‘GET’, ‘POST’, or ‘PUT’
public String getMethod()

  1. getSession()
    It returns the current session associated with the request or if the request does not
    have a session, creates one.

public HttpSession getSession(boolean create)
public HttpSession getSession()

0 comments:

Post a Comment

Let us know your responses and feedback