云自无心水自闲

天平山上白云泉,云自无心水自闲。何必奔冲山下去,更添波浪向人间!
posts - 288, comments - 524, trackbacks - 0, articles - 6
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

 

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就是时区,比如东八区,就传入8,西二区就传入-2

新的方法,使用指定的TimeZone ID来获得TimeZone,这样更精确,因为有一些城市,虽然时区。比如:悉尼和布里斯班,都是东10区,但是悉尼实行夏令时,所以夏天的时候,悉尼要比布里斯班早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列表,可以使用函数
    public static String[] TimeZone.getAvailableIDs();
来获得

 


posted @ 2008-02-07 07:04 云自无心水自闲 阅读(1551) | 评论 (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 云自无心水自闲 阅读(437) | 评论 (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 云自无心水自闲 阅读(15282) | 评论 (10)编辑 收藏

在Struts2中,radio标签可以使用一个list来输出一组radio按钮,
        <s:radio name="sex" list="#{'male','female'}" label="%{getText('app.label.sex')}" />
但是如何设置其中一个被默认选中。

查阅了struts2的文档,发现radio标签有一个value属性是用于对radio的进行预选的: http://struts.apache.org/2.x/docs/radio.html
value: Preset the value of input element.
于是,进行了试验,<s:radio name="sex" list="#{'male','female'}" label="%{getText('app.label.sex')}" value="male" />
结果失败了。male的值并没有被选中,经过反复研究,终于得到了正确的结果:
<s:radio name="sex" list="#{'male','female'}" label="%{getText('app.label.sex')}" value="'male'" />
看到其中的区别了吗,就是多了两个单引号。
我认为这是因为value属性的特性引起的。如果male没有加引号,那么struts2会去值的堆栈中寻找变量名为male的值,结果找不到。
加上单引号后,struts2(应该是ognl)把'male'认为是一个简单的字符串。

这样,radio就能够正确地匹配到值,使指定的值默认被选中

posted @ 2008-01-24 22:06 云自无心水自闲 阅读(7046) | 评论 (7)编辑 收藏


在iBatis中,对于in子句的标准做法是采用动态sql来解决的。具体方法大致是:Java代码传入一个List或者数组,然后在sqlMapConfig映射中使用iterate循环取这个变量,动态地生成sql语句。
这个标准解法的缺点是,使用起来比较麻烦
1. 需要在sqlMapConfig中使用动态语句
2. 需要传入一个Iterable的变量
对于这个问题,我使用了一个偷懒的办法,就是使用$标记。
在iBatis中,普通的变量,比如:v,是使用#号,在这个例子中,就是:#v#。
这样,iBatis会使用prepareStatement,并对变量进行变量绑定。
而$符号是简单替代的用法,在数据库的执行效率上要比前一种差。但优点就是简单方便。
比如:
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 云自无心水自闲 阅读(8567) | 评论 (3)编辑 收藏

dhtmlXTree的节点定义可以从服务器生成的Xml中动态加载,我目前使用的是Struts2. 因此,我的做法是,在Javascript生成dhtmlxTree的时候,请求一个加载Struts2的action,Struts2的Action进行用户权限认证,动态生成菜单的Xml字符串。而在jsp中只输出这一个字符串。
开始进行的都比较顺利,但是客户端和服务端一连起来就出问题,页面在加载Xml的时候总是弹出一个对话框,说是加载的xml格式不正确。但是我在IE中直接输入Action,页面显示的结果十分正确,没有问题。后来,无意中我查看了返回xml页面的源文件,这才发现了问题。
原来,xml的<和>全都被转换成&lt;和&gt;了。
我一开始是想在后台考虑如何对字符串进行转换,后来在查struts2文档的时候发现,<s:property有一个escape属性,可以完美地解决这个问题,<s:property value="menuXmlString" escape="false"/>

例子已经整理出来了:http://www.blogjava.net/usherlight/archive/2008/08/07/220756.html

posted @ 2007-12-14 21:14 云自无心水自闲 阅读(5418) | 评论 (6)编辑 收藏

最近在网上搜索网页上的树形菜单的开源项目,发现有一个dhtmlx公司做的挺好的。
dhtmlx.com
其组件包括:
 dhtmlxTree    dhtmlxTabbar
 dhtmlxGrid    dhtmlxCombo
 dhtmlxTreeGrid   dhtmlxVault
 dhtmlxMenu   dhtmlxToolbar

界面做得相当漂亮,在Live Demo中有3种Theme可以选择。
功能也相当出色:可以拖放树中的节点、动态改变节点的Icon,定义节点事件。
可以动态地从Xml中加载菜单的结构定义
节点可编辑
可使用键盘浏览树
树节点可带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 云自无心水自闲 阅读(2676) | 评论 (4)编辑 收藏


    网上介绍使用zipInStream和zipOutStream对文件或者文件夹进行压缩和解压缩的文章比较多。
    但是这次项目中需要对byte[]进行压缩,然后decode,通过http发送到服务端。

    最简单的方法,当然是把byte[]写到文件里,然后根据网上已有的文章,生成fileInputStream,构造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 云自无心水自闲 阅读(4888) | 评论 (2)编辑 收藏

    1. 先写Controller
    2. Controller将业务逻辑委派给Service完成
    3. Service返回一个Domain Object Model
    4. 将Domail Object Model封装成ModelAndView作为Controller的返回结果,并赋予View的名称。
    5. InternalResourceViewResolver根据View名称取出对应的Jsp文件,创建一个包含前缀和后缀的真正的路径
    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会根据这个servlet的名字(在这里是spring)自动寻找  <名字>-servlet.xml(这里将会是:spring-servlet.xml)
    10. 在spring-servlet.xml中,将service注射给controller

    posted @ 2007-09-22 21:28 云自无心水自闲 阅读(1738) | 评论 (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 云自无心水自闲 阅读(540) | 评论 (0)编辑 收藏

    仅列出标题
    共29页: First 上一页 14 15 16 17 18 19 20 21 22 下一页 Last