日期:2014-05-17  浏览次数:20717 次

第一次使用Spring MVC,找不到resolve的页面?
本帖最后由 class281 于 2013-11-21 16:06:00 编辑
工程名叫SpringTest,用到spring框架和spring mvc,配置文件如下:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
  <display-name>SpringTest</display-name>
  
  <servlet>
   <servlet-name>springtest</servlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
   <load-on-startup>1</load-on-startup>
  </servlet>
  
  <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>
   classpath:springContext.xml
   </param-value>
  </context-param>
  <listener>
   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

</web-app>



springtest-servlet.xml
PS:这个文件还一直会提示

springtest-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<mvc:annotation-driven/>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> -->
<property name="prefix" value="/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>


然后我建了个简单的测试页面和方法
页面:home.jsp,直接放在WebContent目录下
控制类:

public class WebController{
// @RequestMapping({"/", "/home"})
// @RequestMapping(value="/", method=RequestMethod.GET)
@RequestMapping(value="/")
public String showHomePage(Model model){
return "home";
}
}

预想的结果是访问工程的默认路径,http://localhost:8080/SpringTest/,就应该可以跳转到home.jsp页面
但是结果是一直找不到页面。。。
新手诚心求解!
Spring SpringMVC