我是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錯誤。 –