struts-config.xml配置里要加个
<action
...
validate=true
...
/>
<action
...
validate=true
...
/>
解决方案 »
- tomcat的安装问题
- 问题讨论:hibernate中one-to-one、one-to-many、many-to-one的设计有必要吗?
- web.xml问题
- java进程 无故消失
- Xpath问题
- struts标签问题
- 用struts能做二级菜单吗?
- java调用jni读取dll的问题
- 请教!!!!想学J2EE
- why csdn send xml document to the browser?
- jbuilder中怎么安装javamail?
- 谁能讲解一下structs的例子:http://localhost:8080/struts-examples/exercise/bean-write-2.do
里面不能是直接填写内容的,他是资源文件里的一个key值
1、errors.add("username1", new ActionMessage("用户名不能空"))中“用户名不能空”应该从资源文件中读取,即是资源文件中的变量,这样才能实现国际化。
2、如果在配置文件中将validate设为true(当然,还要设置input属性,这样在发生错误时,struts能自动转向输入页面)。
<action
...
validate=true
...
/>
如果没有将validate设为true,那么在Action中要显式调用ActionForm.validate(),得到ActionErrors对象,然后再调用saveErrors(request, errors)将错误信息保存。
ActionErrors errors = new ActionErrors(); if ((username == null) || (username.length() < 1))
{
System.out.println("2222222222");
errors.add("username1", new ActionMessage("用户名不能空"));
this.saveErrors(request,errors);
}
return errors;
}