aspose file tools*
The moose likes Servlets and the fly likes How can I run multiple servlets before loading a jsp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can I run multiple servlets before loading a jsp?" Watch "How can I run multiple servlets before loading a jsp?" New topic
Author

How can I run multiple servlets before loading a jsp?

shashank dwivedi
Ranch Hand

Joined: Mar 06, 2012
Posts: 61

I want to run more than one servlets on loading a jsp.
I don't want to copy all logic to write in a single servlet as it is a bad idea. Each controller should have it's own purpose.
But can i really run more than one servlets on loading a particular jsp?
I did something in web.xml like

<servlet>
<servlet-name>s1<servlet-name>
<servlet-class>Controller.MyServlet1</servlet-class>
<servlet-name>s2<servlet-name>
<servlet-class>Controller.MyServlet2</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>s1<servlet-name>
<servlet-name>s2<servlet-name>
<url-pattern>/loadServlet.do</url-pattern>
</servlet-mapping>

I am not sure it is correct way as it's not working.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

shashank dwivedi wrote: But can i really run more than one servlets on loading a particular jsp?


Well, no, that isn't a good idea either. As you yourself say, each controller should have its own purpose. If the controller (the one servlet) needs to execute code which is in some other servlets, then perhaps the code in the other servlets should be in a class whose methods can be called from many servlets. Or perhaps your controller servlet ought to be forwarding to the other servlet. It's hard to say without knowing your requirements. However it is possible to say that the idea of having lumps of code isolated in servlets and then needing to execute more than one of those lumps needs revising.
shashank dwivedi
Ranch Hand

Joined: Mar 06, 2012
Posts: 61
no actually i am not calling one servlet from another servlet rather what i want is something like

run controller 1 with controller1 specific logic
run controoler 2 with controller2 specific logic

then pass logics to my jsp page!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

No, why can't we just have a rational design? Your JSP needs a controller? Of course it does. Then write one. If you think it needs two controllers then you did something wrong in your design.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I run multiple servlets before loading a jsp?