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 Quail <St...@walkers.co.uk> on 2000/12/12 10:01:05 UTC
Follow-up: Forward problems servlet to JSP in 3.2
Thanks for this, I now have the application working OK via a servlet
mapping in the applications web.xml file. For the benefit of those who
find themselves in the same situatuion and this is what I used :
<servlet-mapping>
<servlet-name>
MyServlet
</servlet-name>
<url-pattern>
MyServlet.svlt
</url-pattern>
</servlet-mapping>
Tried adding the following generic *.svlt mapping to the Tomcat base
web.xml (even tried changing my servlet name to MyServlet.svlt too) but
couldn't get it this work, if anyone knows why please email me - it seems
neater to have a generic mapping.
<servlet-mapping>
<servlet-name>
invoker
</servlet-name>
<url-pattern>
*.svlt
</url-pattern>
</servlet-mapping>
Thanks,
Steve Quail.
______________________________ Reply Separator
_________________________________
Subject: RE: Forward problems servlet to JSP in 3.2
Author: Kitching Simon <Si...@orange.ch> at internet-po
Date: 11/12/00 15:30
Hi,
I just have a little bit extra to add to Andrea's email:
The problem is that when a browser has loaded a page containing
relative urls to other files, the *browser* resolves these into absolute
references by merging them with the URL that it *thinks* the
parent page was loaded from.
Because a "forward" operation within the tomcat webserver (or
any other webserver for that matter) is totally invisible to the
browser, it thinks that the parent page came from
/contextname/servlet/something, and therefore uses that
url to figure out what absolute page "images/mygif.gif"
should be loaded from.
The solutions (as far as I know) are
(a)
andrea's solution of mapping the servlet url, so that
the servlet doing the forwarding appears to be in the
same directory as the file it eventually forwards to.
(but this won't work if you might be forwarding to
files in different directories)
(b)
to use absolute paths for all links
Neither of these solutions really appeals to me.
Anyone else out there (Craig??) got a better solution?
PS: I expect that this is a really common problem
for Struts users, because forwarding is very common.
Any comments, Struts users??
> -----Original Message-----
> From: AC [SMTP:smda@lisea.com]
> Sent: Monday, December 11, 2000 3:10 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Re: Forward problems servlet to JSP in 3.2
>
> You should use servlet mapping. If you have http://myhost/myjsp.jsp the
> servlet that call your jsp should be mapped as http://myhost/myservlet .
> In
> this way all the relative links are still good.
> An additional hint...... if you map your servlet with an extension, for
> instance myservlet.Svlt and use a configuration such as
> JkMount /tf/*.jsp ajp13
> JkMount /tf/*.Svlt ajp13
>
> all the request not related to tomcat are served by Apache!!!!
>
> andrea
>
>
> At 13.48 11/12/2000 +0000, you wrote:
> > I'm using using forward to pass a request from my servlet to a JSP
> > page i.e.ServletContext.getRequestDispatcher
> ("my.jsp").forward(req,
> > res).
> >
> > This is fine (the JSP gets displayed no problem) but any relative
> > links in the JSP get messed up with a "/servlet" in the middle -
> e.g.
> > a graphic referenced as "images/mygif.gif" becomes a link to
> > "contextname/servlet/images/mygif.gif" rather than
> > "contextname/images.mygif.gif", links to HTML files similarly get
> > "/servlet" inserted.
> >
> > Help ! There must be a simple solution I'm missing here.
> >
> > Steve Quail.