所以我正在制作一个简单的项目来通过这个 tutorial 测试 Spring Framework , 遇到了想不通的问题。
我的项目结构:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>*.htm</url-pattern>
<url-pattern>*.json</url-pattern>
</servlet-mapping>
</web-app>
调度程序-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"
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">
<context:component-scan base-package="com.itaSS.controller" />
</beans>
家庭 Controller .java:
package com.itaSS.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping("/home")
public String home() {
return "/WEB-INF/jsp/home.jsp";
}
}
所以当在 tomcat 上部署 war 并尝试访问 localhost:8080/home.html 时 我明白了:
我确定 web.xml 中有错误或者我遗漏了什么。 如果有人能帮助我,我将不胜感激!
最佳答案
我认为您的 dispatcher-servlet.xml 文件中缺少以下行。
<mvc:annotation-driven/>
关于java - web.xml 无法正确标记 spring ServletDispatcher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27678927/