• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Changing scriplet to jstl url value tag changes path of a href target

 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the jsp code. The servlet compiles and runs without errors until I click on the first a href link. First link is using jstl, second is original and the way the first link looked before I changed it to a jstl tag.





Below is how the page is rendered in the browser. Why did the jstl tag pickup the extra directory "/ch11download"?

And how did the scriptlet climb up one directory and then go down a parallel directory to find the *.mp3 file?



This is the short picture of the directory structure

/netbeans
--> book_apps
----> musicStore
------>/sound/8601/no_difference.mp3
------>/sound/8601/star.mp3
-->ex_stats
----> ch11download
------> web
-------->8601_download.jsp, file containing the code shown above
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have disabled HTML this time. Thanks. TIA. Margaret.


Here is the JSP code:

<tr><td>You Are a Star</td>
<td>
<a href="<c:url value='/musicStore/sound/${product.code}/star.mp3' />">MP3</a>
</td>
</tr>
<tr><td>Don't Make No Difference</td>
<td><a href="/musicStore/sound/${product.code}/no_difference.mp3">MP3</a></td>
</tr>

Here is the rendered html:

<tr><td>You Are a Star</td>
<td>
<a href="/ch11download/musicStore/sound/8601/star.mp3">MP3</a>
</td>
</tr>
<tr><td>Don't Make No Difference</td>
<td><a href="/musicStore/sound/8601/no_difference.mp3">MP3</a></td>
</tr>

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
/chapter11download is the context path for the web app.
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So the JSTL tag will always add the context path? And the scriptlet will always ignore the path and search for a file match?

This is an exercise in a text book and it said to change all the scriptlets to JSTL. I haven't hit anything that did not work before in the text so this surprises me.

Is there some environmental variable that determines if the context is added, or could Netbeans (7) be adding it?

Thanks...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <c:url> adds the context path. It's supposed to, and it's not a problem.

The context path is needed on any URL that is generated from the browser: images, scripts, stylesheets, links, form actions, and so on.

When the app is deployed as the root web app, the context path is the empty string. But a web app should never hard-code the context path (be it the empty string or otherwise). The fact that <c:url> does it for us means we don't have to do it ourselves.

P.S. I have no idea what Netbeans does or doesn't do, but you can't rely on Netbeans doing anything when a web app is deployed into the real world.
 
margaret gillon
Ranch Hand
Posts: 335
6
Linux Tomcat Server Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Thank you for explaining how the tag works, it is very helpful.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic