Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com May 10 '12 at 9:53

This question came from our site for professional and enthusiast programmers.

    
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
add comment

1 Answer 1

up vote 2 down vote accepted

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:

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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