私のEclipse動的Webプロジェクトの構造は次のとおりです。
Webコンテンツ:
- CSS
- (各種cssファイル使用)
- JavaScript
- (JSファイル)
- ページ
- Page1.jsp
- Page2.jsp
- メタINF
- WEB-INF
- ライブラリ
- web.xml
でフロント エンドと Ajax 検証に jQuery 検証エンジンを使用しています。Ajaxpage1.jsp
部分は、データを検証するアクション クラスを呼び出します。
page1.jsp
:
<script>
$(document).ready (function ()
{
$("#subform").validationEngine('attach', {
autoHidePrompt : true ,
autoHideDelay : 5000,
ajaxFormValidation : true,
ajaxFormValidationURL : 'ajaxVal/FormVal',
ajaxFormValidationMethod : 'post',
onBeforeAjaxFormValidation : function (form, options) {
console.log ("before ajax validation in function");
form.validationEngine ('hideAll');
$('#txtlname').validationEngine ('showPrompt', 'Validating your name please wait', 'load', true);
return true;
},
onAjaxFormComplete : function (status, form, json, option) {
console.log ("ajax validation done");
console.log ("status: " + status);
console.log ("data returned " + json);
console.log ("checking status now");
if (status) {
console.log ("status good, detaching now");
form.validationEngine ('hideAll');
form.validationEngine ('detach');
form.submit ();
}
}
});
});
</script>
<title>Form Validation test</title>
</head>
<body>
<div>
<form id = "subform" action = "submitForm" method = "post"> <br><br><br>
First Name: <input id = "txtfname" name = "txtfname" type = "text" class = "validate[required]"
placeholder = "enter emp name" />
Last name: <input id = "txtlname" name = "txtlname" type = "text" placeholder = "enter emp lname"
class = "validate[required, ajax[ajaxStrutsCall]]" />
Age: <input id = "txtage" name = "txtage" type = "text" placeholder = "enter age" />
<input id ="cmdsubmit" type = "submit" name = "cmdsubmit" value = "click here" />
</form>
</div>
</body>
"last name"
input タグ の class 属性の Ajax 呼び出しjquery.validationEngine-en.js
は次のとおりです。
"ajaxStrutsCall": {
"url": "ajaxVal/LnameVal",
"alertTextOk": "Your last name seems ok",
"alertText": "Bad Last name",
"alertTextLoad": "Validating, please wait"
},
私のstruts.xml
:
<struts>
<constant name = "struts.devMode" value = "true" />
<package name = "strutsaction" extends = "struts-default">
<action name = "submitForm" class = "validation.action.JqueryAction" method = "execute">
<result name = "success">/Pages/page2.jsp</result>
</action>
</package>
<package name = "ajaxAction" namespace = "/ajaxVal" extends = "json-default">
<action name = "LnameVal" class = "validation.struts.AjaxStrutsAction" method = "execute">
<result name = "success" type = "json" />
</action>
<action name = "FormVal" class = "ajax.form.validator.FormValidation" method = "execute">
<result name = "success" type = "json" />
</action>
</package>
ここで問題は、すべてのコードが完全に機能していたときに、page1.jsp
とpage2.jsp
が 1 つのフォルダーにあったとき、つまり、フォルダーにWebContent
それらを追加するとすぐにPages/
、次のページへのアクションが実行されたとしても、Ajax 検証呼び出しが発生しないことです。 .
これは、次の URL が機能したため、Tomcat サーバーの struts クラスにアクセスしようとしたときに、URL が一致しないためであると考えました。
http://localhost:8080/AjaxTest/ajaxVal/LnameVal
ただし、これはしませんでした:
http://localhost:8080/AjaxTest/Pages/ajaxVal/LnameVal
ajaxAction
パッケージの名前空間を に変更しましたstruts.xml
が/Pages/ajaxVal
、サイコロはありません。