public String add() {
if(name == null || !name.equals("admin")) {
this.addFieldError("name", "name is error");
this.addFieldError("name", "name is too long");
return ERROR;
}
return SUCCESS;
}

 

 this.addFieldError(name, errorMessage);

使用此方法要继承ActionSupport

在页面中显示错误信息:

<!-- 以固定的css样式取出错误信息,不方便我们进行相应的处理-->
<s:fielderror fieldName="name" theme="simple"/>
<!-- 从存储错误信息的Map中拿数据 -->
<s:property value="errors.name[1]"/>
<!-- 显示详细的栈信息-->
<s:debug></s:debug>

使用struts2标签要引入标签库

<%@taglib uri="/struts-tags" prefix="s" %>


加上<s:debug>标签会产生一条连接,点击后显示struts的一些信息:

1)value stack contents:OGNL值栈

struts2学习 - action -5 value stack contents 和 stack context

相关文章:

  • 2021-06-20
  • 2021-09-12
  • 2021-06-07
  • 2022-12-23
  • 2022-02-09
  • 2021-09-11
  • 2022-01-03
  • 2021-04-08
猜你喜欢
  • 2021-05-28
  • 2021-11-08
  • 2021-08-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-08-12
相关资源
相似解决方案