下面是js的驗證
<script type="text/javascript">
$(document).ready(function(){
$.formValidator.initConfig({onError:function(msg){alert(msg)}});
$("#keyWord").formValidator({onshow:"請輸入非法關鍵字",onfocus:"非法關鍵字不能爲空",oncorrect:"通過"}).InputValidator({min:2,onerror:"非法關鍵字不能少於2個字符,請確認"}).AjaxValidator({
// type : "get",
url : "<c:url value='/ajax/checkIllegalKeyWord.html'/>",
datatype : "json",
data: "keyWord:"+$("#keyWord").val(),
success : function(data){
if(data.result == 'true' ){
return true;
}
else{
return false;
}
},
buttons: $("#button"),
error: function(){alert("服務器沒有返回數據,可能服務器忙,請重試");},
onerror : "該關鍵字已經存在,請更換關鍵字",
onwait : "正在對關鍵字進行合法性校驗,請稍候..."
}).DefaultPassed();
$("#replaceStr").formValidator({onshow:"請輸入替換符",oncorrect:"通過"}).InputValidator({min:1,onerror:"替換符至少爲一個字符"});
$("#level").formValidator({onshow:"請輸入等級",oncorrect:"通過"}).InputValidator({min:1,max:5,type:"value",onerror:"等級爲1-5之間的數"});
});
</script>
struts.xml
<action name="checkIllegalKeyWord" class="com.XX.xx.CheckAction" method="checkIllegalKeyWord">
<result type="json">
<param name="ignoreHierarchy">false</param>
<param name="excludeNullProperties">true</param>
<param name="excludeProperties">actionErrors,actionMessages,fieldErrors,texts,errorMessages,error,errors,locale</param>
</result>
</action>
驗證在action中正常,但是總提示服務器沒有返回數據.....並且其他原來沒問題的驗證也出現這個問題
錯誤:
org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"
原因:
原來在checkAction中用到的xxManager.xx()方法時,不僅加上了setxxManager還不小心還添加了getxxManager()的方法這樣json在返回數據的時候將manager也返回了,所以產生了這個情況。去掉get方法就沒問題了