0

I'm learning and making a website with a tomcat server with servlet/JSP.

I can reach my home page with this URL : ip:8080/myapp/Home

it's actually a servlet which take the request and respond with a JSP.
So until here no problem.
But i wanted reach the home page with this URL (shorter) : ip:8080/myapp/
So after editing the web.xml adding a new mapping section like that :

  <servlet-mapping>
    <servlet-name>Home</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

It was working but i had a strange bug : impossible to get my image, .css, .js file... Actually when i checked the file (css/img...), for example logo.png the server sent me the Home Page (JSP) in respond. I don't understand why.

So, anyone have an idea how to fix this ? BTW, when i delete the servlet-mapping it's working so, it i'm sure it come from this part ~

Is it not possible to add two servlet-mapping on the same servlets or something like that ? I need to...
the web.xml :

  <servlet>
    <servlet-name>Home</servlet-name>
    <servlet-class>pages.Home</servlet-class>
  </servlet>


  <servlet-mapping>
    <servlet-name>Home</servlet-name>
    <url-pattern>/Home</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>Home</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
Ewen
  • 21
  • 1
  • About mapping to slash read this: https://stackoverflow.com/questions/28315618/why-should-url-pattern-in-servlet-mapping-start-with-forward-slash/28315917 especially part of the answer with "A string containing only the ’/’ character ..." and about mapping two urls this: https://stackoverflow.com/questions/8995353/many-url-pattern-for-the-same-servlet – Krystian G Aug 09 '19 at 21:44
  • I red that, but i need my Home servlet to be the default servlet of my webapp, so it's should be the good syntax no ? (like written in my code) because, when i enter no URL like ip:8080/webapp, i get redirect to my Home page which is nice, but with the bug of no getting media,css... :/ – Ewen Aug 10 '19 at 01:24
  • Ok i tried with the "" string, and it's working apparently – Ewen Aug 10 '19 at 01:26

0 Answers0