aspose file tools*
The moose likes Servlets and the fly likes Interesting statement in Servlet 3.0 specification (RequestDispatcher) 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 "Interesting statement in Servlet 3.0 specification (RequestDispatcher)" Watch "Interesting statement in Servlet 3.0 specification (RequestDispatcher)" New topic
Author

Interesting statement in Servlet 3.0 specification (RequestDispatcher)

Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3204
    
    5
Hi All !

I was reading today Servlet 3.0 specification and noticed some confusing statement regarding RequestDispatcher in HttpSession chapter.

[7.3] Session Scope:


To illustrate this requirement with an example: if a servlet uses the
RequestDispatcher to call a servlet in another Web application,
any sessions
created for and visible to the servlet being called must be different from those visible
to the calling servlet.


I always assumed that RequestDispatcher can be used for forwarding only within the same web app. And if we need to redirect user's browser to another web app, we must use response.sendRedirect (but this is another story).

So, could someone comment on this? Is it really possible to forward to another web app using RequestDispatcher as stated in highlighted with red quote, or this is only hypothetical example? Maybe specification should be more clear in this section, and choose another example to demonstrate that session is not shared with other app contexts?

Best regards,
MZ


Free SCDJWS 5.0 Study Guide - SCDJWS 5.0 Quiz (How to get SCDJWS 5.0 Quiz)
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Well there is a getContext(String uri) method in the ServletContext class. You can call that method to get a ServletContext instance of another web application. Then on that ServletContext instance you can call getRequestDispatcher()...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Mikalai Zaikin
Ranch Hand

Joined: Jun 04, 2002
Posts: 3204
    
    5
Howdy Ankit !

Thank you for the clarification. I see that it's possible 8-)

Thanks,
MZ

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It's possible but, because a lot of the details were left out of the spec, it's not very portable.
If you're going to go down that road, you need to really test things in the containers you plan to support as certain things will be different from container to container.

From reading your quote, it looks like 3.0 clarifies some of these things.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
 
subject: Interesting statement in Servlet 3.0 specification (RequestDispatcher)