File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlet chaining Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet chaining" Watch "servlet chaining" New topic

servlet chaining


Joined: Jun 04, 2001
Posts: 2
can anyone tell me the exact purpose of using servlet chaining
probably with an example???
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13027
Servlet chaining was a way of passing the response from one servlet to another servlet as part of the request (as I understand it). I think this was never part of the official API, but something added by some vendors.
The latest API 2.3 has "Filters" which provide a formal method of specifying a filter that looks at and may modify a request before sending it on to a servlet, also the same thing on the output end. As it happens, I am just now reading the comments on Filters in the Tomcat 4.0 distribution:
"You can now register Filters in the web.xml file that are the application level analogue to Valves in the Catalina core. Filters have the following general features:
- Filters can be mapped to either URL patterns or particular servlets
- Filters can pre-process and post-process requests and responses
- Filters can wrap the request and/or response objects that are passed on
(so you can do content type transformations, for example)
- Filters can respond to a request and return, instead of passing the request on (for example, you can do authentication challenges at the app level)
Related to this, servlets can now do the same sort of wrapping when they pass arguments to a RequestDispatcher. Previously, you were required to pass the original request and response objects received from the container.
Some uses that occur to me:
Transformation of XML output of a servlet by a filter using a selected XSL transform.

author of:
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Consider Paul's rocket mass heater.
subject: servlet chaining
It's not a secret anymore!