aspose file tools*
The moose likes Servlets and the fly likes JSP- Servlet communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP- Servlet communication" Watch "JSP- Servlet communication" New topic
Author

JSP- Servlet communication

shawn kennedy
Ranch Hand

Joined: Oct 31, 2002
Posts: 67
Hi,
I would like to know how could the following be done
If i have a jsp page and want to transfer control to a servlet1 perform some processing there and then transfer control to servlet2 perfrom some computations there then take the data from servlet2 and servlet1 and transfer it to the jsp page.Could some one help me please
Ken Robinson
Ranch Hand

Joined: Dec 23, 2003
Posts: 101
Using the <servlet> tag in web.xml, declare both servlet1 and servlet2. Using the <servlet-mapping> tag in web.xml, give each servlet it's own URL. Have the starting JSP/HTML contain servlet1's URL as it's action. Once processing in servlet1 is done, get a RequestDispatcher using the URL for servlet2 and forward. Once servlet2 is done it's work, get a RequestDispatcher using the URL of the servlet you want to display as the final JSP.
Think of each JSP getting it's own implicit <servlet> and <servlet-url> tag. The RequestDispatcher allows you to send a request to any resource, declared explicitly or implicitly.
shawn kennedy
Ranch Hand

Joined: Oct 31, 2002
Posts: 67
how do i pass the data got from servlet2 back to servlet1 and then data from servlet1 and servlet2 back to jsp in a request dispatcher am i suppose to use request.setattributes()method to do tht
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP- Servlet communication