1
votes

I'd like to have an "explicit" servlet for a particular URL and a default(sort of a catch-all) servlet to handle all other URLs. So I created the web.xml file like this :

  <servlet>
    <servlet-name>My myindex.html servlet</servlet-name>
    <servlet-class>in.shakir.web.MyIndexServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>My myindex.html servlet</servlet-name>
    <url-pattern>/myindex.html</url-pattern>
  </servlet-mapping>

  <servlet>
     <servlet-name>My all others servlet</servlet-name>
     <servlet-class>in.shakir.web.MyHandlerServlet</servlet-class>
  </servlet>
  <servlet-mapping>
     <servlet-name>My all others servlet</servlet-name>
     <url-pattern>*</url-pattern>
  </servlet-mapping>

However it is not working(I get 404 error even for /myindex.html) I am using Tomcat 7.

But if I remove second (default or catch-all) part from my web.xml, then myindex.html works fine. So whats wrong with my url-pattern ? Please advise.

1

1 Answers

3
votes

change

<url-pattern>*</url-pattern>

to

<url-pattern>/*</url-pattern>

see this for more information.