2022 年 6 月 26 日下午 5:27:51 org.springframework.web.servlet.PageNotFound noHandlerFound 警告:在 DispatcherServlet 中找不到具有 URI [/hello/] 的 HTTP 請求的映射,名稱為“spring”在控制臺中獲取此資訊,服務器正在獲取啟動成功,但 http://localhost:8080/hello/ http://localhost:8080/greeting/ 沒有加載,請您幫忙..
Controller class
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class SimpleController {
@RequestMapping("/hello")
public String hello() {
return "index";
}
@RequestMapping("/greeting")
public ModelAndView greet() {
ModelAndView mav = new ModelAndView("greet");
mav.addObject("greeting", "Hi this me");
return mav;
}
}
<?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" id="WebApp_ID" version="3.0">
web.xml-> SpringMVC
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!-- Provide support for component scanning -->
<context:component-scan base-package="com.springmvc" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
<!--Provide support for conversion, formatting and validation -->
<context:annotation-config/>
<mvc:annotation-driven/>
</beans>
greet.jsp-->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<p>Hi</p>
${greeting}
</body>
</html>
-->index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<body>
<p>Hi</p>
</body>
</html>
uj5u.com熱心網友回復:
你應該試試 http://localhost:8080/hello ,沒有最后一個反斜杠
uj5u.com熱心網友回復:
確保專案中的maven依賴右鍵單擊你的專案>屬性>選擇依賴組件選項卡選擇添加->添加Maven依賴
uj5u.com熱心網友回復:
通過在 lib 路徑中添加 jstl jar 解決了這個問題。感謝您的回答和支持。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/498484.html
上一篇:@Value不注入任何值
下一篇:org.springframework.dao.IncorrectResultSizeDataAccessExceptionMongoLimit不起作用?
