This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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?
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.
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.