public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors=new ActionErrors();
for(int i=0;i<groupby.length;i++)
{
if(!groupby[i].equals("none"))
{
for(int j=0;j<groupby.length;j++)
{
if(groupby[j].equals("groupby"))
break;
if(j==groupby.length-1)
{
errors.add("errormesg",new ActionMessage("没有选择列为group by"));
return errors;
}
}

for(int j=0;j<groupby.length;j++)
{
if(groupby[j].equals("none"))
{
errors.add("errormesg",new ActionMessage(groupby[j]+"在选择列表中无效,因为该列既不包含在聚合函数中,也不包含在 GROUP BY 子句中"));
return errors;
}
if(groupby[j].equals("groupby")&&i!=j)
{
errors.add("errormesg",new ActionMessage("GROUP BY 子句中只能有一个列"));
return errors;
}
}
}
}

return null ;
}当返回错误的时候,怎么在我输入的页面上显示呢?
我在jsp页面是
<html:messages id="errormesg" message="true">
<bean:write name="errormesg"/>
</html:messages>但是不会跑出错误信息

解决方案 »

  1.   

    楼主可以使用 <html:errors/>来显示错误!!!!!!
      

  2.   

    我知道有<html:errors/>和<html:messages/>都可以
    但是我不知道格式怎么写
      

  3.   

    <html:errors property="errormesg"/>   
      

  4.   

    明白了吧,呵呵,其实property就是你add的第一个参数名
      

  5.   

    你使用调试单步跟踪一下,看这个错误放到errors里没有
      

  6.   

    有放进去啊
    而且我试了<html:messages id="errormesg" property="errormesg"/>   也不行
      

  7.   

    将 new ActionMessage 换成 new ActionError试一试
      

  8.   

    或者直接在页面使用<html:messages id="errormesg"/>
      

  9.   


    我参照了一本书改了一下,现在就是说在actionform中有
    errors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("没有选择列为group by"));
    return errors;
    上面的没错,我调试了发现错误有存入errors然而在jsp页面中我这么写]<html:messages id="errormesg" message="true">
    <bean:write name="errormesg"/>
    </html:messages>却不显示
      

  10.   

    <html:errors/>这样就可以,
    如果要具体的话可以<html:error name="xxx"/>
    就好了,<bean write>当然是不行的了
    祝你好运啊
      

  11.   

    actionform中
    errors.add(ActionErrors.GLOBAL_MESSAGE,new ActionMessage("没有选择列为group by"));
                            return errors;
    页面中
    <html:errors/>
    还是不显示是不是<html:errors/>要放在form里面还是什么的?