• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I run multiple servlets before loading a jsp?

 
shashank dwivedi
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 21000
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21000
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic