當前位置:首頁 > IT技術 > 移動平臺 > 正文

No mapping found for HTTP request with URI [/zjic] in DispatcherServlet
2021-08-08 11:54:59

最近做項目 出現(xiàn)了前臺訪問出現(xiàn)404?

控制臺出現(xiàn) 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

但是發(fā)現(xiàn)無法訪問靜態(tài)資源 很郁悶

一月 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'
等等

No mapping found for HTTP request with URI [/zjic] in DispatcherServlet_java

參考?http://blog.163.com/zhangmihuo_2007/blog/static/27011075201453044959574?suggestedreading

解決了這個問題:

No mapping found for HTTP request with URI [/zjic] in DispatcherServlet_java_02

靜態(tài)資源都在lib下面

因此在spring配置文件中加入

?

	<!-- 靜態(tài)資源訪問 -->
<mvc:resources location="/lib/" mapping="/lib/**"/>

?

?

只需要映射webroot 下一層子目錄即可

如果有多個 可以寫多個mvc:resources

?

解決了這個問題
No mapping found for HTTP request with URI [/zjic] in DispatcherServlet_spring_03

此時.do 訪問可能出現(xiàn)404

?

?

本文摘自 :https://blog.51cto.com/u

開通會員,享受整站包年服務立即開通 >