• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How can a RequestDispatcher call a servlet in another web application?

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the servlet specification 2.3 there is such a statement:

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 callee servlet must be different from those visible to the calling servlet.

 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use the code below to get the servlet context reference. From there, you can retrieve an appropriate RequestDispatcher.

this.getServletContext().getContext(uripath)
 
Yorck Zhou
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anthony!
But when I tried the following fragment code in the Tomcat 4.1. It return a NullpointerException. Is it a bug of Tomcat 4.1?


try{
ServletContext rootContext = getServletContext().getContext("http://localhost:8080/");
System.out.println( ( rootContext.getAttribute("root") ).toString() );
}catch(Exception e){
System.out.println(e);
}

 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to specify the context path of your Web application, not the URL that accessing your website.

Nick
 
Yorck Zhou
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I have also tried a uri as an argument of the getContext() method, but it is still return a NullpointerException!

In the servlet API, I found the following statement about the getContext():

In a security conscious environment, the servlet container may return null for a given URL.



So, should make any change in the Tomcat to make it work?
 
reply
    Bookmark Topic Watch Topic
  • New Topic