我在AWS上运行了api。我使用TomCat来运行我的Play应用程序。我对前端和scala知之甚少,但我按照教程创建了一个Form。问题是:页面没问题,我可以正常访问。问题是当我点击提交按钮时...它总是会导致错误的POST网址。
这是错误的网址:
POST /myapplication/myapplication/recoverPasswordAction
应该是
POST /myapplication/recoverPasswordAction
有人知道如何解决这个问题吗?
Main.scala.html:
@(title: String)(content: Html)
<!DOCTYPE html>
<html>
<head>
<title>Recuperar senha</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<!-- Load site-specific customizations after bootstrap. -->
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="http://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-inverse" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="/">Recuperar senha</a>
</div>
</div>
</div>
@content
<script src="https://code.jquery.com/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<!-- Enable tooltips. Used primarily to validate that JQuery + Bootstrap JS are loaded. Remove this script if you don't want tooltips. -->
<script type="text/javascript">
jQuery(function ($) {
$("[rel='tooltip']").tooltip()
});
</script>
</body>
</html>
这是我的fieldset.scala.html
@(changePassword: Form[views.formdata.ChangePasswordForm])
@import views.html.bootstrap3._
<fieldset>
<!-- Header -->
<div id="legend">
<legend>Recuperar Senha</legend>
</div>
<!-- Name -->
@password(changePassword("password"),
label = "Senha",
placeholder = "Nova senha",
help = "Senha com no mínimo 4 e no máximo 12 carácteres.")
<!-- Password -->
@password(changePassword("confirmPassword"),
label = "Confirmar Senha",
placeholder = "Confirme a Nova senha",
help = "")
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button id="submit" type="submit" value="Submit" class="btn btn-primary">Confirmar</button>
</div>
</div>
</fieldset>
Index.scala.html:
@(changePassword: Form[views.formdata.ChangePasswordForm])
@import helper._
@Main("Index") {
<div class="container">
<div class="well">
@form(routes.UserPasswordRecoveryController.postCreateNewPassword(), 'class -> "form-horizontal") {
@fieldset(changePassword)
}
</div>
@if(flash.containsKey("success")) {
<div class="well">
<div id="success-message" class="text-success">
@flash.get("success")
</div>
</div>
}
@if(flash.containsKey("error")) {
<div class="well">
<div id="error-message" class="text-danger">
@flash.get("error")
</div>
</div>
}
</div>
}
这是我的ChangePasswordForm.java
public class ChangePasswordForm {
public String password;
public String confirmPassword;
public long userId;
private PBKDF2Generator pbkdf2Generator;
/** Required for form instantiation. */
public ChangePasswordForm() {
}
public List<ValidationError> validate() {
List<ValidationError> errors = new ArrayList<>();
if (password == null || password.length() == 0) {
errors.add(new ValidationError("password", "Por favor, digite uma senha."));
}else if(password.length() < 4){
errors.add(new ValidationError("password", "Por favor, digite uma senha com no mínimo 4 dígitos."));
}else if(password.length() > 12){
errors.add(new ValidationError("password", "Por favor, digite uma senha com no máximo 12 dígitos."));
}else if(confirmPassword.length() == 0 || confirmPassword.equals("")){
errors.add(new ValidationError("confirmPassword", "Por favor, digite a confirmação da senha."));
}else if(!confirmPassword.equals(password)){
errors.add(new ValidationError("confirmPassword", "Senha incorreta."));
}
if(errors.size() > 0){
return errors;
}else{
try {
String uuid = UUID.randomUUID().toString().replace("-", "");
this.pbkdf2Generator = new PBKDF2Generator();
this.password = pbkdf2Generator.generateStrongPasswordHash(password, uuid);
this.confirmPassword = pbkdf2Generator.generateStrongPasswordHash(confirmPassword, uuid);
} catch (NoSuchAlgorithmException | InvalidKeySpecException | UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
}
最后是没有以正确方式调用的按钮操作的路径:
POST /recoverPasswordAction controllers.UserPasswordRecoveryController.postCreateNewPassword()