*
The moose likes JSP and the fly likes Context Root of WebApplication in javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Context Root of WebApplication in javascript" Watch "Context Root of WebApplication in javascript" New topic
Author

Context Root of WebApplication in javascript

sandeeprajsingh tandon
Ranch Hand

Joined: Mar 06, 2009
Posts: 70
Hi,
I am in the process of changing all the paths in js files to prepend the context root to the paths.
I can get context path in the js by way of reading application.xml but that puts a restriction of not being able to read the application.xml from a relative path. Because application.xml is placed in META-INF which is not accessible to the outside world.

2nd way is i can include a header jsp in all the jsps and then have a common code like
<script type="text/javascript">
var CONTEXT_ROOT = '<%= request.getContextPath() %>';
</script>

now we could refer to context_root in all the js files.

is there any other alternative too?


thanks
sandeepraj
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60776
    
  65

Except for the fact that you are using scriptlets (in 2012? Scriptlets?) that's pretty much what I do.

To get the context path with the EL: ${pageContext.request.contextPath}


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sandeeprajsingh tandon
Ranch Hand

Joined: Mar 06, 2009
Posts: 70
thanks..
yes its a 2001 code still not upgraded so yes..in 2012 i am using scrip lets.

thanks for your reply

thanks
sandeepraj
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Context Root of WebApplication in javascript
 
Similar Threads
Javascript and the DispatcherServlet
calling js file from jsp.
calling js file..
Migration from websphere 3.5 to 4.0.1
Relative file paths in JSP