This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes How can I dispatch Requests to >1 JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can I dispatch Requests to >1 JSP?" Watch "How can I dispatch Requests to >1 JSP?" New topic
Author

How can I dispatch Requests to >1 JSP?

Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
Hi,
Does anyone have a good reference they can point me to, or just some sample code, on dispatching a Request from a servlet to more than one JSP? I have two include files in a larger page that need to receive Vectors with, respectively, up to 64 objects and up to 256 objects. I'd like to keep the processing for those two sets of data as separate as possible.
My plan was that a request would come to the servlet, it would call two discrete beans to do the processing, get the results back, and dispatch them to two different pages.
Any helpful thoughts?
Thanks!
g.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Same procedure as this post:
http://www.coderanch.com/t/280687/JSP/java/Displaying-Dynamic-Tables
/Rene


Regards, Rene Larsen
Dropbox Invite
Steve Chernyak
Ranch Hand

Joined: Oct 19, 2000
Posts: 113
You could store the vector into the request object and then use the include method to pass control to a JSP page, then after the first jsp was done do the same for the second.
Let me know if I misunderstood your question.
Hope this helps.
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
I think I'm probably not being clear enough.
I'm trying to work out the design in such away that the two Vectors never have to coexist anywhere, excepting when they are passed through some controlling servlet. Also, when the servlet has done its job, I need to pass control back to the main JSP which includes the two smaller ones. I'd like to find a way not to pass my generated data to the big JSP, but rather, to pass each set of results to the appropriate include file.
Is that possible?
Steve Chernyak
Ranch Hand

Joined: Oct 19, 2000
Posts: 113
I think I understand:
You only want the vectors available in the scope of the includes. Is that right?
If yes, then I dont know of anyway to declare them outside of that include itself.
You could use some thing like a JavaBean or a taglib inside the include and declare the vector with the page scope.
Garann Means
Ranch Hand

Joined: Jan 28, 2002
Posts: 214
Steve,
You're saying just call the bean directly from the included page, don't try and pass it through the servlet? That seems good to me.
But how, then, do I get the included pages to refresh their data? I.e., I have a form in the parent page that takes the input used to generate the data for the includes. If my guess is correct, I should use the servlet the form submits to to pass the request to each of the include pages, then leave them to do their work separately using their own beans. Is that correct?
Thank you for your help!
g.
Steve Chernyak
Ranch Hand

Joined: Oct 19, 2000
Posts: 113
When the main jsp includes the other two all three of them have access to the request. You can use the scripting variable "request", so you don't need to explisitly pass it from include to include (this is already done for you when using jsps).
If the processing that the included JSPs will be doing is for presentation logic that is dependant on previous input from the user then I dont think you need the servlet to do any of the includes logic.
In my opinion the servlet could recieve the request, and if there is no processing other then what to present next, i would just have servlet forward to the main jsp, and include the other two from there.
 
Consider Paul's rocket mass heater.
 
subject: How can I dispatch Requests to >1 JSP?