Cool eye

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            63 Posts :: 4 Stories :: 3 Comments :: 0 Trackbacks

          1.錯誤和信息的處理.

          首先在資源文件中定義錯誤信息和普通信息.如:MessageResources.properties中定義如下:
          java代碼: 


          #
          # Resources for testing <html:errors> tag.
          #

          errors.header=<table>
          errors.footer=</table>
          errors.prefix=<tr><td>
          errors.suffix=</td></tr>

          property1error1=Property 1, Error 1
          property2error1=Property 2, Error 1
          property2error2=Property 2, Error 2
          property2error3=Property 2, Error 3
          property3error1=Property 3, Error 1
          property3error2=Property 3, Error 2
          globalError=Global Error

          #
          # Resources for testing <html:messages> tag.
          #

          messages.header=<table>
          messages.footer=</table>

          property1message1=Property 1, Message 1
          property2message1=Property 2, Message 1
          property2message2=Property 2, Message 2
          property2message3=Property 2, Message 3
          property3message1=Property 3, Message 1
          property3message2=Property 3, Message 2
          globalMessage=Global Message



          在程序中定義錯誤和信息類,這個例子寫在JSP中

          java代碼: 


          <%
                ActionErrors errors = new ActionErrors();
                errors.add("property1", new ActionError("property1error1"));
                errors.add("property2", new ActionError("property2error1"));
                errors.add("property2", new ActionError("property2error2"));
                errors.add("property2", new ActionError("property2error3"));
                errors.add("property3", new ActionError("property3error1"));
                errors.add("property3", new ActionError("property3error2"));
                errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("globalError"));
                request.setAttribute(Globals.ERROR_KEY, errors);

                ActionMessages messages = new ActionMessages();
                messages.add("property1", new ActionMessage("property1message1"));
                messages.add("property2", new ActionMessage("property2message1"));
                messages.add("property2", new ActionMessage("property2message2"));
                messages.add("property2", new ActionMessage("property2message3"));
                messages.add("property3", new ActionMessage("property3message1"));
                messages.add("property3", new ActionMessage("property3message2"));
                messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("globalMessage"));
                request.setAttribute(Globals.MESSAGE_KEY, messages);
              %>





          顯示錯誤:
          java代碼: 


          <html:errors property="property1" />
          <html:errors property="property2" />


          顯示信息:
          java代碼: 


          <html:messages property="property1" message="true" id="msg" header="messages.header" footer="messages.footer">
                      <tr>
                        <td>
                               <%= pageContext.getAttribute("msg") %>
                        </td>
                      </tr>
                    </html:messages>

          <html:messages message="true" id="msg" header="messages.header" footer="messages.footer">
                      <tr>
                        <td>
                         <%= pageContext.getAttribute("msg") %>
                        </td>
                      </tr>
          </html:messages>

          posted on 2006-02-13 11:04 joeyeezhang 閱讀(312) 評論(0)  編輯  收藏 所屬分類: Struts

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 潞西市| 玛纳斯县| 盘锦市| 南充市| 读书| 瑞昌市| 沿河| 阿拉善盟| 扎赉特旗| 德令哈市| 缙云县| 万宁市| 大冶市| 醴陵市| 松江区| 奉新县| 青阳县| 视频| 博客| 绥阳县| 河南省| 龙岩市| 临夏县| 鲁甸县| 荣成市| 阿克苏市| 隆安县| 磐石市| 华蓥市| 黄骅市| 潼南县| 红桥区| 亳州市| 曲靖市| 盐城市| 五华县| 自贡市| 青川县| 子洲县| 六枝特区| 普定县|