java - IE10向Spring Controller 发送双重post请求

标签 java spring internet-explorer spring-mvc

我的主页上有一个“忘记密码”按钮,该按钮在 Chrome 中工作正常,但如果在 IE 中使用,则会发送两个 post 调用,从而生成 2 封电子邮件通知发送给用户。如何防止 IE 中发生这种情况?

AM 使用 JDK 7、Spring-security 3.1.4、spring web mvc 3.2.4 和 Hibernate 3.6.10

当我在 Fiddler 中捕获它时,我看到以下流量

# Result Protocol Host URL Body Caching Content-Type Process Comments Custom<br/> 1 200 HTTPS dc-rpalle7 /CP/forgotPassword.do 1,699 no-cache; Expires: Wed, 31 Dec 1969 23:59:59 GMT text/html;charset=utf-8 iexplore:45740<br/> 2 200 HTTP Tunnel to dc-rpalle7:443 0 iexplore:45740<br/> 3 200 HTTPS dc-rpalle7 /CP/forgotPassword.do 1,699 no-cache; Expires: Wed, 31 Dec 1969 23:59:59 GMT text/html;charset=utf-8 iexplore:45740

这是 Controller 中我的忘记密码方法

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView forgotPassword(HttpServletRequest request, HttpServletResponse response) throws IOException,
            ServletException {
        getCurrentRequestProperties().put(CurrentRequestProperties.IS_VALID_REQUEST, true);
        authorizationService.logout();
        ModelAndView mav = new ModelAndView();
        String email = request.getParameter("email");
        if (email != null && StringUtils.isNotEmpty(email)) {
            User uRecord = api.search.query(
                    User.class,
                    api.search.and().add(api.search.property("emailAddress").eq(email))
                            .add(api.search.property("locked").eq(false))).first();
            if (uRecord == null)
                mav.addObject("failedMessage", "forgot.email.invalid");
            else {
                String url = request.getRequestURL().toString().replaceFirst(request.getServletPath(), "");
                try {
                    collabSecurityService.forgotPasswordSendEmail(uRecord, url, "Reset Password Initiate");
                    mav.addObject("validMessage", "forgot.email.valid");
                } catch (Exception ex) {
                    mav.addObject("failedMessage", "forgot.email.error");
                }
            }
        }
        mav.addObject("notimeout", true);
        return mav;
    }

这是我的collabSecurityService.forgotPasswordSendEmail(...)方法

public void forgotPasswordSendEmail(User user, String URL, String notification) {
    UserSecurityQuestions userSecQuestions = api.search.query(UserSecurityQuestions.class,
            api.search.property("user").eq(user)).first();
    if (userSecQuestions == null) notification = "Reset Password Error";
    EmailTemplate emailTemp = api.search.query(EmailTemplate.class, api.search.property("name").eq(notification))
            .first();
    if (emailTemp != null) {
        String body = emailTemp.getEmailBody();
        if (userSecQuestions != null && notification.equals("Reset Password Initiate")) {
            String hStr = Long.toHexString(new SecureRandom().nextLong());
            String url = URL.toString() + "/resetPassword.do?hStr=" + hStr;
            body += "<br/><br/>" + url;
            userSecQuestions.setHashString(hStr);
            long four = 14400000;
            userSecQuestions.setValidThrough(new Timestamp(new Date().getTime() + four));
            userSecQuestions.setTries(0);
        }

        IEmailMessage message = new EmailMessage();
        message.setSubject(emailTemp.getSubject());
        message.setToAddress(user.getEmailAddress());
        message.setFromAddress(emailTemp.getFromAddress());
        message.setEmailBody(body, emailTemp.getContentType());
        api.notification.sendEmailMessage(message);
    }
}

最佳答案

当使用 Javascript 执行提交时,我们在 IE9 上也遇到了类似的问题。 IE9 在这种情况下发表了两个帖子。决定使用 onclick="... return false;"

关于java - IE10向Spring Controller 发送双重post请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26350461/

相关文章:

java - 使用 tcp 从 java 发送 double 到 C#

java - 一起使用@Spy 和@Autowired

delphi - IExplorer.exe 的 ShellExecute 路径

javascript - 在 IE9 上删除阴影边框

java - 如何允许拆分中引用数据?

java - isValid 抛出异常 - hibernate validator

java - ClientRequest 接受所有证书

mysql - LEFT JOIN 与 ON - Spring 中的 JPA 存储库

java - 部署到 AppFog 时未检测到环境变量

javascript - 原型(prototype)观察者在 IE8 中不触发