<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    云自無心水自閑

    天平山上白云泉,云自無心水自閑。何必奔沖山下去,更添波浪向人間!
    posts - 288, comments - 524, trackbacks - 0, articles - 6
      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

     

    public String getFormatedDateString(int timeZoneOffset)
            
    if (timeZoneOffset > 13 || timeZoneOffset < -12{
                logger.error(
    "Configuration item TimeZone " + timeZoneString + " is invalid.");
                timeZoneOffset 
    = 0;
            }

            TimeZone timeZone;

            String[] ids 
    = TimeZone.getAvailableIDs(timeZoneOffset * 60 * 60 * 1000);
            
    if (ids.length == 0{
                
    // if no ids were returned, something is wrong. use default TimeZone
                timeZone = TimeZone.getDefault();
            }
     else {
                timeZone 
    = new SimpleTimeZone(timeZoneOffset * 60 * 60 * 1000, ids[0]);
            }


            SimpleDateFormat sdf 
    = new SimpleDateFormat("yyyyMMddHHmmss");
            sdf.setTimeZone(timeZone);

            
    return sdf.format(newDate);
        }

    其中timeZoneOffset就是時區(qū),比如東八區(qū),就傳入8,西二區(qū)就傳入-2

    新的方法,使用指定的TimeZone ID來獲得TimeZone,這樣更精確,因為有一些城市,雖然時區(qū)。比如:悉尼和布里斯班,都是東10區(qū),但是悉尼實行夏令時,所以夏天的時候,悉尼要比布里斯班早1小時。

            TimeZone timeZoneSYD = TimeZone.getTimeZone("Australia/Sydney");
            TimeZone timeZoneBNE = TimeZone.getTimeZone("Australia/Brisbane");
           
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sdf.setTimeZone(timeZoneSYD);
            Date date = new Date();
            System.out.println(sdf.format(date));
           
            sdf.setTimeZone(timeZoneBNE);
            System.out.println(sdf.format(date));

    其中TimeZone的ID列表,可以使用函數(shù)
        public static String[] TimeZone.getAvailableIDs();
    來獲得

     


    posted @ 2008-02-07 07:04 云自無心水自閑 閱讀(1573) | 評論 (0)編輯 收藏


    File[] filesWanted = dir.listFiles(
        new FilenameFilter() {
            public boolean accept(File dir, String name) {
                return name.endsWith(".html") || name.endsWith(".htm");
            }
        });

    posted @ 2008-02-06 09:43 云自無心水自閑 閱讀(456) | 評論 (0)編輯 收藏

    <%@ taglib prefix="s" uri="/struts-tags"%>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        
    <head>
            
    <s:head />
        
    </head>

        
    <body>

            
    <table border="1">
                
    <s:iterator value="dataMap.keySet()" id="class">
                    
    <s:iterator value="dataMap.get(#class).keySet()" id="group">
                    
    <tr>
                        
    <td><s:property value="group"/></td>
                        
    <s:iterator value="dataMap.get(#class).get(#group).values()" id="name">
                            
    <td><s:property value="name"/></td>
                        
    </s:iterator>
                    
    </tr>
                    
    </s:iterator>
                
    </s:iterator>
            
    </table>
        
    </body>
    </html>

    posted @ 2008-01-25 13:16 云自無心水自閑 閱讀(15319) | 評論 (10)編輯 收藏

    在Struts2中,radio標(biāo)簽可以使用一個list來輸出一組radio按鈕,
            <s:radio name="sex" list="#{'male','female'}" label="%{getText('app.label.sex')}" />
    但是如何設(shè)置其中一個被默認(rèn)選中。

    查閱了struts2的文檔,發(fā)現(xiàn)radio標(biāo)簽有一個value屬性是用于對radio的進(jìn)行預(yù)選的: http://struts.apache.org/2.x/docs/radio.html
    value: Preset the value of input element.
    于是,進(jìn)行了試驗,<s:radio name="sex" list="#{'male','female'}" label="%{getText('app.label.sex')}" value="male" />
    結(jié)果失敗了。male的值并沒有被選中,經(jīng)過反復(fù)研究,終于得到了正確的結(jié)果:
    <s:radio name="sex" list="#{'male','female'}" label="%{getText('app.label.sex')}" value="'male'" />
    看到其中的區(qū)別了嗎,就是多了兩個單引號。
    我認(rèn)為這是因為value屬性的特性引起的。如果male沒有加引號,那么struts2會去值的堆棧中尋找變量名為male的值,結(jié)果找不到。
    加上單引號后,struts2(應(yīng)該是ognl)把'male'認(rèn)為是一個簡單的字符串。

    這樣,radio就能夠正確地匹配到值,使指定的值默認(rèn)被選中

    posted @ 2008-01-24 22:06 云自無心水自閑 閱讀(7071) | 評論 (7)編輯 收藏


    在iBatis中,對于in子句的標(biāo)準(zhǔn)做法是采用動態(tài)sql來解決的。具體方法大致是:Java代碼傳入一個List或者數(shù)組,然后在sqlMapConfig映射中使用iterate循環(huán)取這個變量,動態(tài)地生成sql語句。
    這個標(biāo)準(zhǔn)解法的缺點是,使用起來比較麻煩
    1. 需要在sqlMapConfig中使用動態(tài)語句
    2. 需要傳入一個Iterable的變量
    對于這個問題,我使用了一個偷懶的辦法,就是使用$標(biāo)記。
    在iBatis中,普通的變量,比如:v,是使用#號,在這個例子中,就是:#v#。
    這樣,iBatis會使用prepareStatement,并對變量進(jìn)行變量綁定。
    而$符號是簡單替代的用法,在數(shù)據(jù)庫的執(zhí)行效率上要比前一種差。但優(yōu)點就是簡單方便。
    比如:
    SELECT * FROM  emp WHERE emp_no in ($empString$);
    而empString的值就是1, 2, 3. 在Log中,可以看到,Sql語句就是:SELECT * FROM emp WHERE emp_no in (1,2,3)

    posted @ 2008-01-02 20:48 云自無心水自閑 閱讀(8588) | 評論 (3)編輯 收藏

    dhtmlXTree的節(jié)點定義可以從服務(wù)器生成的Xml中動態(tài)加載,我目前使用的是Struts2. 因此,我的做法是,在Javascript生成dhtmlxTree的時候,請求一個加載Struts2的action,Struts2的Action進(jìn)行用戶權(quán)限認(rèn)證,動態(tài)生成菜單的Xml字符串。而在jsp中只輸出這一個字符串。
    開始進(jìn)行的都比較順利,但是客戶端和服務(wù)端一連起來就出問題,頁面在加載Xml的時候總是彈出一個對話框,說是加載的xml格式不正確。但是我在IE中直接輸入Action,頁面顯示的結(jié)果十分正確,沒有問題。后來,無意中我查看了返回xml頁面的源文件,這才發(fā)現(xiàn)了問題。
    原來,xml的<和>全都被轉(zhuǎn)換成&lt;和&gt;了。
    我一開始是想在后臺考慮如何對字符串進(jìn)行轉(zhuǎn)換,后來在查struts2文檔的時候發(fā)現(xiàn),<s:property有一個escape屬性,可以完美地解決這個問題,<s:property value="menuXmlString" escape="false"/>

    例子已經(jīng)整理出來了:http://www.tkk7.com/usherlight/archive/2008/08/07/220756.html

    posted @ 2007-12-14 21:14 云自無心水自閑 閱讀(5446) | 評論 (6)編輯 收藏

    最近在網(wǎng)上搜索網(wǎng)頁上的樹形菜單的開源項目,發(fā)現(xiàn)有一個dhtmlx公司做的挺好的。
    dhtmlx.com
    其組件包括:
     dhtmlxTree    dhtmlxTabbar
     dhtmlxGrid    dhtmlxCombo
     dhtmlxTreeGrid   dhtmlxVault
     dhtmlxMenu   dhtmlxToolbar

    界面做得相當(dāng)漂亮,在Live Demo中有3種Theme可以選擇。
    功能也相當(dāng)出色:可以拖放樹中的節(jié)點、動態(tài)改變節(jié)點的Icon,定義節(jié)點事件。
    可以動態(tài)地從Xml中加載菜單的結(jié)構(gòu)定義
    節(jié)點可編輯
    可使用鍵盤瀏覽樹
    樹節(jié)點可帶checkbox

    • Multibrowser/Multiplatform support
    • XHTML compatible
    • Loading from XML or Javascript
    • Async mode loading support
    • Editable Items
    • Keyboard navigation
    • Multiselect
    • Drag-&-drop (within one tree, between trees)
    • Right-to-left languages support (RTL)
    • Full controll with JavaScript API
    • Dynamic Loading for big trees
    • Distributed Loading for big levels
    • Smart XML Parsing for big trees
    • Serialization to XML


  • Customizable drag-&-drop to/from dhtmlxGrid
  • Copy with drag-n-drop
  • Drop-between/drop-inside
  • Checkboxes (two/three states, disabled/hidden, radio)
  • Customizable View
  • Unlimited User-data for nodes
  • ASP.NET custom server control
  • JSP custom tag
  • Macromedia Cold Fusion support
  • Detailed documentation
  • posted @ 2007-12-11 19:38 云自無心水自閑 閱讀(2690) | 評論 (4)編輯 收藏


    網(wǎng)上介紹使用zipInStream和zipOutStream對文件或者文件夾進(jìn)行壓縮和解壓縮的文章比較多。
    但是這次項目中需要對byte[]進(jìn)行壓縮,然后decode,通過http發(fā)送到服務(wù)端。

    最簡單的方法,當(dāng)然是把byte[]寫到文件里,然后根據(jù)網(wǎng)上已有的文章,生成fileInputStream,構(gòu)造zipInStream。
    但是這個做法有著明顯的問題,需要操作IO,在效率上不可取。

    下面是利用ByteArrayOutStream來完成壓縮和解壓縮的代碼。



       
    /**
         * Answer a byte array compressed in the Zip format from bytes.
         * 
         * 
    @param bytes
         *            a byte array
         * 
    @param aName
         *            a String the represents a file name
         * 
    @return byte[] compressed bytes
         * 
    @throws IOException
         
    */
        
    public static byte[] zipBytes(byte[] bytes) throws IOException {
            ByteArrayOutputStream tempOStream 
    = null;
            BufferedOutputStream tempBOStream 
    = null;
            ZipOutputStream tempZStream 
    = null;
            ZipEntry tempEntry 
    = null;
            
    byte[] tempBytes = null;

            tempOStream 
    = new ByteArrayOutputStream(bytes.length);
            tempBOStream 
    = new BufferedOutputStream(tempOStream);
            tempZStream 
    = new ZipOutputStream(tempBOStream);
            tempEntry 
    = new ZipEntry(String.valueOf(bytes.length));
            tempEntry.setMethod(ZipEntry.DEFLATED);
            tempEntry.setSize((
    long) bytes.length);
            
            tempZStream.putNextEntry(tempEntry);
            tempZStream.write(bytes, 
    0, bytes.length);
            tempZStream.flush();
            tempBOStream.flush();
            tempOStream.flush();
            tempZStream.close();
            tempBytes 
    = tempOStream.toByteArray();
            tempOStream.close();
            tempBOStream.close();
            
    return tempBytes;
        }


        
    /**
         * Answer a byte array that has been decompressed from the Zip format.
         * 
         * 
    @param bytes
         *            a byte array of compressed bytes
         * 
    @return byte[] uncompressed bytes
         * 
    @throws IOException
         
    */
        
    public static void unzipBytes(byte[] bytes, OutputStream os) throws IOException {
            ByteArrayInputStream tempIStream 
    = null;
            BufferedInputStream tempBIStream 
    = null;
            ZipInputStream tempZIStream 
    = null;
            ZipEntry tempEntry 
    = null;
            
    long tempDecompressedSize = -1;
            
    byte[] tempUncompressedBuf = null;

            tempIStream 
    = new ByteArrayInputStream(bytes, 0, bytes.length);
            tempBIStream 
    = new BufferedInputStream(tempIStream);
            tempZIStream 
    = new ZipInputStream(tempBIStream);
            tempEntry 
    = tempZIStream.getNextEntry();
            
            
    if (tempEntry != null) {
                tempDecompressedSize 
    = tempEntry.getCompressedSize();
                
    if (tempDecompressedSize < 0) {
                    tempDecompressedSize 
    = Long.parseLong(tempEntry.getName());
                }

                
    int size = (int)tempDecompressedSize;
                tempUncompressedBuf 
    = new byte[size];
                
    int num = 0, count = 0;
                
    while ( true ) {
                    count 
    = tempZIStream.read(tempUncompressedBuf, 0, size - num );
                    num 
    += count;
                    os.write( tempUncompressedBuf, 
    0, count );
                    os.flush();
                    
    if ( num >= size ) break;
                }
            }
            tempZIStream.close();
        }

    posted @ 2007-09-26 10:31 云自無心水自閑 閱讀(4923) | 評論 (2)編輯 收藏

    1. 先寫Controller
    2. Controller將業(yè)務(wù)邏輯委派給Service完成
    3. Service返回一個Domain Object Model
    4. 將Domail Object Model封裝成ModelAndView作為Controller的返回結(jié)果,并賦予View的名稱。
    5. InternalResourceViewResolver根據(jù)View名稱取出對應(yīng)的Jsp文件,創(chuàng)建一個包含前綴和后綴的真正的路徑
    6.  這些定義在spring-servlet.xml文件中
    7. 配置文件:首先要在web.xml中配置ContextLoaderListener,介紹這個的文章非常多
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    8. 在web.xml中加入DispatherServlet的配置
    <servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/app/*</url-pattern>
    </servlet-mapping>
    9. spring會根據(jù)這個servlet的名字(在這里是spring)自動尋找  <名字>-servlet.xml(這里將會是:spring-servlet.xml)
    10. 在spring-servlet.xml中,將service注射給controller

    posted @ 2007-09-22 21:28 云自無心水自閑 閱讀(1751) | 評論 (4)編輯 收藏

    On Sep 4, Matt Raible annouced the release of AppFuse 2.0RC1.
    On Sep 7, Matt Raible uploaded a PDF to appfuse.dev.java.net contains the relevant pages from the wiki that help you develop with AppFuse 2.0.
    And yesterday, Matt Raible uploaded a big package to appfuse.dev.java.net. It included all the dependencies of the appfuse2.0 RC1 needed.

    good job, Matt.

    posted @ 2007-09-17 12:42 云自無心水自閑 閱讀(566) | 評論 (0)編輯 收藏

    僅列出標(biāo)題
    共29頁: First 上一頁 14 15 16 17 18 19 20 21 22 下一頁 Last 
    主站蜘蛛池模板: 无码一区二区三区免费视频| 中文字幕在线免费播放| 久久青草国产免费观看| 免费永久看黄在线观看app| 色噜噜亚洲男人的天堂| 免费一区二区三区在线视频| 国产免费一区二区三区| 国产成人精品免费视频软件| 亚洲人成在久久综合网站| 久9这里精品免费视频| 亚洲人成图片小说网站| 欧洲精品码一区二区三区免费看| 香蕉视频在线观看免费国产婷婷| 成人永久福利免费观看| 精品亚洲AV无码一区二区三区| 久久久久免费看成人影片| 亚洲国产无套无码av电影| 久久免费国产视频| 亚洲国产亚洲综合在线尤物| 野花高清在线观看免费3中文 | 巨胸喷奶水视频www免费视频| JLZZJLZZ亚洲乱熟无码| 两性色午夜视频免费播放| 亚洲成色999久久网站| 欧美好看的免费电影在线观看| 欧美激情综合亚洲一二区| 亚洲精品无码av天堂| 久久免费区一区二区三波多野| ASS亚洲熟妇毛茸茸PICS| 国产精品va无码免费麻豆| 美女被免费网站91色| 亚洲日本乱码一区二区在线二产线| 毛片免费观看的视频在线| 免费精品视频在线| 亚洲色图国产精品| 国产精品无码素人福利免费| 和老外3p爽粗大免费视频| 亚洲国产超清无码专区| 四虎亚洲国产成人久久精品| 免费a级毛片无码a∨免费软件| 在线观看亚洲免费视频|