aspose file tools*
The moose likes JSP and the fly likes Correct specification of javascript library location Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Correct specification of javascript library location" Watch "Correct specification of javascript library location" New topic
Author

Correct specification of javascript library location

Dmitry Zhuravlev
Ranch Hand

Joined: Apr 14, 2010
Posts: 92
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?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

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}.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dmitry Zhuravlev
Ranch Hand

Joined: Apr 14, 2010
Posts: 92
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.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Correct specification of javascript library location