File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes getRequestDispatcher forwarding across applications Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "getRequestDispatcher forwarding across applications" Watch "getRequestDispatcher forwarding across applications" New topic

getRequestDispatcher forwarding across applications

David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34

Is it possible to use the RequestDispatcher.forward() method to forward to a servlet in a different context path?

For example:

I have the following jsp:
...that tries to forward to:

Here is the code that I am using in index.jsp:

RequestDispatcher rd = request.getSession().getServletContext().getRequestDispatcher("/app2/myServlet");

It returns null.

I could use:
But that sends the response back to the user before requesting the servlet, and would rather not use it if possible. :-/


Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Look at:
public ServletContext getContext(java.lang.String uripath)

Depending on the container, you may need to do some configuring (lower security) to allow this.
In Tomcat, you would set the crossContext property to true in your <Context../> entry.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34
I'll try that!

Thanks Ben!
David Miranda
Ranch Hand

Joined: Mar 14, 2005
Posts: 34

Any idea how to get another app context using ServletContext.getContext(String uripath) in Weblogic 8.1?


I agree. Here's the link:
subject: getRequestDispatcher forwarding across applications
It's not a secret anymore!