如何在Spring MVC中将一个页面重定向到另一个页面

时间:2015-09-07 10:10:43

标签: java spring model-view-controller

这是我的控制器:

  @Controller
    public class WebRedirectController {
        @RequestMapping(value = "/welcome", method = RequestMethod.GET)
        public String welcome() {
            return "welcome";
        }

        @RequestMapping(value = "/redirect", method = RequestMethod.GET)
        public String redirect() {
            return "redirect:finalPage";
        }

        @RequestMapping(value = "/finalPage", method = RequestMethod.GET)
        public String finalPage() {
            return "final";
        }
    }

servletContext.xml:

<beans xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
    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">

    <!-- Enable annotation driven controllers, validation etc... -->
    <mvc:annotation-driven></mvc:annotation-driven>
    <context:component-scan base-package="com.dineshonjava.controller">
    </context:component-scan>

    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        id="viewResolver">
        <property name="prefix" value="/WEB-INF/views/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

</beans>  

我在运行应用程序时遇到此异常:

来自ServletContext资源[/WEB-INF/config/sdnext-servlet.xml]的XML文档中的第10行无效;嵌套异常是org.xml.sax.SAXParseException; lineNumber:10; columnNumber:65; cvc-elt.1:找不到元素&#39; bean的声明。

请告诉我我在哪里做错了我试图解决这个问题,但仍然无法修复请建议我。

1 个答案:

答案 0 :(得分:0)

我认为你应该在XML文档中添加它

  1. contextConfigLocation的 /WEB-INF/classes/applicationContext.xml