1

With the following configuration:

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

then both Tomcat7 and Tomcat6 serves the following URL just fine: http://127.0.0.1:8087/mynet/index.html

However, if I reduce the configuration to just mention the CSS pattern:

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.css</url-pattern>
</servlet-mapping>

Then Tomcat6 works, but Tomcat7 fails with: The requested resource () is not available.

Why is there a difference here?

2
  • Because they decided to change it? – Brian Roach May 9 '12 at 1:32
  • If I do not add any “default” 。Access 127.0.0.1:8087/mynet/index.html Success。 tomcat7 ,tomcat6 – weisd May 9 '12 at 2:04
2

You should not map container's default servlet in your webapp's web.xml. Whatever functional requirement for which you thought that this is the solution, it has definitely to be solved differently.

If you have for example overridden it with a custom front controller servlet on an URL pattern of /, then you should fix that servlet to listen on a more specific URL pattern instead. Use if necessary a filter to "hide" the servlet's specific URL pattern by collecting all static resources in a single folder such as /static or /resources and letting the filter check on that.

See also:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.