<form action="@routes.Account.changeemail()" method="Post">
email:<input name ="email">
<button type="submit" name="action" value="Change_email">save</button>
<br />
</form>
<form action="@routes.Account.changepassword()" method="Post">
password:<input name ="password">
<button type="submit" name="action" value="change_password">save</button>
</form>
<br />
这是我的控制器
public static Result changeemail(){
final DynamicForm form = Form.form().bindFromRequest();
Logger.info(form.get("email"));
return TODO;}
public static Result changepassword(){
final DynamicForm forms = Form.form().bindFromRequest();
Logger.info(forms.get("password"));
return TODO;}
这里有路线:
GET /account controllers.Account.accountview()
POST /account controllers.Account.changeemail()
POST /account controllers.Account.changepassword()
问题是如果我按下Change_email按钮它会做正确的事情,但是如果我按下密码按钮它正在执行changeemail动作,即使它应该处理changepasswort动作。我用firefox网络分析检查了它,似乎它正在发送正确的动作。
前进谢谢你的帮助
问候亚历克斯
答案 0 :(得分:2)
问题来自你的路线,顺序很重要。您的路由器始终采用执行POST /account
操作的第一个changeemail()
。对于两种不同的操作,您无法POST /account
。它应该是:
GET /account controllers.Account.accountview()
POST /account/change-email controllers.Account.changeemail()
POST /account/change-password controllers.Account.changepassword()