Invoking a JSP Page from a Servlet
You can invoke a JSP page from a servlet through functionality of the
standard javax.servlet.RequestDispatcher interface.
Complete the following steps in your code to use this mechanism:
· Get a servlet context instance from the servlet instance:
ServletContext sc = this.getServletContext();
· Get a request dispatcher from the servlet context instance, specifying the absolute
path of the target JSP page as input to the getRequestDispatcher() method:
RequestDispatcher rd = sc.getRequestDispatcher("/jsp/mypage.jsp");
· Invoke the include() or forward() methods of the request dispatcher, specifying the
HTTP request and response objects as arguments.
rd.include(request, response); or
rd.forward(request, response);
· The functionality of these methods is similar to that
of jsp:include and jsp:forward actions.
Note : To implement MVC Architecture, we use the above technique
Comments
Post a Comment