我試圖在谷歌應用引擎上構建一個spring mvc網頁。但我無法進行路由/映射工作。谷歌應用引擎中的Spring MVC路由
我有我的HelloController
,這表明我希望映射到/hello
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/hello")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String Index() {
return "hello";
}
}
和一個非常簡單的hello.jsp
文件
<html>
<head><title>Hello :: Spring Application</title></head>
<body>
<h1>Hello - Spring Application</h1>
<p>Greetings.</p>
</body>
</html>
然而,當我嘗試訪問/hello
,我會得到404找不到。
這裏是我的XML映射文件mvc-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.example.web" />
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
我缺少什麼?如何解決它?
你在web.xml中映射的servlet春天? – 2015-03-03 07:43:10
你把hello.jsp放在哪裏?我想你應該把它放在'InternalResourceViewResolver'配置中'prefix'指定的目錄中 – hsluo 2015-03-03 09:41:06