我是 Spring 框架的新手。我想开发一个简单的 web 应用程序,它显示基于 url“/greeting.html”的 hello.jsp 内容。但现在,它给了我 404 错误。我究竟做错了什么?
这是我的项目的 github repo(这个项目是在 Eclipse STS 下创建的):https ://github.com/terancet/EventTracker
这是我的 HelloController 类
@Controller
public class HelloController {
@RequestMapping(value = "/greeting")
public String sayHello(Model model) {
model.addAttribute("greeting", "Hello World");
return "hello.jsp";
}
}
这是 web.xml
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.pluralsight.WebConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
这是一个项目结构: