springmvc jsp中的css,js路径正确,但浏览器无法找到
也是初级开发的错误:
在web.xml中设置了
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<!--
<url-pattern>*.do</url-pattern>
<url-pattern>*.screen</url-pattern>-->
<url-pattern>/</url-pattern>
</servlet-mapping>
改成了:<url-pattern>*.do</url-pattern>就好了
但不是根本的解决办法.....
在这个网页中找到了原因::::::http://love-love-l.blog.163.com/blog/static/21078304201111895950748/
应用springMVC时JS等文件找不到错误
应用springMVC时如果配置URL映射时如下配置
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
会导致页面引用的JSCSS发生找不到的错误
此时应在web.xml中添加
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>