Note that there are some explanatory texts on larger screens.

plurals
  1. POwhy tomcat7.0.47 can not access static resources(js, css) while mapping a front controller servlet on an URL pattern of *.do or / or /*
    primarykey
    data
    text
    <p>In fact, I am writing <strong>a maven project with spring</strong>.Everything is ok until I want to <strong>import my css file</strong>.Here is my web.xml(<strong>only the servlet part</strong>):</p> <pre><code>&lt;servlet&gt; &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;/WEB-INF/mvc-dispatcher-servlet.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>Then I visit my page on this url:</p> <pre><code>http://localhost:8080/hello.do?method=reg </code></pre> <p>However, I have got a problem:<strong>style.css is 404 Not Found</strong></p> <p>so, I have searched some file and then I got a method:add some configuration in my servlet.xml(my servlet is <strong>mvc-dispatcher-servlet.xml</strong>):</p> <pre><code>&lt;mvc:resources mapping="resources/**" location="/WEB-INF/resources/" /&gt; &lt;mvc:default-servlet-handler /&gt; </code></pre> <p>As you see my css file is under "/WEB-INF/resources/".But,the problem still exists.At last, I know one thing:</p> <blockquote> <p>static resources cannot be accessed while servlet is mapped on an URL pattern of / or /*</p> </blockquote> <p>So I change my <strong>web.xml</strong> to this:</p> <pre><code>&lt;servlet-mapping&gt; &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt; &lt;url-pattern&gt;/user/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>Finally, the problem is totally solved,but this makes me more puzzled,<strong>why tomcat can not access static resources(js, css) while mapping a front controller servlet on an URL pattern of **.do or / or /*</strong></p> <p><strong>update(Dec 30 '13):</strong></p> <p>My application is this:</p> <pre><code>MyApplication pom.xml src test main java com.roger.spring controller UserController.java dao impl UserDaoImpl.java UserDao.java domain User.java service impl UserService.java UserService.java webapp WEB-INF applicationContext.xml dao.xml db.properties mvc-dispatcher-servlet.xml service.xml web.xml pages index.jsp taglib.jsp user login.jsp reg.jsp profile.jsp resources css style.css js calendar.js </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload