42
Chapter 4 Using Servlets and JSP
Servlets answer a request by constructing an HTTP response and sending that response
back to the client. Within your servlet, you access the HTTP response to write
information within the response that is sent back to the client.
You can access HTTP response information in the following ways:
•
In a Java Servlet, use the
javax.servlet.HttpServletResponse
object, which
defines methods for accessing the information stored within the response.
•
In a JSP, use the implicit JSP object
response
. You can use the same methods with
the response object as you can with the
javax.servlet.HttpServletResponse
object.
The HTTP response includes an output stream for sending results back to the client.
Writing results back to the client
With servlets, you can return dynamic content to the requesting client. That output is
generated based on information passed to the servlet or on information that the servlet
calculates. For example, a servlet can use a passed form attribute (accessed using the
request object) to return formatted database data. Alternatively, if the application has a
method of maintaining user preferences, the servlet might set the display color of the
browser based on stored preference information.
You return information through the HTTP response, in the following ways:
•
Servlets use the
javax.servlet.HttpServletResponse
object’s
PrintWriter
or
ServletOutputStream
interfaces. These interfaces include
println
and
methods, which let you write to the output stream.
•
JSPs use the implicit JSP object
out
. The
out
object also includes
println
and
methods.
Using servlet filters
The Servlet 2.3 specification introduces servlet filters, which give you access to the
HTTP request and response objects for pre- and post-processing.
Filters
process request
objects before they get to the server, or process response objects after they leave the server
and before they are returned to the client. You can also invoke filters in a chain so that
one filter can pass the request or the response to another in the chain, and so on. You can
use filters to do the following tasks:
•
Take flow-control logic out of web application components.
•
Examine and modify the request object before the server receives it from the client.
•
Examine and modify the response object before the client receives it from the server.
•
Change the content of the response.
For more information on using filters, see JRun Programmer’s Guide.
Содержание 38000382 - Macromedia JRun - Mac
Страница 1: ...Getting Started with JRun...
Страница 16: ......
Страница 68: ...54 Chapter 5 Introduction to EJB...
Страница 82: ......
Страница 110: ...96 Lesson 3 EJB Tutorial...
Страница 128: ...114 Lesson 4 Web Services Tutorial...
Страница 132: ...118 Index...