My web application calls response.sendRedirect("/newapp/home.jsp").
It works fine.
But i am also passing some request parameters which are exposed through request-header.
Is there a way i can use RequestDispatcher to invoke a jsp in another web-app.
I tried::
getServletContext().getRequestDispatcher(newURL).forward(request, response)
But it didn't work.
I am doing this in a Struts action class.
Any ideas?
RequestDispatcher can forward request to the resources running within the webapplication.
It cannot help in forwarding request to another web application.
Harpreet Singh janda wrote:If both the web applications are running on the same server than you can user the forward method to forward the request to other web app.
Can you post the code to get request dispatcher to forward the call to another application in the same server???
Have a look at the getRequestDispatcher method, it comes in two forms. One allows you to access resources from another context in the same web container.
David O'Meara wrote:Have a look at the getRequestDispatcher method, it comes in two forms. One allows you to access resources from another context in the same web container.
Did you guys tried to access??
I am not able to access. Please provide the code if you are able to access.
This never works for accessing resources of other web application.
ServletContext.getRequestDispatcher(java.lang.String) the path must start with '/' (no scope of keeping a URL). So, the resource should always be local to that context root. No options to access different context even if other web application is deployed in same server/ web container.
ServletRequest.getRequestDispatcher(java.lang.String)
The pathname specified may be relative, although it cannot extend outside the current servlet context.
Again the resource should be within the context.
David O'Meara wrote:How about showing what you tried.
Hope that makes sence.
Amarnath Ramasamy
Greenhorn
Joined: Feb 05, 2010
Posts: 7
posted
0
If you are using weblogic, you can call another web app using weblogic.servlet.proxy.HttpProxyServlet class., or even you can use HttpClient. This is another way where in which you can avoid redirect.
[quote=Amarnath Ramasamy]If you are using weblogic, you can call another web app using weblogic.servlet.proxy.HttpProxyServlet class., or even you can use HttpClient. This is another way where in which you can avoid redirect.[/quote]
Can you post the code(If you are sure!..?)
Amarnath Ramasamy
Greenhorn
Joined: Feb 05, 2010
Posts: 7
posted
0
Try this..you can also find several examples on web for httpclient / httpproxy
This never works for accessing resources of other web application.
ServletContext.getRequestDispatcher(java.lang.String) the path must start with '/' (no scope of keeping a URL). So, the resource should always be local to that context root. No options to access different context even if other web application is deployed in same server/ web container.
ServletRequest.getRequestDispatcher(java.lang.String)
The pathname specified may be relative, although it cannot extend outside the current servlet context.
Again the resource should be within the context.
David O'Meara wrote:How about showing what you tried.
Hope that makes sence.
Please read this statement under link I have given before. Have you tried doing this.
"This method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container".