Response to a Servlet Request

Tomcat will also pass your servlet one of these response objects as an argument. The object has lots of methods that let you give values to its fields. You send back the actual data by writing to a print writer that you get from the response object.

Table 26-5 shows the most frequently called methods of your response object, the HTTP servlet response.

You will invoke these methods on the javax.servlet.http.HttpServletResponse parameter, as shown in the example coming up. There are about 20 methods in HttpServletResponse and its parent class, ServletResponse, allowing just about any field to be set and returned to the browser. There are about 20 static final variables giving names to each of the status codes. You should review the javadoc descriptions of these classes.

There are about a dozen HTTP headers, but you can ignore them unless you need the special effects that they cause. The content type is the only one you need to set. You can also look a few pages further on in this chapter, in ava Server Pages on page 710, where we write a JSP program to echo the headers received from the browser. That shows you some typical headers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.225