aspose file tools*
The moose likes Servlets and the fly likes Can we use RequestDispatcher to access another web application servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can we use RequestDispatcher to access another web application servlet" Watch "Can we use RequestDispatcher to access another web application servlet" New topic
Author

Can we use RequestDispatcher to access another web application servlet

Mukesh Mittal
Ranch Hand

Joined: Jan 13, 2006
Posts: 31
Hi

If we have two web application (Web Application A and Web Application B) in the same EAR file. Can we use requestDispatcher from Web Application A to call Web Application B servlet.


I Checked the servlet 2.4 spec. In Section SRV.7.3 its mentioned

"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 think this indicates, we can call servlet from different web application.But in another place SRV.8.1

"The getRequestDispatcher method takes a String argument describing a
path within the scope of the ServletContext."



Can we access Servlet from different web application?
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
From browsing the API, it looks like your ability to forward to a separate web app on the same server will depend on the manner in which you go aboout getting your RequestDispatcher object.

I know of two ways to get a RequestDispatcher object: from the request or from the the ServletContext.

It sounds like the RequestDispatchers obtained from the request must point to a resource on the same web app: api

In contrast, the APi documentation for the ServletContext method that returns a RequestDispatcher suggests that the resource could be a differnt web app, provided that the resource is in the same context root: api

I've not tested using the ServletContext to obtain a RequestDispatcher for a resource in a different web app in the same container, but it sounds like it would work based on what the api has to say. If you try out that method, please let me know how it worked for you.


Fun programming etcetera!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39575
    
  27
It depends on the servlet container whether a RequestDispatcher can be obtained for a resource in a different context. E.g., Tomcat has the crossContext attribute for determining whether that's allowed; it's documented here.


Ping & DNS - updated with new look and Ping home screen widget
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Wow, you guys are blowing my mind!

I was almost positive that you couldn't use the request dispatcher to forward outside of the current war file, which is pretty much defined by a context root. I mean, I thought the ServletRequest and ServletResponse was good only withing the web app in which it was created.

Crazy. I'll have to test it.

-Cameron McKenzie
Mukesh Mittal
Ranch Hand

Joined: Jan 13, 2006
Posts: 31
Thank you very much for the responses.

I will check this fuctionality on Websphere.


Thanks

Mukesh Mittal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we use RequestDispatcher to access another web application servlet
 
Similar Threads
session, mock, p 274 - 7 c - is correct?
Session Scope
request dispatcher
HTTPSession scope, multiple WAR's, multiple EAR's
Interesting statement in Servlet 3.0 specification (RequestDispatcher)