Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tagib url tag

 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The / before ${pageContext... is the error. Leave it out.
 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked (as you knew it would) thanks for the tip!

Mike
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic