首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

<html:error>问题,百思不得其解,遮住脸再来问!

2014-01-26 
jsp:html:errors /struts-config:action-mappingsaction path/IndexAction typehzxbl.IndexActio

jsp:
  <html:errors />
 
  struts-config:
 
  <action-mappings>
  <action path="/IndexAction" type="hzxbl.IndexAction"
  name="IndexForm" scope="request" validate="true"
  input="/index.jsp">
  <forward name="ok" path="/index.jsp" />
  </action>
  </action-mappings>
 
  IndexForm:
  public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){
  ActionErrors errors=new ActionErrors();
  if((userName==null)||(userName.length()<1))
  errors.add("userName",new ActionMessage("hello.no.username.error"));
 
  return errors;
  }
  ApplicationResources.properties
  hzxbl.no.username.error=no user name
 
  用bean:message能输出信息
  struts1.1 jdk1.5
 
  为什么就不显示呢?我查了论坛的帖子,好象我没有他们的问题!奇怪啊,各位大大帮我看看
 

------解决方法--------------------------------------------------------
如果是struts1.1,那么应该使用ActionError啊
 
  errors.add("userName",new ActionError("hello.no.username.error"));
 
------解决方法--------------------------------------------------------
new ActionMessage("hello.no.username.error")
  改为
  new ActionError("hello.no.username.error")
------解决方法--------------------------------------------------------
struts1.2才用ActionMessage,struts1.1用ActionError
------解决方法--------------------------------------------------------
并且程序中是 hello.no.username.error
  资源文件中是 hzxbl.no.username.error
 
  <html:errors/>找不到hello.no.username.error,就不会显示相应的信息,也不会提示找不到message key
 
  不像<message key标答,如果找不到key就会报出异常来

        

热点排行