aspose file tools*
The moose likes JSP and the fly likes tagib url tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "tagib url tag" Watch "tagib url tag" New topic
Author

tagib url tag

Mike Tabak
Ranch Hand

Joined: Mar 31, 2012
Posts: 43
I am just learning about the core taglib. I was doing an exercise where I was replacing a jsp url tag with a taglib url tag. The link is to download a file. The original tag was:

<a href="/ch11download/sound/${product.code}/filter.mp3">MP3</a>

which downloads a file in the web/sound/...... directory and ch11download is the name of the application. When I replaced it with the tablib url tag, I had to modify it as follows to work:

<a href="<c:url value='/sound/${product.code}'/>/filter.mp3">MP3</a>

The mystery to me being I had to leave out "/ch11download". Can someone tell me why? Does the taglib tag assume the root of your app?

Thank you
Mike
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

The c:url tag does that, yes.

Which is quite a convenient feature, because it reduces the number of times that you hard-code your context path into your JSPs. (Hint: you really shouldn't be doing that. You should be using ${pageContext.request.contextPath} instead.)
Mike Tabak
Ranch Hand

Joined: Mar 31, 2012
Posts: 43
Thanks for the answer, my book did not point that out. By the way, I tried inserting ${pageContext.request.contextPath} as you suggested in the old tag and instead of seeing

localhost:8080/ch11download/sound/product=8601 in the URL box I saw

ch11download/sound/product=8601, in other words it was looking for a server named ch11download. I used:

<a href="/${pageContext.request.contextPath}/sound/${sessionScope.product.code}/star.mp3">MP3</a>

What's the error?

Thank you
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

The / before ${pageContext... is the error. Leave it out.
Mike Tabak
Ranch Hand

Joined: Mar 31, 2012
Posts: 43
That worked (as you knew it would) thanks for the tip!

Mike
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: tagib url tag