【发布时间】:2015-06-25 04:42:37
【问题描述】:
我是 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>
这是一个项目结构:
【问题讨论】:
-
你能不能把
@RequestMapping(value = "/greeting")换成@RequestMapping(value = "/greeting.html")试试? -
你点击的完整网址是什么?
-
我的完整网址 - localhost:8080/EvenTracker/greeting.html 。我已替换为“/greeting.html”,但仍然出现 404 错误。
-
你能在这里添加你的jsp控制器调用吗
-
我已经更新了回购链接:github.com/terancet/EventTracker
标签: spring spring-mvc spring-webflow spring-mvc-test spring-web