I'm working on a GAE/J app and I have the following structure:
- war
|
- mobile
| |
| - assets
| | |
| | + a.jpg
| | + b.gif
| | + c.js
| + a.jsp
| + b.jsp
| + index.jsp
| + d.css
| + e.css
|
+ landing.jsp
Now in web.xml, I have a URL mapping of /mobile
pointing to <jsp-file>/mobile/index.jsp<jsp-file>
. In my index.jsp
, I used relative addressing to reference all the required resources like JS files, CSS files and images; and this works well if I type our_domain/mobile/index.jsp
in the browser. But when I type our_domain/mobile
, it serves the correct file (index.jsp) but every relative address breaks which means no CSS, no JS, no image.
From my investigation, it seems that web.xml
doesn't actually redirect but rather calls a specified JSP/Servlet to answer to a specific URL pattern. This does not work well with relative addressing as path information that would be correct with a real redirect is left at the root. How do I ensure that relative addresses work as expected in this kind of scenario?
[edit]
I've tried sevral configurations. Now /mobile
URL works properly and all my CSS gets loaded but /mobile/
doesn't load my CSS. Here's my mapping:
<servlet> <description>Landing page on mobile site</description>
<display-name>MobileIndex</display-name>
<servlet-name>MobileIndex</servlet-name>
<jsp-file>/mobile/index.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>MobileIndex</servlet-name>
<url-pattern>/mobile/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>MobileIndex</servlet-name>
<url-pattern>/mobile</url-pattern>
</servlet-mapping>