my dog learned polymorphism*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 91
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: 60810
    
  65

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: 91
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: 1016
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: 60810
    
  65

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
 
Similar Threads
dojo 1.1.2 fails in firefox 3.0.5
DOJO1.2.3/ IE7 /addOnLoad()
Struts 2 and Dojo (dojo undefined error)
Finding out the version of Dojo
Problem regarding Struts and Dojo integration