Forward request from a jsp to differents servlets
1 posts in topic
Flat View  Flat View

Posted By:   Javier_Martinez
Posted On:   Wednesday, December 26, 2001 03:14 AM

I´d like to forward a request from a JSP to a servlet but the problem is that when I call the JSP I don't know which servlet is gonna be the target of the request.

The target depends on the option selected by the user on its web browser. Do you know how to manage this on JSP´s? It should be as a link on a menu that guides you to different servlets.

Re: Forward request from a jsp to differents servlets

Posted By:   Bozidar_Dangubic  
Posted On:   Wednesday, December 26, 2001 05:11 AM

have each option have the value of the name of the servlet that you want to be accessed when users select that option from the menu. forward all requests to a controller servlet which based on the name can get to the servlet using ServletContext.getNamedDispatcher() method. pass the name of the servlet to this method and forward the request to it. this means that you need to have servlet names as setup in the web.xml in the client code which is not particularly nice so you can setup init parameters or something like to provide the mapping between the values you specify in the options on the client side and the actual names of the servlets deployed in your container. this is if you want to decouple the client from the server a bit further. if you do not care about that, simply have values of the options be names of the servlets you want request forwarded to and you will be good to go. it is pretty simple solution.
About | Sitemap | Contact