我是一位经验丰富的程序员,他拥有多年的Spring 3.0框架经验,但这个让我感到有点困惑。
在我的表单中,我有三个不同的场景,我和标签都没有提交给我的控制器(我已经使用@InitBinder方法检查了任何绑定异常,但是没有&# 39; t任何错误......这是我的表格标签:
<form:form commandName="accountCommand" method="POST">
<form:hidden path="action"/> <%-- THIS WORKS --%>
<%-- ... --%>
<%-- These don't submit anything to the controller --%>
<div>
Old Password: <form:password path="oldPassword"/>
New Password: <form:password path="newPassword"/>
</div>
</form:form>
这是控制器:
@RequestMapping(value="editAccount.htm", method=RequestMethod.POST)
public String accountPost(@ModelAttribute AccountsCommand accountsCommand,
@RequestParam(required=false) String stripeToken,
Principal principal, ModelMap model) throws GeneralSecurityException, IOException, AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException
{
// Once inside here, the "accountsCommand" object doesn't have the expected mapped values... except the <form:hidden...> values are set accordingly.
}
这是命令对象:
public class AccountsCommand
{
private String oldPassword;
private String newPassword;
private String action;
public String getOldPassword()
{
return oldPassword;
}
public void setOldPassword(String oldPassword)
{
this.oldPassword = oldPassword;
}
public String getNewPassword()
{
return newPassword;
}
public void setNewPassword(String newPassword)
{
this.newPassword = newPassword;
}
public String getAction()
{
return action;
}
public void setAction(String action)
{
this.action = action;
}
}
我已经在setter方法中设置了断点,并且可以确认他们没有被要求输入&#34;密码&#34;字段。
这是我用来提交隐藏字段(可行)的JS代码:
$("#planSubmit").click(function () {
$("#action").val("updateAccount");
$("#accountCommand").submit();
return false;
});
编辑:
以下是我网站上显示的实际HTML代码:
<form id="accountCommand" action="/account/editAccount.htm" method="POST">
<input id="action" name="action" type="hidden" value=""/>
<div>
<input id="oldPassword" name="oldPassword" type="password" value=""/>
<input id="newPassword" name="newPassword" type="password" value=""/>
</div>
</form>
我已经确认密码输入确实在提交时通过在我调用$("#actionCommand").submit()
方法之前输出它们的值来提供值...但是一旦我在控制器中,这些值是空的。
答案 0 :(得分:0)
找出问题。
在我隐藏的所有字段之下,我添加了另一个<form>
标记...所以我在同一个网站上有两个表单。
这导致第二个表单下方的所有输入在提交给我的控制器时失败。
这是一个复制/粘贴失败,因为我从我的应用程序的另一部分复制了代码。
所以对于那些感兴趣的人...我刚刚删除了第二个<form>
代码并解决了我的问题
生活和学习!