Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

getRequestDispatcher forwarding across applications

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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:
http://localhost:8080/app1/index.jsp
...that tries to forward to:
http://localhost:8080/app2/myServlet

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

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

It returns null.

I could use:
response.sendRedirect("/app2/myServlet");
But that sends the response back to the user before requesting the servlet, and would rather not use it if possible. :-/

Thanks!

David
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at:
public ServletContext getContext(java.lang.String uripath)

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html

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.
 
David Miranda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try that!

Thanks Ben!
 
David Miranda
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hrmmm

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

Thanks!

David
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic