I could avoid the workaround if all the references to resources were relative and the transitions between JSP pages use the “jsp:forward” instead of “sendRedirect”, but this requires lot of changes, some of them non trivial.
The problem with references to resources is simple: the application generates HTML pages with absolute references like “/style/global.css”. These references can be changed to be relative like “style/global.css”, with no prefix.
The problems with the “sendRedirect” method is more complex. When you use this method the servlet container will send an HTTP response to the browser telling it to go to a new URL, for example, if you use code like this inside “page.jsp”:
The browser will send a request like this:
GET /page.jsp HTTP/1.1
And it will receive a response like this:
HTTP/1.1 302 Moved Temporarily
Then the browser will immediately fetch the new URL. This works fine when the host name and application path are the same from the point of view of the servlet container and from the point of view of the browser. This is not my case. This behavior can be avoided using “jsp:forward” instead of “sendRedirect”.