I'm trying to add URL routing to a web application running in Tomcat 5.5.
I want to make the dynamic page URLs more friendly, changing main.jsp?type=test&group=info
to main/test/info
as is all the rage.
I have set up the following in the web.xml
<servlet>
<servlet-name>main</servlet-name>
<jsp-file>/main.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>main</servlet-name>
<url-pattern>/main/*</url-pattern>
</servlet-mapping>
and in main.jsp I use request.getPathInfo()
to get the data that I need to do the routing. All this seems to work fine, and when I browse to http://mytestserver/example/main/test/info
I get the html that I expect.
The problem is that any relative links on that page, images, style-sheets, javascript, etc., are now all broken, as they are being interpreted as relative to the full URL.
I can't think of an easy way to use static links because the URLs on the test server and production server are at different levels: http://mytestserver/example/
maps to http://example.com/
in production, and I really do not want to have to write code to wrap every internal link on the site or set up a virtual server for each site on the test server.
Is there anything else I can do?