在Spring中实现忘记密码给垃圾URL

时间:2014-11-13 16:45:57

标签: spring jsp spring-mvc

我正在开发一个Spring-MVC应用程序。我想实现忘记密码功能。为此,我正在使用秘密问题方法。我创建了一个JSP页面,在那里我收到了像username,secretanswer这样的值,然后检查这些值是否存在,然后保存用户提供的新密码。我在JSP页面遇到问题,当我点击提交时,它会显示一些垃圾URL。我相信这是一个小错误,我无法看到。请告诉我出了什么问题。

Apache tomcat错误网址:

HTTP Status 404 - /id=0,%20username=null,%20password=null

更改密码的控制器功能:

 @RequestMapping(value = "/forgotpassword")
    public String forgotPassword(Model model){
       model.addAttribute("person",new Person());
       return "forgotpassword";
    }

    @RequestMapping(value = "/changepassword")
    public String changepassword(@ModelAttribute("person") Person f,Model model){
        System.out.println("Did we reach here on submit");
        personService.checkAuthenticitiy(f.getUsername(), f.getSecretanswer(), f.getNewpassword());
        model.addAttribute("person", new Person());
        return "redirect:/forgotpassword";
    }

JSP页面:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Forgot Passsword page</title>
</head>
<body>

<td><a href="<c:url value='/' />" >Go Home</a></td>

<h1>
    Change password
</h1>

<c:url var="addAction" value="/changepassword" ></c:url>
<form:form action="${person}" commandName="person">
<table>
        <tr>
            <td>
                <form:label path="username">
                    <spring:message text="username"/>
                </form:label>
            </td>
            <td>
                <form:input path="username"  />
            </td>
        </tr>
        <tr>
            <td>
                <form:label path="secretquestion" >
                    <spring:message text="secretquestion"/>
                </form:label>
            </td>
            <td>
                <form:input path="secretquestion"/>
            </td>
        </tr>
        <tr>
            <td>
                <form:label path="secretanswer" >
                    <spring:message text="secretanswer"/>
                </form:label>
            </td>
            <td>
                <form:input path="secretanswer"/>
            </td>
        </tr>
    <tr>
        <td>
            <form:label path="newpassword" >
                <spring:message text="newpassword"/>
            </form:label>
        </td>
        <td>
            <form:input path="newpassword"/>
        </td>
    </tr>
        <tr>
            <td>
                <input name="submit" type="submit" value="Submit" />
            </td>
        </tr>
        </table>
    </form:form>
</body>
</html>

人物模型:

@Entity
@Table(name="person")
public class Person implements UserDetails{

 @Column(name = "username")
    private String username;


    @Column(name = "password")
    private String password;

    @Column(name = "secretquestion")
    private String secretquestion;

    @Column(name = "secretanswer")
    private String secretanswer;

    @Transient
    private String newpassword;
     //Getters and setters for all.

}

1 个答案:

答案 0 :(得分:1)

<c:url var="addAction" value="/changepassword" ></c:url>
<form:form action="${person}" commandName="person">

应该是

<c:url var="addAction" value="/changepassword" ></c:url>
 <form:form action="${addAction}" commandName="person">

人不是你的行动