You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Steve Haines <sh...@ipnet-solutions.com> on 2000/05/08 19:54:05 UTC
RequestDispatcher from Servlet to JSP
I have a servlet that I am using to do some processing and then I want to
subsequently forward the request to a JSP page for presentation. The forward
works fine to get me to the JSP page, but the servlet URL stays in the
browser so the JSP page cannot access its resources (e.g. images).
Here is my file layout:
webapps/myapp/myjsppage.jsp
webapps/myapp/images/myimage.gif
webapps/web-inf/classes/com/mypackage/myservlet.class
So from the web server I access the page:
http://localhost:8080/servlet/myservlet?param=value
And in my Servlet's service() method I make the following call to
RequestDispatch:
String jsp = "/myjsppage.jsp";
RequestDispatcher dispatcher;
// All of these work the same:
//dispatcher = getServletContext().getRequestDispatcher( jsp );
//dispatcher = context.getRequestDispatcher( jsp );
dispatcher = req.getRequestDispatcher( jsp );
dispatcher.forward( req, res )
And my "myjsppage.jsp" page is displayed without access to any of its images
(e.g. "myimage.gif")
The page should be:
http://localhost:8080/myjsppage.jsp
but it stays:
http://localhost:8080/servlet/myservlet?param=value
Any ideas how I can actually redirect the browser (without using
sendRedirect()) to the jsp page where it can access its resources??
Thanks!
Steve
RE: RequestDispatcher from Servlet to JSP
Posted by Fernando Salazar <fs...@quickdot.com>.
> Any ideas how I can actually redirect the browser (without using
> sendRedirect()) to the jsp page where it can access its resources??
>
> Thanks!
> Steve
>
I don't believe that what you describe can be done without a redirect.
You could include a <BASE> tag in your jsp, eg:
<HEAD>
<BASE href="/myjsppage.jsp">
...
</HEAD>
That should give the page access to its resources, but
the URI will still display in the browser as originally entered.
- Fernando