• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

passing information between servlets

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, this seems to be a long one, please bear with me,

I have jsp A, servlet B running on web app 1, and jsp C and servlet D running on web app2.

jsp A invokes servlet B, then B opens a URLConnection to servlet D, and writes some information through the connection. servlet D reads the information through the connection and invokes jsp C, passing .

My question is, how do I delegate control from jsp A over to jsp C? I believe once the URLConnection is closed, the control is still on servlet B of app 1. If I use response.sendRedirect to invoke servlet D after I close the URLConnection, the information I passed through URLConnection will be lost because my request will probably be handled by a new thread of servlet D, correct?

I can not use sendRedirect to pass the information because it is likely to run out of limit.

Thanks for your help.

Arnold
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you using a URLConnection to pass information from Servlet to Servlet?

Why don't you just use setAttribute() and forward the request on.

request.setAttribute(String, Object);
request.getRequestDispatcher("/url_of_servlet").forward(request, response);

Then in the servlet you forward to:

request.getAttribute(String); (make sure you cast it to the appropriate object type)
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot forward between different web apps.
 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
You cannot forward between different web apps.



Bear,
In "SCWCD Exam Study Guide" by Deshmukh & Malavia, it says at the bottom of page 57,
"You cannot directly forward or include a request to a resource in another web application. To do this, you need to get a reference to the ServletContext of the other web application using

this.getServletContext().getContext(uripath);

using this servlet context reference, you can retrieve an appropriate RequestDispatcher object as usual"


I have not tried it, but suspect it's poor design anyway.
-Jeff Walker
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's true, but it assumes that the web apps are on the same server. I got the impression that they were not, but looking back at the OP, it's not clear.

(And no, I've never had the occasion to try it either).
 
arnold yan
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the sake of clarification, the two web apps are sitting on different boxes.

Arnold
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
isn't it weired mates. you mean to say, switch to the different web app right? sorry no solutions with me. but anyways i need to know the way if there is any.
reply
    Bookmark Topic Watch Topic
  • New Topic