0

I'm setting up a simple servlet to act as a forwarder. Basically so that you can hit the page with this http://localhost:8080/WebProjectName/ServletName/foo/bar instead of like this http://localhost:8080/WebProjectName/Main.jsp?par1=foo&par2=bar

However, it seems to break in a way that I don't even know where to begin looking. It forwards to the page fine when I go to this http://localhost:8080/WebProjectName/ServletName, but when I add anything on the end, it doesn't load any styling or images. Just the text content of the pages.

Anyways, here's my simple servlet

protected void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
    request.getRequestDispatcher( "/main.jsp" ).include( request, response ) ;
}

And here is the web xml chunk

<servlet>
  <description></description>
  <display-name>Main</display-name>
  <servlet-name>Main</servlet-name>
  <servlet-class>package.thing.Main</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>Main</servlet-name>
  <url-pattern>/ServletName/*</url-pattern>
</servlet-mapping>

What's happening when I even just add a slash, that would cause it to only load the text of main.jsp, and not the styling or any images?

This works: http://localhost:8080/WebProjectName/ServletName

This breaks: http://localhost:8080/WebProjectName/ServletName/

This also breaks: http://localhost:8080/WebProjectName/ServletName/why

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
CrazyPenguin
  • 619
  • 2
  • 10
  • 29
  • possible duplicate of [Servlets - Browser can't access css, images when doing a forward to a JSP?](http://stackoverflow.com/questions/3655316/servlets-browser-cant-access-css-images-when-doing-a-forward-to-a-jsp) – BalusC Nov 10 '11 at 15:18
  • Do you mean to invoke `include` rather than `forward`? – shelley Nov 29 '11 at 22:24

1 Answers1

0

well you need put ../css, if because you use /your_uri/ this means if you have WebContent/css/file.css

to : /your_uri/ css = href="../css/file.css"

to : /your_uri/?par=my_thing css = href="../css/file.css

to : /your_uri css = href="css/file.css"

harvpan
  • 8,571
  • 2
  • 18
  • 36
demopix
  • 159
  • 6