JSP页面不会解析电子邮件地址作为参数 [英] JSP page url not parsing email address as a parameter

查看:176
本文介绍了JSP页面不会解析电子邮件地址作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring-MVC应用程序,我正在处理密码重置功能。发送给用户的令牌创建在3部分,Ema​​il-id:timestamp:secretkey ..所以例如,当我尝试测试密码重置链接并粘贴了我在电子邮件中收到的URL(给出如下)。我在一个字段中复制了token参数,任何.com被忽略?为什么会这样?任何解决方案。

I am working on a Spring-MVC application, and I am working on the password reset functionality. The token which is sent to user is created in 3 parts, Email-id : timestamp : secretkey.. So for example, when I tried to test the password reset link and pasted the url I recived in email(given below). I copied the token parameter in a field, anything .com is ignored? Why is that happening? Any solutions.

重置链接网址:

localhost:8085/newpassword/myemail@gmail.com:1416404954901:uXRjA7FAqe0bO_zdwse_4PdVzjQdT1RjJ3QYG5PEODg

JSP页面保存为:

localhost:8085/newpassword/myemail@gmail

resetpassword.jsp页面:

resetpassword.jsp page :

<c:url var="addAction" value="/newpassword/{token}" ></c:url>
<form:form action="${addAction}" 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="token">
                    <spring:message text="token"/>
                </form:label>
            </td>
            <td>
                <form:input path="token"  />
            </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>

控制器代码:

 @RequestMapping(value = "/resetpassword")
    public String newPasswordPage(Model model){
        model.addAttribute("person", new Person());
        return "resetpassword";
    }
   @RequestMapping(value = "/newpassword/{token}")
   public String changePasswordFunction(@ModelAttribute("person") Person person, Model model, @PathVariable("token") String token){
        if(person.getPassword() == null){
            return "resetpassword";
        } else {
            personService.changePassword(token,person.getUsername(),person.getPassword());
            System.out.println("User and password is :"+person.getUsername()+" and password "+person.getPassword());
            model.addAttribute("person",person);
            return "redirect:/";
        }
    }

令牌创建机制:

 @Override
    public void createToken(String username){
        long timestamp = System.currentTimeMillis() - 1_000 * 60 * 60 * 48;
        StringBuilder sb = new StringBuilder();
        sb.append(generateTokenStringPublicPart(username, timestamp));
        sb.append(TOKEN_SEPARATOR);
        try {
            sb.append(computeSignature(username, timestamp, signKey));
        } 
      // The above method returns the String as :
return Base64.encodeBase64URLSafeString(hmac.doFinal(sb.toString().getBytes(StandardCharsets.UTF_8)));

我将该链接传递给该人的电子邮件ID。任何解决方案我尝试使用MD5,它完美地作为它的整数。

I pass that link to the email id of the person. Any solutions? I tried using MD5, it works perfectly as its just integers.

推荐答案

尝试通过 URL encoder 。它应该适当地转义所有有问题的字符,以便编码的令牌可以作为URL的一部分传递。

Try passing the token through URL encoder. It should properly escape all problematic characters, so that encoded token can be passed as part of the URL.

这篇关于JSP页面不会解析电子邮件地址作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆