I’m sorry if this question has been asked before, but I can’t seem to find an answer for it anywhere else.
I am running a local tomcat instance using eclipse and wtp. When the local server is running, I have to use the url http://localhost:8080/appName in order to access it.
I have been using relative URLs to use my javascript and css, but now I would like start using namespaced URLs, such as domain.com/admin/users. I can’t use relative css and javascript resources with these urls, since there is no javascript in the admin directory.
How can I use css and javascript resources from either my development or my production context? Is there a way to use my local tomcat instance from the ROOT context, as I can do in production? Do I have to use something to build the URLs for my resources (I would have to do this a lot, in both struts2 jsps, as well as sitemesh) ?
Don’t think it’s a good idea to hard code the domain urls. You can always work with the root context of your web application. You can use request.getContextPath() to know your context root. Your js/css should be under this. So you can access it like “<%=request.getContextPath()%>/js/some.js”. So even when the context root changes you do not have to do any code changes. I have used the scriplet here as an example.