• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Correct specification of javascript library location

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gentlemen,
here is a line from some jsp page I got:

As far as I understand this line means, that a corresponding web-path to the resource should be server_url/html/js/dojo/release/dojo/dojo/dojo.js because of that first "/" sign.
Am I right?

A problem is that my application is deployed in server_url/myAppName/, and thus my dojo.js can be found via path server_url/myAppName/html/js/dojo/release/dojo/dojo/dojo.js

Am I right in my presuppositions?
Can I fix it somehow without correcting the legacy jsp page?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The context path to the application must be included. The only way to fix it, without really fixing it, is to deploy the app as the ROOT application, in which case the context path becomes /.

The real fix is to use the EL to fetch the context path and include it in the URL with ${pageContext.request.contextPath}.
 
Dmitry Zhuravlev
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:The context path to the application must be included. The only way to fix it, without really fixing it, is to deploy the app as the ROOT application, in which case the context path becomes /.

The real fix is to use the EL to fetch the context path and include it in the URL with ${pageContext.request.contextPath}.



Thanks, Bear, but the best option is to remove the leading "/" sign from the path to library, am I right? This will work with any context path.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That would work with any context path, as long as the relative reference was correct.

Note that the reference is relative to the requested url, which may or may not be the actual JSP.
If you put a servlet in front of things and then forward to this JSP, then the file may not be found, as the relative link is incorrect.

Bear's suggestion including the context path in the url, is guaranteed to work in any circumstance.
Wrapping it in a custom tag would be fairly straightforward.

cheers,
evnafets

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dmitry Zhuravlev wrote:

Bear Bibeault wrote:The context path to the application must be included. The only way to fix it, without really fixing it, is to deploy the app as the ROOT application, in which case the context path becomes /.

The real fix is to use the EL to fetch the context path and include it in the URL with ${pageContext.request.contextPath}.



Thanks, Bear, but the best option is to remove the leading "/" sign from the path to library, am I right? This will work with any context path.


No, that is far from the best option. The fix I outlined works with any context path (as it is determined dynamically) and is not prone to fragility and breakage when app structure is changed.
 
What's a year in metric? Do you know this metric stuff tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic