• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet Chaining??

 
Harpreet Hira
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could any one explain how we can do servlet chaining. How is it different from forwarding to a servlet using RequestDispatcher.
Thanks in anticipation
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Servlet chaining, the output produced by one servlet becomes the input for the next servlet in the chain. This can continue any number of times and the final output produced by the last servlet in the chain is what is returned to the client; unless of course an error occurs in between.
In Servlet forwarding, one servlet completely delegates the job of building the response to another servlet. Note that the forwarded servlet works directly on the request parameters, but not the content generated by the forwarding servlet.
To give you an anology, servlet chaining is like a relay race where one player passes the torch on to the next one and so on, until the last player. Whereas servlet forwarding is like football where once you pass the ball on to the next player, your job is pretty much done.
Hope that helps!
 
Rashid Ali
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A very well described answer Ajith.
Thanks for being with us.
Rashid Ali
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On a side note, I did read here (Bill Brogden ?)
(not sure this forum or JSP forum) that the concept of servlet chaining is superseeded by Filters. Not sure how filters are used but yes I am very positive I read that. Try a search in these two forums with the keyword "chaining".
I will try as I get time today.
regds.
- satya
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chk this out.....
So, basically you are better off with Filters or going through the RequestDispatcher....seems like!
- satya
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right. Filtering is a superior and recommended alternative to servlet chaining. My omission was intentional so as to not confuse the questioner with details. But I think this is really important to know.
I beg to differ, however, with using filters for dispatching. Dispatching is clean and efficient and very viable solution if your servlet chain has only two servlets.
Filters are really cool since they allow us to intercept a servlet's invocation before the servlet is called. Intercepting here really means you can inspect, modify request parameters as well as response headers(!) even before the control goes to service() or doXXXX methods. This is a very powerful feature, even outside the chaining scenario. Whats more, filters can be chained too
A very nice article on filters on Servlets.com (where else? ) is worth reading.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, are filters included in the objectives? Even otherwise, have people seen questions on filters in the test?
I am really interested to know...
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
YUp, I have read from people that some qstns on Filters were in their exam. So for I care, they are in the exam whether they are in the obj's or not.
Also, just clarifying my earlier point on dispatching....From what I understood, either Filters or RequestDispatch is preferred to Servlet Chaining. I hope I am clear.
regds.
- satya
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ajith, filters are not included in the exam objectives...but a few of ppl got 1 filter option as a possible answer in their answer options (I didn't get any). I don't think it should be learnt for exam purpose. But as its the newset choice in servlet 2.3 spec that is far advantagous than older servlet chaining options, real world projects can never avoid filtering i think...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic