Reputation: 28598
I need to write a webapp, using Jetty. My context path is decided externally and will vary from one customer to the next.
Is this a normal requirment?
Assuming I have links to other pages, AJAX calls from static JavaScript files and image references from static CSS files, how can this be achieved? What is the recommended project structure?
Can I accomplish this without templates? (JSP).
Upvotes: 0
Views: 459
Reputation: 691635
Is this a normal requirment?
Yes. Nothing in your webapp should depend on the value of the context path.
It's actually quite simple to support any context path: systematically prepend the context path to every URL your app produces.
In JSP files, use the <c:url>
tag (or similar) to generate URLs.
In JS files, use URLs passed from the JSP pages, or use a global variable set in theJSP file and containing the context path to generate the URLs.
In Java files, use request.getContextPath()
to get the context path and prepend it to URLs.
In CSS files, use relative paths.
Upvotes: 1