The REQUESTDISPATCHER object is used to reference or jump to other JSP or servlets. In the previous article, I use the request object to do it. In fact, you can use the servletContext object using the jump:
Public RequestDispatcher getRequestDispatcher (String URL)
Public RequestDispatcher getnameddispatcher (String name)
When using the getRequestDispatcher method, be careful, the latter URL must begin with "/", this URL is the virtual path you on the web, and the parameters after using the getNamedDispatcher method is set in the web.xml file. The name of the corresponding servlet file.
Such as:
There is a setting in Web.xml:
If you get this servlet resource with servletContext, use the following statement:
RequestDispatcher D = getServletContext (). GetRequestDispatcher ("/ loginservlet");
RequestDispatcher D = getServletContext (). Getnamedispatcher ("/ loginservletname);
The above is two different setup methods, but the point to which points is the same.