Spring 控制器方法中不需要的逗号分隔参数
我看到Spring MVC控制器出现了一个奇怪的问题。此方法用于设置密码。它采用两个表单参数“密码”和“确认密码”。第一次调用窗体时,这工作正常 - 字段被传递给方法。
第二次提交表单时会出现此问题。如果表单首次填写不正确,则会将用户正确发送回表单页面,并提示用户再次输入密码。但是,该方法的参数在第二次尝试时不正确。参数是一个逗号分隔的列表,其中包括与第二个表单条目连接的第一个表单条目。
例:
带有字段“密码”的第一个表单帖子的值为“abc”。方法参数“password”具有值“abc”。
带有字段“密码”和值“xyz”的第二个表单帖子。方法参数“password”具有值“xyz,abc”。
Spring MVC文档并没有指出太多用处。不知何故,旧的表格帖子被记住并包括在内。有人有解决这个问题的经验吗?
控制器方法如下:
@RequestMapping(value = "/account/reset", method = RequestMethod.POST)
public String resetPassword(@RequestParam("password") String password,
@RequestParam("confirmPassword") String confirmPassword,
@RequestParam("hash") String hash, ModelMap model) throws EncryptionException
{
String userName = stringEncrypterService.decrypt(hash);
User user = userService.findUserByPath(userName);
if (!password.equals(confirmPassword))
{
model.put("hash", hash);
model.put("user", user);
model.put("error",
"The two passwords you entered below do not match. Please try again.");
return "users/resetPassword";
}
userService.updatePassword(user, password);
emailService.sendUserInfoChange(user);
return "redirect:/session/signin?passwordReset=true";
}
更新。一些响应者建议,有问题的帖子可能具有额外的URL参数或隐藏的表单字段,从而导致重复的字段名称。我向Fiddler确认情况并非如此。下面是第三次尝试的原始请求。(稍作编辑以删除会话 Cookie)。
POST http://wintest.foriodev.com/simulate/account/reset/ HTTP/1.1
Host: wintest.foriodev.com
Connection: keep-alive
Referer: http://wintest.foriodev.com/simulate/account/reset/
Content-Length: 73
Cache-Control: max-age=0
Origin: http://wintest.foriodev.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16
Content-Type: application/x-www-form-urlencoded
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: AUTOLOGIN_TOKEN=xyz; SIMULATE_WORKER=wintest; JSESSIONID=xyz;
password=a&hash=xyz&confirmPassword=a&save=Reset+Password