牛仔褲的夏天

          JAVA是藍(lán)色的- online

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            30 隨筆 :: 5 文章 :: 15 評(píng)論 :: 0 Trackbacks

          #

          在Jdon.com里面看到的,覺(jué)得很值得借鑒
          原文:http://www.jdon.com/jive/thread.jsp?forum=16&thread=302

          看下面比較:

          public List getUsers() 
            ResultSet rs 
          = userDbQuery();
            List retval 
          = new ArrayList();
            
          while (rs.next()) {
              retval.add(rs.getString(
          1));
            }

            
          return retval;
          }
          上面是個(gè)我們采取返回Collection后最常用的方法,將ResultSet中的用戶名加入List再返回,顯然這很耗費(fèi)內(nèi)存。

          使用Iterator返回:
          public Iterator getUsers() {
            
          final ResultSet rs = userDbQuery();
              
          return new Iterator() {
                
          private Object next;
                
          public void hasNext() {
                  
          if (next == null{
                    
          if (! rs.next()) {
                      
          return false
                    }
           
                    next 
          = rs.getString(1);
                  }

                  
          return true;
                }


                
          public Object next() {
                  
          if (! hasNext()) {
                    
          throw new NoSuchElementException();
                  }

                  String retval 
          = next;
                  next 
          = null;
                  
          return retval;
                }


                
          public void remove() {
                  
          throw new UnsupportedOperationException ("no remove allowed");
                }

             }

          }

          這個(gè)Javabean只是做了一個(gè)指針傳遞作用,將調(diào)用本Javabean的指針傳遞到ResultSet,這樣既提高了效率,節(jié)約了內(nèi)存,又降低了偶合性,這是堪稱中間件典型的示范。


          posted @ 2006-03-15 16:56 luckyrobbie 閱讀(5454) | 評(píng)論 (6)編輯 收藏

          今天貝貝在家休息一天,沒(méi)有去幼兒園
          下午我打電話到父母家,我爸爸說(shuō)了幾句后把電話給了貝貝
          和貝貝聊了一會(huì)后
          我:讓奶奶接電話
          貝貝:媽媽剛才也讓奶奶接電話的
          我:快點(diǎn)
          貝貝:不行
          我:那讓爺爺接電話
          貝貝:也不可以
          我:為什么
          貝貝:只允許貝貝接電話
          ...
          ...
          我:快點(diǎn)呀,讓爺爺奶奶接電話
          貝貝:byebye~~~
          最后竟然把電話掛了。

          posted @ 2006-03-13 22:51 luckyrobbie 閱讀(256) | 評(píng)論 (0)編輯 收藏

               摘要: 單位里的查詢系統(tǒng)是基于struts的,在結(jié)果集顯示的處理上都是用 <logic:iterate id=".." indexId="id" name=".." scope="request"> 然后在<bean:write name=".." property=".."> 這樣子對(duì)付的,后來(lái)覺(jué)得比較麻煩,就寫了一個(gè)顯示結(jié)果集的標(biāo)簽 行記錄用HashMap保存 ...  閱讀全文
          posted @ 2006-03-10 13:12 luckyrobbie 閱讀(1164) | 評(píng)論 (1)編輯 收藏

          http://www.w3schools.com/xpath/default.asp

          http://www.zvon.org/xxl/XPathTutorial/General/examples.html
          posted @ 2006-03-09 13:20 luckyrobbie 閱讀(371) | 評(píng)論 (3)編輯 收藏

          When to use DOM

          If your XML documents contain document data (e.g., Framemaker documents stored in XML format), then DOM is a completely natural fit for your solution. If you are creating some sort of document information management system, then you will probably have to deal with a lot of document data. An example of this is the Datachannel RIO product, which can index and organize information that comes from all kinds of document sources (like Word and Excel files). In this case, DOM is well suited to allow programs access to information stored in these documents.

          However, if you are dealing mostly with structured data (the equivalent of serialized Java objects in XML) DOM is not the best choice. That is when SAX might be a better fit.

          When to use SAX

          If the information stored in your XML documents is machine readable (and generated) data then SAX is the right API for giving your programs access to this information. Machine readable and generated data include things like:

          • Java object properties stored in XML format
          • queries that are formulated using some kind of text based query language (SQL, XQL, OQL)
          • result sets that are generated based on queries (this might include data in relational database tables encoded into XML).

          So machine generated data is information that you normally have to create data structures and classes for in Java. A simple example is the address book which contains information about persons, as shown in Figure 1. This address book XML file is not like a word processor document, rather it is a document that contains pure data, which has been encoded into text using XML.

          When your data is of this kind, you have to create your own data structures and classes (object models) anyway in order to manage, manipulate and persist this data. SAX allows you to quickly create a handler class which can create instances of your object models based on the data stored in your XML documents. An example is a SAX document handler that reads an XML document that contains my address book and creates an AddressBook class that can be used to access this information. The first SAX tutorial shows you how to do this. The address book XML document contains person elements, which contain name and email elements. My AddressBook object model contains the following classes:

          • AddressBook class, which is a container for Person objects
          • Person class, which is a container for name and email String objects.

          So my "SAX address book document handler" is responsible for turning person elements into Person objects, and then storing them all in an AddressBook object. This document handler turns the name and email elements into String objects.

          Conclusion

          The SAX document handler you write does element to object mapping. If your information is structured in a way that makes it easy to create this mapping you should use the SAX API. On the other hand, if your data is much better represented as a tree then you should use DOM.

          posted @ 2006-02-22 21:52 luckyrobbie 閱讀(203) | 評(píng)論 (0)編輯 收藏

          參考原文地址 http://homepage.mac.com/edahand/projects/java/example1.html

          1  在E盤建立一個(gè)目錄sandh, 然后把那個(gè)空的struts-blank.war解壓到這下面作為struts模板,把hibernate3.1里面的jar文件拷貝到/sandh/web-inf/lib下面,ehcache.xml拷貝到/sand/web-inf/src/java下面。

          2  在tomcat下配置datasource命名為jdbc/aix,然后建立一個(gè)新的context名字為sand,在sand下建一個(gè)新的資源連接jdbc/aix,作為hibernate.cfg.xml中hibernate.connection.datasouce引用值。

          3  在sybase中新建一個(gè)表item

          create table dbo.item (
          id  numeric(
          180)  identity,
          name    varchar(
          32) not null,
          description text    
          null,
          constraint PK_ITEM PRIMARY KEY  NONCLUSTERED ( id )
          )


          4  在/sandh/web-inf/src/java下面建立以下文件
          log4j.properties 
          hibernate.cfg.xml
          Item.hbm.xml
          HibernateUtil.java
          Item.java
          AddItemAction.java
          ItemService.java

          在/sandh/web-inf/src下面新建build.xml文件,然后ant compile。
          在/sandh/pages下新建AddItem.jsp文件

          5   修改/sandh/web-inf/struts-config.xml文件,內(nèi)容如下:

          <struts-config>
              
          <form-beans>
                  
          <form-bean name="addItemForm" 
                             type
          ="org.apache.struts.validator.DynaValidatorForm">
                             
          <form-property name="name" type="java.lang.String"/>
                             
          <form-property name="description" type="java.lang.String"/>
                  
          </form-bean>
              
          </form-beans>

              
          <global-forwards>
                  
          <forward name="welcome" path="/items.do"/>
              
          </global-forwards>
              
              
          <action-mappings>
                  
          <action
                  path
          ="/items"
                  type
          ="org.apache.struts.actions.ForwardAction"
                  parameter
          ="/pages/AddItem.jsp"/>
               
                  
          <action
                     path
          ="/addItem"
                     type
          ="com.fan.hibernate.AddItemAction"
                     name
          ="addItemForm"
                     scope
          ="request"
                     validate
          ="true"
                     input
          ="/pages/AddItem.jsp">
                     
          <forward name="success" path="/pages/AddItem.jsp" />
                   
          </action>
              
          </action-mappings>
              
              
          <message-resources parameter="MessageResources" null="false"/>
              
              
          <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
                 
          <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
              
          </plug-in>    
          </struts-config>



          修改/sandh/web-inf/validation.xml文件,為addItemForm增加動(dòng)態(tài)驗(yàn)證,內(nèi)容如下:

              <formset>
                  
          <form name="addItemForm">
                      
          <field property="name" depends="required">
                          
          <arg key="name" resource="false"/>
                      
          </field>
                      
          <field property="description" depends="required">
                              
          <arg key="description" resource="false"/>
                      
          </field>
                  
          </form>
              
          </formset>


          6   在tomcat下面測(cè)試一下吧。http://127.0.0.1:8080/sand

          7   測(cè)試的時(shí)候發(fā)現(xiàn)2個(gè)問(wèn)題:
          首先,如果在/sandh/web-inf/classes下面沒(méi)有ehcache.xml這個(gè)文件,會(huì)報(bào)這個(gè)錯(cuò)誤,
          No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath:.....這個(gè)文件是hibernate緩存配置文件,以后在學(xué)習(xí)。
          另外在log文件中一直發(fā)現(xiàn)這個(gè)警告:Could not bind factory to JNDI javax.naming.NamingException: Context is read only..... 網(wǎng)上查找后發(fā)現(xiàn)只要在hibernate.cfg.xml文件的<session-factory name="java:/hibernate/HibernateFactory"> 中把name=....去掉就好了,否則會(huì)自動(dòng)把name注冊(cè)進(jìn)jndi中失敗而發(fā)出警告。

          8   所有文件打包在這里
          http://www.aygfsteel.com/Files/luckyrobbie/sandh.rar 里面lib下面的文件自己添進(jìn)去吧。



          posted @ 2006-01-26 10:49 luckyrobbie 閱讀(814) | 評(píng)論 (0)編輯 收藏

          昨晚帶貝貝去大統(tǒng)華玩,買了幾本書(shū)和吃的東西,比較開(kāi)心的樣子。
          “貝貝,晚上和誰(shuí)睡覺(jué)?”
          “爸爸”
          “一定嗎”
          “一定”
          “如果騙人的話你是什么”
          “小豬”
          “那我們拉勾”
          “不”
          怎么也不肯和我拉勾,看來(lái)還是騙人的
          posted @ 2006-01-24 08:44 luckyrobbie 閱讀(636) | 評(píng)論 (0)編輯 收藏

          昨天是星期天,早上我睡懶覺(jué)起床后貝貝和媽媽已經(jīng)出去玩了,發(fā)現(xiàn)電腦桌上有幾顆魚(yú)皮花生米,那是我買給貝貝吃的椰子味的花生米。心想:是不是留給我吃的啊^^

          中午在父母家吃飯,我問(wèn)老婆,是不是貝貝特意留了給我的?老婆說(shuō),別美了,肯定是他放在桌子上忘記了。于是我問(wèn)貝貝:是否留給爸爸吃的呀?貝貝答:是的。我繼續(xù)問(wèn):你當(dāng)時(shí)是怎么想的啊?貝貝答:我當(dāng)時(shí)想爸爸也喜歡吃的,于是留給你的。

          呵呵,不管是真是假,心里美滋滋的。

          晚上,貝貝拿著玩具手機(jī)打電話給老師,編了幾句后,我問(wèn)他老師說(shuō)什么了。他說(shuō):陸老師明天帶我到##飯店去吃飯的。
          “帶爸爸去嗎?”
          “不帶”
          “帶媽媽去嗎?”
          “不帶”
          “那你一個(gè)人怎么過(guò)去呢?” 我問(wèn)。
          于是貝貝又打了一個(gè)電話,說(shuō)“陸老師明天來(lái)接我去吃飯的”

          posted @ 2006-01-16 14:49 luckyrobbie 閱讀(346) | 評(píng)論 (0)編輯 收藏

          今天看了一個(gè)別人的帖子才發(fā)現(xiàn)剛剛做的項(xiàng)目里面存在一些畫(huà)蛇添足的實(shí)現(xiàn)方法。

          在action處理完控制邏輯后,把dto處理結(jié)果扔給顯示層表示后,在顯示層里面如果要顯示一些在ActionForm中的property,本來(lái)是通過(guò)在action中用request.setAttribute(..)傳遞的,其實(shí)沒(méi)這個(gè)必要。

          Action處理完畢后,本來(lái)傳遞給action的form在request域里面是依舊存在的,所以在輸出的顯示頁(yè)面上只要用<bean:write name="actionformname" property="field" scope="request"/> 就ok了。

          打個(gè)哈欠,以前寫的代碼也懶得去改了,反正也沒(méi)多大的不適,嘿嘿

          468c05860200005t.jpg
          posted @ 2005-12-15 16:16 luckyrobbie 閱讀(371) | 評(píng)論 (0)編輯 收藏

          public ?ActionForward?execute(ActionMapping?mapping,?ActionForm?form,
          ???HttpServletRequest?request,?HttpServletResponse?response)
          {

          // ***********

          ??DynaValidatorForm?f
          = (DynaValidatorForm)?form;

          ??String?a
          = (String)?f.get( " A " );???

          ??String?b
          = (String)?f.get( " B " );???

          // ***********

          }

          對(duì)于上面的actionform的傳遞,本來(lái)以為一定要通過(guò)提交<html:form.../>才能接收的,后來(lái)發(fā)現(xiàn)其實(shí)通過(guò)參數(shù)的傳遞也可以實(shí)現(xiàn)。

          例如上面的actionform, 如果有2個(gè)field, 分別是A和B, 如果不通過(guò)提交form的方法,直接用帶參數(shù)的連接表示, 那么通過(guò)這個(gè)做法也可以正確的用f.get(..)方法得到數(shù)值.?

          http://localhost:8080/app/myaction.do?A=abc&B=def

          由此可見(jiàn),如果分別3個(gè)頁(yè)面page a, page b and page c. page a中有一個(gè)form, 提交后產(chǎn)生page b, 對(duì)page b中的鏈接提交后產(chǎn)生page c. 那么page b 和 page c 可以通過(guò)一個(gè)action來(lái)實(shí)現(xiàn), 只要保證page b中關(guān)于action的連接后面加的參數(shù)名字和actionform的field名字一致就可以了。

          468c05860200007v.jpg

          posted @ 2005-12-13 21:52 luckyrobbie 閱讀(620) | 評(píng)論 (0)編輯 收藏

          僅列出標(biāo)題
          共3頁(yè): 上一頁(yè) 1 2 3 
          主站蜘蛛池模板: 陵水| 鄯善县| 靖江市| 灵台县| 会昌县| 玛多县| 启东市| 闻喜县| 无为县| 抚远县| 绥滨县| 疏附县| 颍上县| 富阳市| 巴楚县| 安丘市| 灵丘县| 梁平县| 明溪县| 华亭县| 新密市| 都昌县| 离岛区| 大宁县| 泰和县| 乐陵市| 平安县| 行唐县| 绥滨县| 柘荣县| 邵东县| 伽师县| 文昌市| 嘉黎县| 肃北| 玉门市| 新兴县| 商城县| 临清市| 灵寿县| 新宁县|