当前位置: 代码迷 >> Java Web开发 >> SpringMVC 跳转有关问题
  详细解决方案

SpringMVC 跳转有关问题

热度:862   发布时间:2016-04-12 22:13:21.0
SpringMVC 跳转问题
本帖最后由 Flashzx 于 2013-08-15 18:31:05 编辑
框架搭好后程序可以正常运行,但在return ModelAndView ( new ModelAndView("goto.jsp"))时不是跳转指定的页面,而是跳转 @requestMapping("list")指定的访问路径,也就是 list.jsp 而不是 goto.jsp。求解决.

代码如下:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


<servlet> 
        <servlet-name>SpringMVC</servlet-name> 
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
        <load-on-startup>1</load-on-startup> 
    </servlet>
    <servlet-mapping> 
        <servlet-name>SpringMVC</servlet-name> 
        <url-pattern>*.do</url-pattern> 
    </servlet-mapping>


  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
     <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>




springmvc-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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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">
<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<!-- Spring MVC的注解功能,完成请求和注解POJO的映射-->  
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />

<!-- 扫描包 -->
<context:component-scan base-package="com.ld.*.controller" />
<context:component-scan base-package="com.ld.*.service" />
<context:component-scan base-package="com.ld.*.dao" />
  相关解决方案