我是Spring框架的新手。我会开发一个简单的网络应用程序,显示基于URL“/greeting.html”的hello.jsp内容。但现在,它给了我404错误。我究竟做错了什么?Spring MVC 4的无效控制器配置
这里是我的项目的GitHub库(该项目下的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(值= “/问候语”)'和'@RequestMapping(值=“/greeting.html “)'并尝试? – barunsthakur
什么是你打的完整网址? –
我的完整网址 - http:// localhost:8080/EvenTracker/greeting.html。我用“/greeting.html”代替,仍然有404错误。 –