File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we use RequestDispatcher to access another web application servlet

 
Mukesh Mittal
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 262
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much for the responses.

I will check this fuctionality on Websphere.


Thanks

Mukesh Mittal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic