Larry Seabrook wrote:
>
> Hello Everybody,
>
> Is anybody successfully using the RequestDispatcher.forward() method with
> Tomcat to pass control from a servlet to a jsp? I am having nothing but
> problems. There are 3 ways that I know of to obtain a RequestDispatcher
> object for a resource, in this case, a jsp file:
>
> (1) Using ServletContext.getRequestDispatcher(file.jsp): This returns
> NULL for me, even with the full url.
Here you must use a context-relative path, in other words a path that
starts with a slash and is interpreted relative to the context's URI
prefix. So if the URI you would type in a browser to request the
page is /myapp/mydir/file.jsp, you need to use /mydir/file.jsp.
> (2) request.getRequestDispatcher(file.jsp): This returns an object, but
> the object wants to treat file.jsp as a servlet instead of a
> jsp file. It wants to find a class file for file.jsp in the servlet
> directory.
Which version of Tomcat? I believe there was a problem with this in 3.1
but that it works in 3.2 Beta 2. The path must be relative to the URI
for the current request, so if you do this in a servlet invoked with
/myapp/servlets/myServlet, you need to use ../mydir/file.jsp for the
example JSP page above.
> (3) ServletContext.getNamedDispatcher(file.jsp): This method gets a "Null
> Pointer Exception" error.
This should work if you have assigned a name to the JSP file in the
WEB-INF/web.xml file. The argument value must be the assigned name.
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets