When servlet accepts a request from a client, it recieves two objects, ServletRequest and ServletResponse.
ServletRequest includes the communication from client to server and ServletResponse includes the communication from server to client.
Suppose on a jsp\html page we have a form with input texts and button. When we click on button after providing some input then request gets transferred to servlet with provided input as specified in form tag and web.xml
On servlet we are provided with below methods to get that provided input data:
ServletRequest.getParameter(String name): It returns the value of named parameter as String or null.
ServletRequest.getParameterValues(String name): It returns the values of named parameter as String array if parameter has multiple values. We can use it in case of multiselect check boxes.
ServletRequest.getParameterNames(): It returns al list of parameter names from form.
Request contains a lot of header information. Some of them mentioned below:
1) Accept-It specifies the MIME type which clients accept.
2) Accept-Languages-It specifies the languages which clients recieve.
3) Accept-Encoding-It specifies the types of encodings that the browser knows how to handle. Values of gzip or compress are the two most common possibilities.
4) User-Agent-It gives information about client software(browser).
5) Cookie-It returns cookies to servers that previously sent them to the browser.
6) Content-Length-It is applicable to POST request and gives the size of POST data in bytes.
It consist of three things-
Response Body which contains output
Status Codes: Http status codes returned by server to the client. It is three digit integer value which gets specified as:
4**: Client Error
5**: Server Error
Header Information: Some of Http response header information are as follows:
1) Cache-control- It tells all caching mechanism from server to client whether they may cache this object.
2) Expires- It gives date and time after which the response is considered as expired.
3) Refresh- It is used to specify when response will get refreshed automatically.
4) Set-Cookie- It specifies a cookie associated with the page
5) Connection- It is used to indicate whether the server is willing to maintain as open connection to the client.