工程名叫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
------解决方案--------------------

第一点:应该是先有监听器,再写DispatcherServlet的
第二点:注意你的mvc配置文件名称是否和web.xml中写的一样,还有路径是否是在classpath下?
------解决方案--------------------
<!-- 自动扫描的包名 -->
<context:component-scan base-package="xxx" ></context:component-scan>
<!-- 默认的注解映射的支持 -->
<mvc:annotation-driven />
------解决方案--------------------
你的controller注解加了么 我没看到你截图显示
你最好把错误信息贴出来