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?
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.
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.
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.