Request is forwarded from Servlet to JSP using RequestDispatcher. This interface has two method, forward and include. Forward method is used to forward request to the resource (servlet and JSP).
Getting a RequestDispatcher from a ServletRequest. It is suitable for accessing JSP/Servlet in same web application.
RequestDispatcher view=request.getRequestDispatcher("result.jsp");
// It means the result.jsp is relative to current HTTP request
Getting a RequestDispatcher from a ServletContext. It is suitable for accessing JSP/Servlet in other web application.
RequestDispatcher view=getServletContext().getRequestDispatcher("/result.jsp");
//It means that result.jsp is relative to root of the ServletContext. Slash (/) must be used.
Calling forward() on a RequestDispatcher.
view.forward(request,response);
No comments:
Post a Comment