我的主页上有一个“Forgot Passowrd”按钮,可以在Chrome中正常使用,但如果在IE中使用它,它会发送两个帖子,这会产生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
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
2 200 HTTP Tunnel to dc-rpalle7:443 0 iexplore:45740
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
这是我在控制器中的forgetPassword方法
@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);
}
}
答案 0 :(得分:1)
当通过Javascript执行提交时,我们遇到了与IE9类似的问题。在这种情况下,IE9发了两个帖子。决定使用onclick =&#34; ... return false;&#34;