Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Forwarding request to another servlet (from a servlet)

 
Varun Nayudu
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have 2 questions:
1>
How do we pass a request to another servlet through a request.getRequestDispatcher().

2>
And is there a way to invoke the container from a servlet to search for a servlet in the web.xml.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Varun Nayudu:
1>
How do we pass a request to another servlet through a request.getRequestDispatcher().

request.getRequestDispatcher("/target.jsp").forward(request,response);


2>
And is there a way to invoke the container from a servlet to search for a servlet in the web.xml

request.getRequestDispatcher("/target.do").forward(request,response);// target.do is the url-pattern in web.xml

Hope This Helps
 
Lakshmi Narayanan
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
other way is using servletcontext.

this.getServletContext().getRequestDispatcher("/start.jsp").foward(req,res)

difference is / is mandatory.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!