tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig McClanahan <>
Subject RE: jsp:forward with URI's beginning with '/'
Date Thu, 13 Apr 2000 17:49:47 GMT

>> >If it is the former (TomCat 3.1 RC1
>> >thinks so), then how do we forward wrt the Web server (to, 
>> say, a static
>> >page not in any Web app, or a JSP/servlet in another 
>> Webapp)? Using absolute
>> >URLs (ugh!)?
>> >
>> You don't.  Forwarding is for use within a web application 
>> only.  You will
>> need to use sendRedirect() to transfer a user outside the 
>> current webapp.
>Craig, this is fine for me since I am forwarding within my web application.
>The problem is that the URI returned by getRequestURI() and the URI accepted
>by <jsp:forward/> don't match up. Is there any method in the servlet API
>that returns relative path of a servlet within the context?

The relative path of a servlet depends on how you've set up the mappings in
your web.xml file.  If you're not using any mappings and just relying on
"/servlet/xxxxx", then the answer is simple:

	<jsp:forward page="/servlet/xxxxx"/>

If you've mapped your servlet to a particular URL, you just use that URL --
the mappings in web.xml are also context-relative.  For example, if you've
got a mapping like this:


then the context-relative URL would be:

	<jsp:forward page="/catalog"/>

Note:  the reason pretty much every path in servlet+JSP is context relative is
so that you can be totally independent of the context path your application
is loaded at.  Note that the above choices work, no matter what your server's
sysadmin chooses.



View raw message