龍行天下

            政 博
          隨筆 - 23, 文章 - 0, 評論 - 12, 引用 - 0
          數據加載中……

          Hibernate查詢解決方案

               摘要: 第一部分: Hibernate 提供的查詢接口或其方法 (此部分不做深究,請參考 hibernate 手冊) ????? ?????? 1 。...  閱讀全文

          posted @ 2006-05-03 20:03 feingto 閱讀(429) | 評論 (0)編輯 收藏

          struts在URI后面傳參數的問題

          在struts標簽<html:link>的page屬性指定的URI后面傳遞參數可以有幾種方式:
          1.若明確參數名和參數值則直接在URI后輸出,
          如:<html:link page="/test.do?action=add">add</html:link>

          2.對于參數值不確定的,paramName和paramProperty來輸出,用paramId屬性指定參數名。
          對于paramName指定的對象應該存在于page、request、session、application其中之一。一般來說,是從Action類傳過來的,作為request的屬性之一(requst.setAttribute("name",object))。
          如果paramName指定的對象是action的ActionForm,則無需使用request.setAttribute方法。
          例:<html:link page="/test.do" paramId="userid" paramName="uid">uname</html:link>
          若參數值是一個bean對象的屬性值(比如ActionForm,或者集合中存放的對象)則:
          <html:link page="/test.do" paramId="userid" paramName="user" paramProperty="uid">uname</html:link>

          3.若兩個參數,一個確定一個不確定,則是以上兩種方法的結合,即:
          <html:link page="/test.do?action=modify" paramId="userid" paramName="uid">modify</html:link>

          4.對于多個參數的問題,可以使用一個HashMap集合對象來存放所有的參數名及對應的參數值的方式,paramName屬性值指定為該HashMap集合對象即可。
          舉例:
          <%
          //代碼理想的位置應該是在action中
          //可以在jsp頁面測試
          ? java.util.HashMap pms = new java.util.HashMap();
          ? pms.put("code", "001002");
          ? pms.put("name", "tester");
          ? pms.put("alias", new String[]{"matin","jack"});
          ? request.setAttribute("params", pms);
          %>
          <html:link action="/test.do" name="params" >test</html:link>
          編譯后的結果:<a href="/test.do?code=001002&name=tester&alias=matin&alias=jack">test</a>
          這種方式雖然可以解決傳多參數的問題,但是實現起來也比較麻煩,特別是對記錄集中的數據逐條列出的時候

          5.針對有的網友在<html:link>標簽中嵌入使用jsp腳本(scriptlet)的問題,
          例如:
          <html:link page="/test.do?code=<%=varible%>">add</html:link>,這種寫法是錯誤的,是無法編譯的。
          有的網友認為在struts標簽內是不允許使用jsp腳本的,這種說法也不準確。如果前面的寫法改成:
          <html:link page="<%="/test.do?code="+varible%>">add</html:link>,就可以被執行,但是要注意URL相對路徑的問題。

          雖然在struts標簽中嵌入jsp腳本不是真正意義上的struts應用,但是有時在委曲求全的情況下也只能如此了,除非使用自定義標簽。比如在form表單中可能需要根據具體數據讓某個字段是只讀的,就可以用嵌入jsp腳本來實現:
          <%
          boolean rdonly=false;
          if(2==2) rdonly=true;
          %>
          <html:text property="userid" readonly="<%=rdonly%>" />


          6.另外一種比較變態的方法,既不是真正意義上的struts,也不符合xml規范。那就是在<a>標簽中用<bean:write>標簽輸出參數值。
          如:<a href="test.do?uid=<bean:write name="user" property="userid"/>&name=<bean:write name="user" property="username"/>">test</a>

          posted @ 2006-05-03 20:02 feingto 閱讀(888) | 評論 (0)編輯 收藏

          struts錯誤和信息的處理

          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 @ 2006-05-03 20:02 feingto 閱讀(1036) | 評論 (0)編輯 收藏

          僅列出標題
          共3頁: 上一頁 1 2 3 
          主站蜘蛛池模板: 花莲县| 珠海市| 英吉沙县| 登封市| 吴江市| 揭东县| 宜兰县| 察隅县| 武冈市| 甘洛县| 运城市| 马山县| 庆云县| 大渡口区| 隆子县| 锡林浩特市| 沿河| 金塔县| 奇台县| 琼结县| 栖霞市| 马公市| 亚东县| 宜春市| 区。| 锦屏县| 来凤县| 扎鲁特旗| 海城市| 巴南区| 敖汉旗| 永州市| 中西区| 淮北市| 秀山| 商都县| 乌兰浩特市| 武鸣县| 岳池县| 龙州县| 永平县|