creates ServletRequest object from client request and pass it to the servlet service() method for
processing.
Some of the important methods of ServletRequest interface are:
• Object getAttribute(String name) – This method returns the value of named attribute as Object
and null if it’s not present. We can use getAttributeNames() method to get the enumeration
of attribute names for the request. This interface also provide methods for setting and removing
attributes.
• String getParameter(String name) – This method returns the request parameter as String. We
can use getParameterNames() method to get the enumeration of parameter names for the
request.
• String getServerName() – returns the hostname of the server.
• int getServerPort() – returns the port number of the server on which it’s listening.
The child interface of ServletRequest is HttpServletRequest that contains some other methods
for session management, cookies and authorization of request.
ServletResponse interface
ServletResponse interface is used by servlet in sending response to the client. Servlet container creates the
ServletResponse object and pass it to servlet service() method and later use the response object to
generate the HTML response for client.
Some of the important methods in HttpServletResponse are:
• void addCookie(Cookie cookie) – Used to add cookie to the response.
• void addHeader(String name, String value) – used to add a response header with the given
name and value.
• String encodeURL(java.lang.String url) – encodes the specified URL by including the session
ID in it, or, if encoding is not needed, returns the URL unchanged.
No comments:
Post a Comment