Methods of ServletRequest Interface

Estudies4you
Methods of ServletResponse Interface
Interfaces
  • Servlet Interface: This is the interface that declares life cycle methods of Servlet. So the reason, any of your classes to behave as Servlet must implement the Servlet Interface (or) extend any class that implemented Servlet Interface
  • ServletRequest Interface: This is the interface that helps the servlet to get the client request related details

Methods of ServletRequest Interface
String getServerName( )
Returns the server name
int getServerPort( )
Returns the port number
String getScheme( )
Returns the URL scheme (ftp, http)
Object getAttribute(String attr)
Returns the value of the attribute `attr’
String getContentType( )
Returns the type of the request. Text/html/binary
ServletlnputStream
getlnputStream( ) throws IOException
Returns a ServletlnputStream that is used to read binary data from the request
String getParameter(String par)
Returns the value of the parameter named 'par’
String[ ] getParameterValues (String name)
Returns an array containing values associated with the parameter specified by name

  • ServletResponse Interface: This is the interface that helps the servlet to get the prepare response to client

Methods of ServletResponse Interface
PrintWriter getWriter( )
throws IOException
Returns a PrintWriter that can be used to write character data to the response.
void setContentLength(int size)
Sets the content length for the response to size.
void setContentType(String type)
Sets the content type for the response to type.
ServletOutputStream
getOutputStream( ) throws IOException
Returns a ServletOutputStream that can be used to write binary data to the response.
String getCharacterEncoding( )
Returns the character encoding for the response.


To Top