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 Redirection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Redirection" Watch "Servlet Redirection" New topic

Servlet Redirection

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I am doing a servlet project right now. On the server-side, I am trying to design a dispatchServlet which will receive the request from the user and dispatch this request to different servlets depending on some conditions.All the reponses will be handled in the latter servlets.So HttpServletResponse.sendRedirect() is not a good choice since all contents of the request will lose. Is RequestDispatcher the only choice? ( RequestDispatcher.forword()?) Any of your suggestion will be very appreciated.

Joined: Jul 06, 2000
Posts: 16
My question to you is why do the "latter servlets" even have to be servlets? Why can't you make them regular Java Classes and have your dispatcher servlet create and call them directly? I have done this exact thing and in fact I am currently using it for internal web applications. The main advantage is that the developers of the "latter" classes don't need to know anything about servlets, but simply the interface with the dispatcher servlet. Also you don't have to worry about forwarding and redirecting.
I agree. Here's the link:
subject: Servlet Redirection
jQuery in Action, 3rd edition