【问题标题】:how to redirect one page to another page in Spring MVC如何在 Spring MVC 中将一个页面重定向到另一个页面
【发布时间】:2015-09-07 10:10:43
【问题描述】:

这是我的控制器:

  @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;行号:10;列号:65; cvc-elt.1:找不到元素“beans”的声明。

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

【问题讨论】:

  • 您遇到的错误与您提出的问题完全无关。检查你的 xml。检查您的类路径中是否有适当的 Spring 库。
  • paste.ofcode.org/HFVEJBgDjyU6pscDWmKdeL 这是 web.xml @ Sotirios Delimanolis
  • 错误是指sdnext-servlet.xml 文件。交叉检查是否有效,如果仍然找不到错误,请在此处粘贴该文件,
  • 请把sdnext-servlet.xml的内容贴在这里。

标签: java spring model-view-controller


【解决方案1】:

我认为你应该在你的 XML 文档中添加这个

  1. 上下文配置位置 /WEB-INF/classes/applicationContext.xml

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 2011-08-22
    • 1970-01-01
    • 2014-08-10
    • 2021-06-24
    相关资源
    最近更新 更多