Wednesday, August 12, 2009

How can i call another Servlet or JSP from the current Servlet ?

One of the previous methods for calling another servlet was

HelloServlet hello = (HelloServlet)getServletConfig().getServletContext().getServlet("hello");

From Servlet API version 2.1, this method has been deprecated and the preferred method is to use RequestDispatcher. Here is the syntax for it,

getServletContext().getRequestDispatcher("/jsp/hello/hello.jsp").forward(req, res);

No comments:

Post a Comment