當(dāng)我訪問 First_Spring_MVC/welcome 時(shí),出現(xiàn)以下錯(cuò)誤:org.springframework.web.servlet.PageNotFound noHandlerFound警告:在名稱為“spring-dispatcher”的 DispatcherServlet 中找不到具有 URI [/First_Spring_MVC/welcome] 的 HTTP 請求的映射這是我的 web.xml 文件:<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>First_Spring_MVC</display-name> <servlet> <servlet-name>spring-dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>spring-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>這是 spring-dispatcher-servlet.xml:<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"><context:component-scan base-package="com.webapp.helloController" /> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name="prefix"> <value>/WEB-INF/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> </beans>
1 回答

縹緲止盈
TA貢獻(xiàn)2041條經(jīng)驗(yàn) 獲得超4個(gè)贊
您正在掃描錯(cuò)誤的包裹。改變 :
<context:component-scan base-package="com.webapp.helloController" />
至
<context:component-scan base-package="com.app.helloController" />
在您的情況下,還要確保您點(diǎn)擊了正確的網(wǎng)址:
http://localhost:{your_port_num}/First_Spring_MVC/welcome
添加回答
舉報(bào)
0/150
提交
取消