最近做项目 出现了前台访问出现404
控制台出现 No mapping found for HTTP request with URI [/zjic] in DispatcherServlet
web.xml如下
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name>zjic</display-name> <servlet> <servlet-name>zjic</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>zjic</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/zjic-servlet.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- Session超时 --> <session-config> <session-timeout>-1</session-timeout> </session-config> </web-app>
最终找到原因 把
<servlet-mapping> <servlet-name>zjic</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
改为
<servlet-mapping> <servlet-name>zjic</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
即/* 去掉* 可以访问jsp
但是发现无法访问静态资源 很郁闷
一月 25, 2016 12:57:41 上午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping found for HTTP request with URI [/Extjs5SSM/lib/js/app/app.js] in DispatcherServlet with name 'extjs'
一月 25, 2016 12:57:41 上午 org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping found for HTTP request with URI [/Extjs5SSM/lib/js/ext-5.1.0/ext-all.js] in DispatcherServlet with name 'extjs'
等等
参考 http://blog.163.com/zhangmihuo_2007/blog/static/27011075201453044959574?suggestedreading
解决了这个问题:
静态资源都在lib下面
因此在spring配置文件中加入
<!-- 静态资源访问 --> <mvc:resources location="/lib/" mapping="/lib/**"/>
只需要映射webroot 下一层子目录即可
如果有多个 可以写多个mvc:resources
解决了这个问题
此时.do 访问可能出现404
本文摘自 :https://blog.51cto.com/u