The ServletRequest is a predefined interface present in javax.serviet package. The object of ServletRequest interface deals with the client request and fetches it to the servlet program. This object is created by the servlet container and is used as the argument of service method (life cycle method).
This interface is also used by javax.http package.
Methods in ServlelRequest
(i) public Object getAttribute(String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.
(ii) public Enumeration getAttributeNames()
Returns an Enumeration containing the names of the attributes available to this request.
(iii) public String getCharacterEncoding()
Returns the name of the character encoding used in the body of this request.
(iv) public intgetContentLength()
Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known. For HTTP Servlets, same as the value of the CGI variable CONTENT_LENGTH.
(v) public String getContentType()
Returns the MIME type of the body of the request, or null if the type is not known.
(vi) public ServletInputStreamgetInputStream() throws IOException
Retrieves the body of the request as binary data using a ServletInputStream.
(vii) public Locale getLocal()
Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.
(viii) public Enumeration getLocales()
Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header.
(ix) public String getParameter(String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist.
(x) public Map getParameterMap()
Returns a java.uti1.Map of the parameters of this request
(xi) public Enumeration getParameterNames()
Returns an Enumeration of String objects containing the names of the parameters contained in this request.
(xii) public String getParameterValues(String name)
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.
(xiii) public String getProtocol()
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1 For HTTP servlets, the value returned is the same as the value of the CGI variable SERVER_PROTOCOL.
(xiv) public BufferedReadergetReader() throws IOException
Retrieves the body of the request as character data using a BufferedReader.
(xv) public String getRemoteAddr()
Returns the Internet Protocol (IP) address of the client that sent the request.
(xvi) public String getRemoteHost()
Returns the fully qualified name of the client that sent the request.
(xvii) public RequestDispatchergetRequestDispatcher(String path)
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
(xviii) public String getScheme()
Returns the name of the scheme used to make this request, for example, http, https, or ftp.
(xix) public String getServerName.()
Returns the host name of the server that received the request.
(xx) public intgetServerPort()
Returns the port number on which this request was received.
(xxi) public booleanisSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.
(xxii) public void removeAttribute(String name)
Removes an attribute from this request. This method is not generally needed as attributes only persist as long as the request is being handled.
(xxiii) public void setAttribute(String name,Object 0)
Stores an attribute in this request. Attributes are reset between requests.
(xxiv) public void setCharacterEncoding(String env) throws Unsupported EncodingException
Overrides the name of the character encoding used in the body of this request.
The ServletResponse is a predefined interface present in javax.servlet package. The object of this interface sends response to the client. Its object is created by the servlet container. To send binary data in MIME body response, we have to use ServletOutputStream returned by getOutputStream. To send text data we will use PrintWriter returned by getWriter.
Melhods in ServlelResponse
(i) public void flushBuffer() throws IOException
Forces any content in the buffer to be written to the client.
(ii) public intgetBufferSize()
Returns the actual buffer size used for the response. lf no buffering is used, this method returns().
(iii) public String getCharacterEncoding()
Returns the name of the charset used for the MIME body sent in this response. lf no charset has been assigned, it is implicitly set to 150-8859-1 (Latin-1).
(iv) public Locale getLocal()
Returns the locale assigned to the response.
(v) public ServletOutputStreamgetOutputStream() throws IOException
Returns a ServletOutputStream suitable for writing binary data in the response. The servlet container does not encode the binary data.
(vi) public PrintWritergetWriter() throws IOException
Returns a PrintWriter object that can send character text to the client.
(vii) public booleanisCommitted()
Returns a boolean indicating if the response has been committed. A commited response has already had its status code and headers written.
(viii) public void reset()
Clears any data that exists in the buffer as well as the status code and headers.
(xi) public void resetBuffer()
Clears the content of the underlying buffer in the response without clearing headers or status code.
(x) public void setBufferSize(int size)
Sets the preferred buffer size for the body of the response.
(xi) public void setContentLength(intlen)
Sets the length of the content body in the response In HTTP servlets, this method sets the HTTP Content-Length header.
(xii) public void setContentType(String type)
Sets the content type of the response being sent to the client.
(xiii) public void setLocaIe(Locale loc)
Sets the locale of the response, setting the headers (including the Content-Type's charset) as appropriate.