struts 在action端进行校验以后,应该会将错误信息返回到页面,如果我要自己写代码获取错误信息,主要是想获取出现错误的field的property,不知道有没有什么办法获取?我的意图: 获取出现错误的field的property, 比如userName, 除了用<html:errors />显示错误以外,我还想highlight出错的field谢谢!!
struts 在action端进行校验以后,应该会将错误信息返回到页面,如果我要自己写代码获取错误信息,主要是想获取出现错误的field的property,不知道有没有什么办法获取?我的意图: 获取出现错误的field的property, 比如userName, 除了用<html:errors />显示错误以外,我还想highlight出错的field谢谢!!
我假设你是通过actionform来验证的
出错的话struts把一个错误集合加到request里面
你页面除了用html:errors 还可以用<% request.getAttribute(xxxxxxx) %>来判断并且作处理
比如:
<div id="userName_">User Name: <html:text property="userName" value=""/></div>如果校验出错了,那么可以通过html:errors 显示错误信息, 可是我同时想通过自己的代码捕捉到是哪个区域出错,比如这里是userName,这样可以通过改变<div id="userName_">的CSS或者style来highlight. 问题就是,我怎么通过自己的代码捕捉到是哪个区域出错.如果用request.getAttribute(xxxxxxx),那么xxxxxxx 代表的是什么?谢谢!
while(e.hasMoreElements()){
String key = (String)e.nextElement();
if(key == Globals.ERROR_KEY){
Object value = request.getAttribute(key);
ActionErrors errors = (ActionErrors)value;
String errorsString = errors.toString();
System.out.println(errorsString );
}
}所有的error信息都在request中.