Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes 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!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic