2

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) ?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry for the late response, but this is exactly what I was looking for. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.