HomeJava & J2EE Page 7 - The JSP Files (part 3): Black Light And White Rabbits
A Positive Response - Java
This week, learn all about the different types of loops supportedby JSP, and also expand your knowledge of the various String objectmethods. Finally, take a quick tour of the JSP Response object inpreparation for learning how JSP handles form data.
Another interesting object, and one that comes in handy in the oddest places, is the Response object. As opposed to the Request object, which is used to retrieve information (come back next time for more on this), the Response object is typically used to send information to the browser; this information could include HTTP headers, redirection URLs, cookies and a variety of other items.
Since the Response object is an "implicit" object (so called because you do not need to explicitly create an instance of the object when you want to use it), you can begin using it immediately in a JSP document. The following example demonstrates using it to turn off caching via the "Cache-Control" header.
You can set the MIME type of a document with the
setContentType() method.
<%
response.setContentType("image/jpeg");
%>
and even set a cookie with the addCookie() method -
more on this as we progress through this series.
That's about all we have time for. Next time, we'll be exploring the JSP Response object, used to process data from HTML forms...so you don't want to miss that one!
Note: All examples in this article have been tested on Linux/i586 with Tomcat 3.2 and JServ 1.1. Examples are illustrative only, and are not meant for a production environment. YMMV!