Defines an object to assist a servlet in sending a response to the client. The servlet container creates a ServletResponse object and passes it as an argument to the servlet's service method. To send character data, use the PrintWriter object returned by getWriter. To mix binary and text data, for example, to create a multipart response, use a ServletOutputStream and manage the character sections manually. String and setContentType java. String methods, or implicitly using the setLocale java.
The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp. This interface can also be used to include the content of another resource also. It is one of the way of servlet collaboration. As you see in the above figure, response of second servlet is sent to the client.
These methods are available with HttpServletResponse object. This method sets an arbitrary status code. The setStatus method takes an int the status code as an argument. If your response includes a special status code and a document, be sure to call setStatus before actually returning any of the content with the PrintWriter. This method generates a response along with a Location header giving the URL of the new document.
There are given 6 steps to create a servlet example. These steps are required for all the servers. The mostly used approach is by extending HttpServlet because it provides http request specific method such as doGet , doPost , doHead etc. The directory structure defines that where to put the different types of files so that web container may get the information and respond to the client. The Sun Microsystem defines a unique standard to be followed by all the server vendors.