Struts中FORM的ActionErrors怎样在jsp页面取出来呢?

来源:百度知道 编辑:UC知道 时间:2024/08/23 06:42:01
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors=new ActionErrors();
if(message_title.equals("")){
System.out.println("Get Errors");
errors.add("title", new ActionMessage("标题不能为空!"));
}
return errors;
}

FORM里这样设置了,出错误以后转发到目标页面index.jsp.然后怎样在这个index.jsp取出errors中的值呢?

在ApplicationResources.properties中配置下,加上:
message_title_null=<li>message_title is null

你写的 errors.add("title", new ActionMessage("标题不能为空!"));有问题(我也不知道有没问题,最好不要写中文),改成:
errors.add("title", new ActionMessage("message_title_null"));

在就是你的struts-config.xml中要配置在<action>的属性中加上input="/index.jsp"即<action input="/index.jsp" .....>

最后在你的index.jsp中加上<html:errors property="title"/>。之后你的title如果输入空提交的话就会显示message_title is null

在index.jsp中加入<html:errors property = "title"/>这个标签就可以取出了。

<html:errors property = "title"/>标签写入jsp就可以了

在struts2.0里面用<s:actionerror />这个标签