This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispather

 
saiprasad raut
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In HF book i saw the example for RequestDispatcher forwarding to JSP.
How do we forward request to Servlet?

Is it something like this?

RequestDispatcher rd = request.getRequestDispatcher("MyServlet");

rd.forward(request, response);

Let me know if this is right??
 
Fraund Bei
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When u foward to a jsp,u use RequestDispatcher rd=request.getRequestDispatcher("myWebApp/myJSP.jsp");,so it is the same rule when u foward to a servelt by RequestDispatcher rd=request.getRequestDispatcher("myWebapp/myServlet");

anyone correct me if im wrong
 
Jagadesh Rangasamy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RequestDispatcher rd = request.getRequestDispatcher("/MyServlet");

Yeah! what you said is right.But you need to do little change with this.While mentioning out servletalias name you need to give the root directory as "/MyServlet".Also before using Requestdispatcher, be sure that you get the corresponding servletcontext of particular web application(i.e., within the web server where it is used to store servlets).
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use RequestDispatcher with servlets too, or any other resource for that matter. The arguement you pass to the getRequestDispatcher method is the path to whatever resource you want to use.
[ April 13, 2005: Message edited by: Paul Bourdeaux ]
 
saiprasad raut
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for the help!!!
 
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!