1

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>
informatik01
  • 16,038
  • 10
  • 74
  • 104
Sayo Oladeji
  • 741
  • 4
  • 15
  • 28
  • What is your mapping look like? – András Tóth Apr 16 '13 at 21:25
  • ` MobileIndex /mobile ` Where `MobileIndex` is also declared in `web.xml` as the servlet name pointed at the `/mobile/index.jsp` file. When dis didnt work, I even pointed `MobileIndex` at another JSP whose only purpose was to do a `response.sendRedirect("/mobile/index.jsp");` but dat didnt work either. I then changed d redirecting JSP 2 a standard servlet s accomplish d same purpose but it also didnt work as expected. They all redirected but my CSS & JS files stil couldnt b located. – Sayo Oladeji Apr 17 '13 at 01:40
  • Why do you use the web.xml to map a jsp to a path where it is? Do you really need a servlet? Any way this is just a misconception not your problem. How do you reference your resource files (eg. CSS/JS/IMGs)? – András Tóth Apr 17 '13 at 09:19
  • relative addressing, e.g `` The reason why I mapped it that way is that I want my users to be able to just type `my_domain/mobile` in their browser instead of `my_domain/mobile/index.jsp` – Sayo Oladeji Apr 17 '13 at 09:44
  • What if you use this href="./d.css"? – András Tóth Apr 17 '13 at 09:49
  • Same result. Question updated. – Sayo Oladeji Apr 17 '13 at 11:27
  • @SayoOladeji Check out my answer that shows how to solve the problem of referencing CSS/JavaScripts etc in JSP files: http://stackoverflow.com/a/14063039/814702 – informatik01 Apr 17 '13 at 13:42
  • 1
    @SayoOladeji, was the solution proposed by effective for you. If so, what specific changes had you made to your mappings shown above? – Nicholas Mar 08 '16 at 18:24
  • Is this issue still occurring? – Nick Aug 22 '16 at 15:37
  • @Nick I just checked and the issue is no longer present. I can't remember what I did to get it to work as I've not been maintaining the project for a long time. If this is an issue that you are experiencing I can investigate. – Sayo Oladeji Aug 22 '16 at 22:57
  • No worries, I was just wondering if you still needed assistance! Glad to hear. I guess this question will go without an answer. I'm not really sure what the Stack Overflow guidelines are for a situation like this... – Nick Aug 23 '16 at 14:15
  • @Nick thanks a lot. I did see anything interesting in the repo. I noticed I later took down `/mobile` entirely. I'm incredibly grateful for all the assistance I received on this thread. Kindly pardon me, it's been over 3 years. I was juggling balls in that period and so wasn't very organized; then we discontinued the project. – Sayo Oladeji Aug 24 '16 at 23:43

1 Answers1

1

I'm not sure redirect is what you actually want. A good organization for your app is:

myapp/ pom.xml src/ main/ java/ ... Your Source Code ... webapp landing.jsp assets/ a.jpg b.gif c.js mobile/ index.jsp a.jsp b.jsp You can, of course, change the location of your assets using the <public-root> and <static-files> elements of appengine-web.xml.