在form 中的Validate()方法中return了ActionErrors,如何在jsp页面中获取这个异常,不使用<html:errors>等标签,就用代码获取错误信息。希大虾们赐教。

解决方案 »

  1.   

    Java代码 
    <!--exception-type设定处理那种异常或子类,location设定捕获到该异常后转向去哪里-->   
        <error-page>   
            <exception-type>org.xiaohanne.simplemvc.exception.ErrorPageException</exception-type>   
            <location>/error/error.jsp</location>   
        </error-page>  <!--exception-type设定处理那种异常或子类,location设定捕获到该异常后转向去哪里-->
        <error-page>
         <exception-type>org.xiaohanne.simplemvc.exception.ErrorPageException</exception-type>
         <location>/error/error.jsp</location>
        </error-page>error.jsp 这个页面因为isErrorPage="true"所以能取默认的exception 
    Java代码 
    <%@page contentType = "text/html;charset=gb2312" %>   
    <%@page isErrorPage="true"%>   
    <html>   
    <head>   
    <title>错误处理</title>   
    <meta http-equiv="Expires" content="">   
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">   
    <link rel="stylesheet" href="css.css">   
    <body color=#FF0000>   
    <br><br><br>   
    <table width="400" bgcolor=#EEEEFF align=center border="0" cellspacing="0" cellpadding="0">   
      <tr class=th height=22><td colspan=10>&错误提示</td></tr>   
      <tr bgcolor=#CCCCEE height=1><td colspan=10></td></tr>   
      <tr>   
        <td width=30 rowspan="4">&</td>   
        <td>   
             <font color=#0000FF><font color="#0000FF">错误信息为:<%=exception.getMessage();%>   
           <%--根据配置文件或url参数决定是否显示--%>           
            <%String sIsDebug=request.getParameter("debug");;    
            if(sIsDebug==null||sIsDebug.equals("");); sIsDebug="false";   
            if(org.xiaohanne.simplemvc.config.Configurator.isDebug();||sIsDebug.equals("true"););{%>   
              <hr>    
              错误详细信息(供管理人员调试);:<%=exception.toString();%>    
              <hr>    
              错误堆栈(供管理人员调试);:<br><%=((org.xiaohanne.simplemvc.exception.ErrorPageException);exception);.toTrace();%>           
            <%}%>   
            </font></font>     
        </td>   
        <td height="69">&</td>   
      </tr>   
      <tr height=30 valign=center>    
        <td valign="top" align="right"><a href='javascript:history.go(-1);;'>返回上页</a></td>   
      </tr>   
      <tr bgcolor=#CCCCEE height=1><td colspan=10></td></tr>       
    </table>   
    </body>   
    </html>  
      

  2.   

    在validate()中 把错误提示放进request中, 然后在报错的页面中 使用 ${requestScope.msg?"":requestScope.msg} 来试试。
      

  3.   

    用request或者session保存错误信息,然后在页面上输出,建议用request。
      

  4.   

    public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) {
    // TODO Auto-generated method stub
    String accountNumber=getAccountNumber();
    String password=getPassword();

    ActionErrors errors=new ActionErrors();
    if(accountNumber.equals("")){

    errors.add("ActionErrors.GLOBAL_MESSAGE",new ActionMessage("accountNumber.none"));
    return errors;
    }
    if(password.equals("")){
    errors.add("ActionErrors.GLOBAL_MESSAGE",new ActionMessage("password.none"));
    return errors;

    }
    return null;
    }
    请问怎么从ActionErrors把错误信息取出来?