struts <hrml :errors>用法

<html:errors>标签用来在网页上输出错误消息。

1.是struts1.1

<span style="font-family:Verdana;color:#cc0066;"><span style="color:#000000;"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title><span style="font-family:Verdana;">test</span></title>
    
       </head>
      <body>

        <html:form action="/loginAction" >
            <html:hidden property="actionType" value="<span style="font-family:Verdana;">query</span>"/>
         
            <table width="100%"  height="100%" border="0" cellspacing="0" cellpadding="0">
              </span></span><pre name="code" class="javascript">                                                               <tr>
                                                                    <td width="40" height="50"><img src="public/resources/localIm/login/user.gif" width="30" height="30"></td>
                                                                    <td width="38" height="50">用户</td>
                                                                    <td width="242" height="50"><input tabindex="1" οnkeydοwn="clickenter()" type="text" name="username" id="username" style="width:164px; height:32px; line-height:34px; background:url(public/resources/localIm/login/inputbg.gif) repeat-x; border:solid 1px #d1d1d1; font-size:9pt; font-family:Verdana, Geneva, sans-serif;"></td>
                                                                </tr>
                                                                <tr>
                                                                    <td height="50"><img src="public/resources/localIm/login/password.gif" width="28" height="32"></td>
                                                                    <td height="50">密码</td>
                                                                    <td height="50"><input tabindex="2" οnkeydοwn="if(event.keyCode==13){document.forms[0].submit();return false;}" type="password" name="userpaw" id="userpaw" style="width:164px; height:32px; line-height:34px; background:url(public/resources/localIm/login/inputbg.gif) repeat-x; border:solid 1px #d1d1d1; font-size:9pt; "></td>
                                                                </tr>
                                                                <tr>
                                                                    <td height="40"> </td>
                                                                    <td height="40"> </td>
                                                                    <td height="60"><img src="public/resources/localIm/login/login.gif" width="95" height="34" οnclick="document.forms[0].submit();return false;"></td>
                                                                </tr>
                                                                <tr><td colspan="3" height="30"><strong><span style="color:#CC0000;"><html:errors/></span></strong></td></tr>
</table> </html:form> <script type="text/javascript"> document.getElementById("username").focus(); </script> </body></html>
 

<span style="font-family:Verdana;color:#cc0066;"><span style="color:#000000;">	ActionErrors errors = new ActionErrors();
		errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(messageCode));
		saveErrors(request, errors);
</span></span>

在Action类中提供了一个saveErrors()方法,可以将ActionErrors对象存入request中。通过这个方法<html:errors>标签可以在request中找到它并将其显示在网页上。

<html;errors>标记可以放在网页上的任何位置,它有以下三个比较重要的属性:

name属性:它指定了存放在request或session属性中的错误对象的值。我们知道,在request或session中,对象的存储一般都以键/值对的方式来进行。ActionErrors对象在request或session中的key默认为Globals.ERROR_KEY。

property属性:用于指定与ActionError对应的key值;

bundle属性:用于指定资源文件,即显示ActionErrors信息时去哪个资源文件中读取相应的消息文本。


2.struts1.2

在2005年Apache正式推出Struts 1.2后,有许多东西已经被改变。其中很重要的一个改动就是与<html:errors>标记相关的改动,主要就是已经不再推荐使用ActionError类和ActionErrors类,因此,如果要将现有的使用到与<html:errors>标记相关的代码从Struts 1.1下移至Struts 1.2下,需要作以下改动。

1. 将代码中使用到ActionError类的地方换为ActionMessage类。

2. 将除了在ActionForm的validate()方法以外使用到ActionErrors类的地方都替换为ActionMessages。

这样做的主要原因是,ActionError是ActionMessage的子类,而ActionErrors是ActionMessages的子类

用法:

只需将 ActionErrors 改为:  ActionMessage



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值