tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <Craig.McClana...@eng.sun.com>
Subject Re: jsp:forward bug???
Date Sat, 03 Jun 2000 18:29:16 GMT
Torsten Glunde wrote:

> Hi,
>
> I just wondered what sence a forward would make, if relative links within the resulting
> page are broken because the clients context is still in the refering page. But as a
> conclusion I will add a paramter to let the forwarded page now about the context it is
> running after the jsp:forward and let the relative links be dynamically generated.
>

Forwards are very useful when you are building an app based on model-view-controller design
patterns, where you use a servlet (plus business logic classes) for the controller, beans
for the model, and JSP pages for the view.

To deal with the relative links issue, I do one of two things:

* Keep every JSP page and corresponding servlet mapping in the "top level"
  directory of the web application.  The simplest way to do that for servlets is
  to map them to a one element URL pattern like "/saveCustomer", or to a
  filename extension (I like using "*.do" because "do" implies "do something".

* Render a "<base href="xxx">" element in the <head> section of the generated
  page -- this tells the browser what URL to resolve relative URLs against.

I don't know if browsers pay any attention to a "Content-Location" header or not, but that
would be an easy experiment to make.  Just include this header in your servlet or JSP page
response, and see what happens.

Craig


>
> "Craig R. McClanahan" schrieb:
>
> > Torsten Glunde wrote:
> >
> > > Hi Craig,
> > >
> > > thats true, but I wondered becaouse under the ApacheJserv the jsp:forward was
> > > interpreted differently, but I am not sure which implementation is correct
> > > according to the specs. Do you know more about that?
> > >
> >
> > I am not familiar with (I assume) GnuJsp or whatever you are using under Apache
> > JServ, but I would suspect that they are really doing a response.sendRedirect()
> > under the covers -- because Apache JServ was based on the 2.0 servlet api that did
> > not have request dispatchers in it, so this might have been their workaround.  Doing
> > this would have the visual appearance of changing the location bar.
> >
> > Technically, what the client shows you is not a "servlet spec" issue at all; the
> > servlet spec only covers what the server does.  But in this respect, Tomcat (and
any
> > other servlet container based on 2.1 or 2.2 that supports request dispatchers) will
> > behave the same way -- the client's location bar will not change because the client
> > has no way to know what is going on.
> >
> > Craig
> >
> > >
> > > Torsten Glunde
> > >
> > > "Craig R. McClanahan" schrieb:
> > >
> > > > Torsten Glunde wrote:
> > > >
> > > > > Hi ,
> > > > >
> > > > > we try to make a jsp:forward to a page a.jsp which locates on the
root
> > > > > directory of the server. if we make the forward from a site deeper
in
> > > > > the directory structure the browser requesting the page comes to
a.jsp,
> > > > > but the path doesn`t change. As a result relative links in a.jsp
are
> > > > > broken.
> > > > >
> > > > > Example:
> > > > >
> > > > > page from /www/dir/forward.jsp
> > > > >         <jsp:forward page="../../index.jsp"/>
> > > > >
> > > > > when we try to access forward.jsp we get the index.jsp but with the
url
> > > > > /www/dir/forward.jsp in the browser.
> > > > >
> > > > > Is this perhaps a bug, or does we misunderstand the specs?
> > > > >
> > > >
> > > > When you use <jsp:forward> (or RequestDispatcher.forward() in a
servlet), the
> > > > client browser has no clue what happened -- it continues to show the location
> > > > to which it *sent* the request.  That's the way it is supposed to work.
> > > >
> > > > If you really want the location bar to change, you need to do a sendRedirect()
> > > > instead -- but that takes a lot longer because of the extra round trip
to the
> > > > browser.
> > > >
> > > > >
> > > > > torsten Glunde
> > > >
> > > > Craig McClanahan
> > > >
> > > > --------------------------------------------------------------------------
> > > > To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> > > > For additional commmands, email: tomcat-user-help@jakarta.apache.org
> > >
> > > --------------------------------------------------------------------------
> > > To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> > > For additional commmands, email: tomcat-user-help@jakarta.apache.org
> >
> > --------------------------------------------------------------------------
> > To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commmands, email: tomcat-user-help@jakarta.apache.org
>
> --------------------------------------------------------------------------
> To unsubscribe, email: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commmands, email: tomcat-user-help@jakarta.apache.org


Mime
View raw message