• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dispatching request outside of the context

 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm trying to redirect the request from one context to another context.
But the context object which i'm trying to redirect is returned as null.

I have two web-apps named SCWCD,Beer both resides in the webapps in Tomcat.

From SCWCD servlet i'm trying to redirect to Beer servlet.

here goes the snippet

ServletContext context = getServletContext().getContext("/Beer");
System.out.println("context --"+context); // returned as null
//System.out.println(" Context ath=="+context.getContextPath());
RequestDispatcher rd = context.getRequestDispatcher("/first.do");
rd.forward(req,res);
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you have defined the web-app's context path correctly?
Please check, is your another web application up?. Can you access it independently?

Regards,
Shivani
 
Senthil Kumar
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shivani,
I'm able to run the servlet from both the applications.As per the API docs
getContext() path shud be relative to the container's root.But im confused as to what is containers root
 
Daniel Dalton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you're doing looks right, BUT if your servlet container is security conscious it may return null when you try and get a foreign context.
 
Sivasundaram Umapathy
Ranch Hand
Posts: 360
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try running in another container such as resin and let us know what happens.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic