gpt4 book ai didi

java - Struts 2 Action 没有被调用

转载 作者:太空宇宙 更新时间:2023-11-04 14:54:53 25 4
gpt4 key购买 nike

几天来,我试图找出为什么我的操作没有以这种特定形式被调用。

我的表单如下所示,我有 struts URL 标签,我将其与 Bootstrap 框架一起使用:

 <s:form action="RegisterUser" cssClass="form-horizontal" id="id-register-form" method="post">
Couple of Struts 2 UI tags
</s:form>

我的注册用户操作非常简单,其中只有一个执行方法,该方法返回字符串“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 和 jquery 验证库进行客户端验证,然后使用 struts 验证框架进行服务器端验证,但我相信问题与验证无关,更多的是在操作映射方面或与提交按钮相关的内容。下面是我的提交按钮,

<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>"
}
});
});

最佳答案

尝试更改消息所在的代码

Email:  {
required: "<small>Please enter a valid email address</small>",
email: "Email addresses are of the form user@host."
}

关于java - Struts 2 Action 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23325223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com