用这个标签老不成功,求解释!public class ValidateForm extends ActionForm {
private User user = new User();
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
} @Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(user.getName() == null || "".equals(user.getName().trim())) {
System.out.println("name must be not null!");
errors.add("name", new ActionMessage("name", "name must be not null!"));
}
if(errors.get().hasNext()) {
System.out.println("here is ValidateForm and has errors");
return errors;
} else {
System.out.println("here is ValidateForm and no errors");
return null;
}
}
}Action的execute方法只有一句mapping.findForward("success");struts-config.xml<struts-config> <form-beans>
<form-bean name="validateForm"
type="com.struts.form.ValidateForm">
</form-bean>
</form-beans> <action-mappings>
<!-- 带有验证功能的ACTION -->
<action path="/validateAction" name="validateForm"
type="com.struts.action.ValidateAction"
input="/ValidateAction/errors.jsp" validate="true">
<forward name="success" path="/WEB-INF/user/success.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
验证失败的JSP页面就一句
<html:errors/>
标签库也引进来了后台输出name must be not null!
here is ValidateForm and has errors
//上面这两句是System.out.println输出的
2011-4-27 21:32:02 org.apache.struts.util.PropertyMessageResources loadLocale
警告: Resource MessageResources_zh_CN.properties Not Found.
2011-4-27 21:32:02 org.apache.struts.util.PropertyMessageResources loadLocale
警告: Resource MessageResources_zh.properties Not Found.
2011-4-27 21:32:02 org.apache.struts.util.PropertyMessageResources loadLocale
警告: Resource MessageResources.properties Not Found.
顺便抱怨下struts1的文档
private User user = new User();
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
} @Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if(user.getName() == null || "".equals(user.getName().trim())) {
System.out.println("name must be not null!");
errors.add("name", new ActionMessage("name", "name must be not null!"));
}
if(errors.get().hasNext()) {
System.out.println("here is ValidateForm and has errors");
return errors;
} else {
System.out.println("here is ValidateForm and no errors");
return null;
}
}
}Action的execute方法只有一句mapping.findForward("success");struts-config.xml<struts-config> <form-beans>
<form-bean name="validateForm"
type="com.struts.form.ValidateForm">
</form-bean>
</form-beans> <action-mappings>
<!-- 带有验证功能的ACTION -->
<action path="/validateAction" name="validateForm"
type="com.struts.action.ValidateAction"
input="/ValidateAction/errors.jsp" validate="true">
<forward name="success" path="/WEB-INF/user/success.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="MessageResources" />
</struts-config>
验证失败的JSP页面就一句
<html:errors/>
标签库也引进来了后台输出name must be not null!
here is ValidateForm and has errors
//上面这两句是System.out.println输出的
2011-4-27 21:32:02 org.apache.struts.util.PropertyMessageResources loadLocale
警告: Resource MessageResources_zh_CN.properties Not Found.
2011-4-27 21:32:02 org.apache.struts.util.PropertyMessageResources loadLocale
警告: Resource MessageResources_zh.properties Not Found.
2011-4-27 21:32:02 org.apache.struts.util.PropertyMessageResources loadLocale
警告: Resource MessageResources.properties Not Found.
顺便抱怨下struts1的文档
解决方案 »
- getBean之后,log4j不能打印信息
- 寻求资深Java技术人才
- Struts中使用javascript时出现的问题
- 求助在STRUTS里面用UPLOAD上传文件的时候中文名取不到
- 请教一个关于将TOMCAT5.0和JBOSS4.0整合到ECLIPSE3.1后出现的问题
- 有关TOMCAT配置的一个小问题
- 烦,烦,烦,还是中文问题,JBuilder9连接mysql的中文问题,我使用jdbtable连接mysql,出现乱码
- 有谁知道在JAVA中播放FLASH
- 如何在java程序里用xslt格式化一个document?
- Java EE中的JavaBean
- 动态生成tree..求救啊
- 关于提取html网页为纯文本内容的问题
你应该提供一个MessageResources.properties文件。在类路径根下。
将
errors.add("name", new ActionMessage("name", "name must be not null!"));
改成
errors.add("name", new ActionMessage("name must be not null!", false));之后,LZ再慢慢弄明白MessageResources.properties是怎么回事吧