几天来,我试图了解为什么我的行为不会以这种特殊形式被调用。
我的表单如下所示,我有struts URL标记,我正在使用它与Bootstrap框架:
<s:form action="RegisterUser" cssClass="form-horizontal" id="id-register-form" method="post">
Couple of Struts 2 UI tags
</s:form>
My Register用户操作非常简单,只有一个返回字符串"success"
的执行方法:
public class RegisterUser extends ActionSupport {
public RegisterUser() {
}
@Override
public String execute() throws Exception {
System.out.println("Inside execute method test 1!");
return "success";
}
}
我的struts.xml
上面的内容如下所示:
<action name="RegisterUser" class="Mypackage.RegisterUser" method="execute">
<result name="success">/WEB-INF/views/usermanagement/register-success.jsp</result>
<result name="error">/WEB-INF/views/usermanagement/register-error.jsp</result>
</action>
但是每当我点击表单的提交按钮时,表单提交都不会被触发。我使用jquery验证库进行客户端验证,然后使用struts验证框架进行服务器端验证,但我认为问题与验证无关,但更多关于动作映射方面或与提交按钮相关的内容。下面是我的提交按钮,< / p>
<s:submit type="button" cssClass="btn btn-primary" value="Create Account" cssStyle="float:left;">Create Account</s:submit>
感谢有人可以看看并给我一些见解。我在Glassfish v4上使用Netbeans IDE,我的Struts 2在win 8.1上是2.3.15.3
这是我使用jQuery进行客户端验证的JS代码:
$(document).ready(function() {
// validate the comment form when it is submitted
$("#id-register-form").validate({
errorPlacement: function(error, element) {
if (element.attr("name") == "Email") {
error.appendTo('#error-Email');
}
else if (element.attr("name") == "Password") {
error.appendTo('#error-Password');
}
else if (element.attr("name") == "ConfirmPassword") {
error.appendTo('#error-ConfirmPassword');
}
else if (element.attr("name") == "AgreetoPolicy") {
error.appendTo('#error-Agree');
}
},
rules: {
Email: {
required: true,
email: true
},
Password: {
required: true,
minlength: 5
},
ConfirmPassword: {
required: true,
minlength: 8,
equalTo: "#Password"
},
AgreetoPolicy: "required"
},
messages: {
Email: "<small>Please enter a valid email address</small>",
Password: {
required: "<small>Please provide a password</small>",
minlength: "<small>Your password must be at least 8 characters long</small>"
},
ConfirmPassword: {
required: "<small>Please provide a password</small>",
minlength: "<small>Your password must be at least 5 characters long</small>",
equalTo: "<small>Please enter the same password as above</small>"
},
AgreetoPolicy: "<strong><small>Please accept our policy</small></strong>"
}
});
});
答案 0 :(得分:0)
尝试将此代码更改为消息
Email: {
required: "<small>Please enter a valid email address</small>",
email: "Email addresses are of the form user@host."
}
答案 1 :(得分:0)
Yup问题现在已经解决。这是我破坏的Jquery验证码,负责不提交表单...感谢Roman和Andrea的帮助和帮助。感谢它。