Spring调度程序不会重定向到下一页

时间:2015-04-04 12:51:17

标签: java spring-mvc http-status-code-404

在我的项目中,spring dispatcher没有重定向到下一页,以下是我的项目

调度-servlet.xml中

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

    <context:component-scan base-package="com.go.controller" />
    <mvc:annotation-driven />

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

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.postgresql.Driver" />
        <property name="url" value="jdbc:postgresql://localhost:5432/GoAnalyserDB" />
        <property name="username" value="postgres" />
        <property name="password" value="toor" />
    </bean>

</beans>

我已经在/ WEB-INF / pages中创建了页面,但它仍然没有重定向到该页面。

我的控制器类

package com.go.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class GoScrapperRouter {

    public GoScrapperRouter(){
        System.out.println("-------Inside thr GoScrapperRouter-------");
    }

    @RequestMapping("/logInSuccess")
    public ModelAndView logInSuccessFn(){
        System.out.println("inside startAnalyser controller loginsuccess");
        ModelAndView model = new ModelAndView("profile");       
        return model;
    }

}

我的jsp文件

<html>
<head></head>
<body>
<form class="form-signin" action="logInSuccess">
                  <label for="exampleInputEmail1">Email address</label>
                  <input type="text" class="input-block-level" placeholder="Email address" ng-model="userName">
                  <label for="exampleInputPassword1">Password</label>
                  <input type="password" class="input-block-level" placeholder="Password" ng-model="password">
                  <center><button class="btn btn-large" type="submit" >Login</button></center>


               </form>
</body>
</html>

当我单击按钮时,控件进入控制器功能并打印文本 “在startAnalyser控制器loginsuccess里面”, 但它没有重定向到WEB-INF / pages /

中的下一页

我的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>Go Scrapper</display-name>

  <servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>                                    
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <welcome-file-list>
    <welcome-file>new.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>

</web-app>

1 个答案:

答案 0 :(得分:0)

请您尝试以下方法:

@RequestMapping("/logInSuccess")
    public String logInSuccessFn(){
                System.out.println("inside startAnalyser controller loginsuccess");
                //ModelAndView model = new ModelAndView("profile");       
                return "profile";
            }