我正在創建一個基本的hello world Spring MVC應用程序。但它無法找到URL映射。我搜索了很多,但沒有找到任何令人滿意的解決方案。我在控制檯上得到以下錯誤。Spring MVC在DispatcherServlet中使用URI [/HelloWeb/WEB-INF/jsp/hello.jsp]找到名爲'servletname'的HTTP請求沒有找到映射
org.springframework.web.servlet.PageNotFound noHandlerFound警告: 否[/HelloWeb/WEB-INF/jsp/hello.jsp]在DispatcherServlet的發現HTTP請求與URI 與名稱映射 'HelloController中'
任何人都可以幫我解決這個問題。以下是我的代碼
HelloController.java package com.tutorialspoint;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.ModelMap;
@Controller
public class HelloController{
@RequestMapping(value="/" , method = RequestMethod.GET)
public String printHello(ModelMap model) {
model.addAttribute("message", "Hello Spring MVC Framework!");
return "hello";
}
}
的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>HelloWeb</display-name>
<servlet>
<servlet-name>HelloController</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HelloController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
HelloController中-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"
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">
<context:component-scan base-package="com.tutorialspoint" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
</web-app>
的hello.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>See this first MVC page here</title>
</head>
<body>
<h2>${message}</h2>
<h6>Check if above sentence is visible</h6>
</body>
</html>
發佈應用程序目錄結構 –
請看看這個答案http://stackoverflow.com/a/32931296/584420 –
包(com.tutorialspoint )> HelloController.java和webcontent結構是WEB-INF> jsp> hello.jsp也是WEB-INF> HelloDispatcher-servlet.xml,web.xml –