What is the use of RequestDispatcher in servlet?
Answer Posted / kollu sreenivasa rao
When you want send your request to another servlet/jsp from
your servlet, we can use RequestDispatcher.
There are two ways to get reference of RequestDispatcher.
1)If you get requestdispatcher reference from
ServletContext, you have to specify the absolute url as
argument in getRequestDispatcher method like below.
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("/my_other_app/servlet/SomeServlet");
dispatcher.forward(request, response);
2)If you get requestdispatcher reference from
ServletRequeset, you have to specify the relative url as
argument in getRequestDispatcher method like below.
RequestDispatcher dispatcher =
request.getRequestDispatcher("SomeServlet");
dispatcher.forward(request, response);
| Is This Answer Correct ? | 18 Yes | 11 No |
Post New Answer View All Answers
What exactly is a servlet?
What is life cycle of Servlet?
Hello, My project requirement is like I need to create a web page using MVC pattern. I hava a bean class, jsp page, servlet, service and dao. My jsp has two fields. One is dropdown list. The option values has to get populated from the database table. The other one is a text box and its value has to come from database table. As of now I have defined the fields in bean class, got the values from database using arraylists in dao class and I called this from service class. Can anyone please tell me the workflow of how the servlet will get this arraylist and populate the arraylist values as dropdown options in jsp page? Also I would like to know the role of bean class in MVC pattern? Thanks in advance!
What is the difference between jsp and servlet life cycle?
What are the new features added to servlet 2.5?
How do I support both get and post from the same servlet?
Explain the difference between jsp and servlet?
What is the default http method in the servlet?
What must be implemented by all servlets?
How can you create a session in servlet?
When a servlet accepts a call from a client, it receives two objects. What are they?
When to use doget() and when dopost()?
What is the use of servlet context?
What are the life-cycle methods for a servlet?
Can a jsp be called using a servlet?