Java Usin动态web项目Http 404资源不可用,但控制台中没有错误

Java Usin动态web项目Http 404资源不可用,但控制台中没有错误,java,spring,spring-mvc,Java,Spring,Spring Mvc,我正在构建一个Spring MVC应用程序;我正在使用Spring工具套件3.6.4和TomCat8。当我运行web应用程序时,当我访问/greeting时,我在控制台中得到“Http状态404请求的资源不可用”,我既没有错误,也没有使用System.out.println显示的消息 下面是我的代码。请帮忙 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2

我正在构建一个Spring MVC应用程序;我正在使用Spring工具套件3.6.4和TomCat8。当我运行web应用程序时,当我访问/greeting时,我在控制台中得到“Http状态404请求的资源不可用”,我既没有错误,也没有使用System.out.println显示的消息

下面是我的代码。请帮忙

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>fitTracker</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>fitness</display-name>
    <servlet-name>fitness</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>fitness</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</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>Insert title here</title>
</head>
<body>
  <h1>${greeting}</h1>
</body>
</html>

在此处插入标题
${问候语}
index.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>Insert title here</title>
</head>
<body>
  <h1>INDEX</h1>
</body>
</html>

在此处插入标题
指数
扫描包
com.thewizardofoz.controllers.controllers
,但您的控制器位于包
com.thewizardofoz.controllers

换成

<context:component-scan base-package="com.thewizardofoz.controllers"/>


而且它应该可以工作

请更改标签:

<context:component-scan base-package="com.thewizardofoz.controllers.controllers"/>



您也可以访问本教程:。

hello.jsp是否可在路径:
/WEB-INF/jsp/hello.jsp
?与您之前的问题相同:这与我第一次使用maven archetype webapp的原因略有不同。在这里,我创建了一个动态web项目,后来将其转换为Maven。真是个错误!谢谢你,亚历山大
<context:component-scan base-package="com.thewizardofoz.controllers"/>
<context:component-scan base-package="com.thewizardofoz.controllers.controllers"/>
<context:component-scan base-package="com.thewizardofoz.controllers"/>