简体   繁体   中英

Asterisk(wild card match) and url-pattern

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.

change

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

to

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

see this for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM