Java SpringMVC。HTTP状态404
我从本课程开始学习“Spring MVC”: 在步骤“构建->运行应用程序”中,我被卡住了 当我尝试转到链接Java SpringMVC。HTTP状态404,java,spring,jsp,spring-mvc,model-view-controller,Java,Spring,Jsp,Spring Mvc,Model View Controller,我从本课程开始学习“Spring MVC”: 在步骤“构建->运行应用程序”中,我被卡住了 当我尝试转到链接http://localhost:8080/FitnessTracker/greeting.html 我得到“HTTP状态404” web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://w
http://localhost:8080/FitnessTracker/greeting.html
我得到“HTTP状态404”
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>fitTrackerServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/config/servlet-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<display-name>Archetype Created Web Application</display-name>
</web-app>
hello.jsp
<%@ page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%>
<!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=US-ASCII">
<title>Insert title here</title>
</head>
<body>
<h1>${greeting}</h1>
</body>
</html>
在此处插入标题
${问候语}
http://localhost:8080/FitnessTracker/
-它的工作(文件:webapp/index.jsp)尝试从控制器返回与jsphello.jsp
匹配的正确大小写视图名称。当前,控制器返回Hello
,而JSP名为Hello.JSP
,导致404
@Controller
public class HelloController {
@RequestMapping(value = "/greeting")
public String sayHello (Model model) {
model.addAttribute("greeting", "Hello WorldX");
//return "Hello";
return "hello";
}
}
错误消息说它正在查找
Hello.jsp
。实际上,您的控制器返回以下视图名称:“Hello”
。但是您的屏幕截图显示您的文件已分析hello.jsp
。案例很重要。更改web.xml
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
fitTrackerServlet
/
您是否尝试过注释版本的InternalResourceViewResolver
?
<%@ page language="java" contentType="text/html; charset=US-ASCII"
pageEncoding="US-ASCII"%>
<!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=US-ASCII">
<title>Insert title here</title>
</head>
<body>
<h1>${greeting}</h1>
</body>
</html>
@Controller
public class HelloController {
@RequestMapping(value = "/greeting")
public String sayHello (Model model) {
model.addAttribute("greeting", "Hello WorldX");
//return "Hello";
return "hello";
}
}
<servlet-mapping>
<servlet-name>fitTrackerServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>