File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes [solved] problem writing href Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "[solved] problem writing href" Watch "[solved] problem writing href" New topic

[solved] problem writing href

Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Got a weird problem: i use <a href="jsp/main.jsp"> from jsp\main.jsp which goes http://localhost:8080/appname/jsp/main.jsp (which is right), but then i lose sight of css files (which are in \css), and if i push the link again it goes http://localhost:8080/appname/jsp/jsp/main.jsp , how do i write the href properly?

P.S. this is part of a struts 2 app with this mapping:

EDIT1: seems that one solution was: <a href="mainAction.action">
Are there any other solutions?
Ankit Garg

Joined: Aug 03, 2008
Posts: 9462

Don't use relative URLs in your tags. use absolute URLs i.e. starting from /contextPath. You can add the context path to your URLs using either c:url JSTL tag or using ${pageContext.request.contextPath} EL before the actual URL...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Tudor Raneti
Ranch Hand

Joined: Nov 29, 2009
Posts: 145
Thanks. There is a second problem with relative paths, that if i prepend with / or ../ the appName gets cut from the URL. But i learnt my lesson, i will use struts 2s tags for it, especially since it seems to do some url rewriting as well.
I agree. Here's the link:
subject: [solved] problem writing href
It's not a secret anymore!