• 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic