软件是对质量的不懈追求

2010年3月8日 #

linux du 查看文件夹占用空间


du -sh *

posted @ 2011-04-15 08:39 BlakeSu 阅读(267) | 评论 (0)编辑 收藏

Building Standalone Application with Maven2

If you are building standalone application in Java, Maven is your friend when packing your application,
There are two way to let Maven package your application, either as a single jar with all your dependencies jar.


 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <configuration>
   <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
   </descriptorRefs>
  </configuration>
 </plugin>



One advantage if you choose to do this way is if you need to sign your application jar.
This is needed if you are building a Java Web Start client and you need more access than connecting back to the server.
To read more about have Maven signing your jar read http://maven.apache.org/plugins/maven-jar-plugin/usage.html.
But if you choose to go this way, make sure that all license agreement are shipped with your one single jar.

Another way is to let Maven package your source code only and then referring the dependent jar file from the MANIFEST file.


 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
   <archive>
    <manifest>
     <addClasspath>true</addClasspath>
     <mainClass>se.msc.adapter.Main</mainClass>
     <classpathPrefix>lib/</classpathPrefix>
    </manifest>
   </archive>
  </configuration>
 </plugin>

posted @ 2011-02-24 13:03 BlakeSu 阅读(308) | 评论 (0)编辑 收藏

eclipse 终于有了列编辑功能

eclipse 3.5之后终于有了列编辑,快捷键是alt+shift+a,再次按此快捷键返回常规编辑状态。


posted @ 2010-10-15 11:33 BlakeSu 阅读(1466) | 评论 (0)编辑 收藏

LineNumberReader 指定文件编码


import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;


public class Main {
    
    
public static void main(String[] args) throws IOException {

        InputStreamReader isr 
= new InputStreamReader(new FileInputStream("15370720.pdf4"), "utf-16");
        LineNumberReader lnr
=new LineNumberReader(isr);
        String line 
= null;
        
while((line=lnr.readLine())!=null){  
           System.out.println(lnr.getLineNumber()
+"\t"+line);
        }
   }
}

posted @ 2010-08-05 09:13 BlakeSu 阅读(1017) | 评论 (0)编辑 收藏

Class.getResourceAsStream 和 ClassLoader.getResourceAsStream

两个方法的区别是资源的定义不同, 一个主要用于相对与一个object取资源,而另一个用于取相对于classpath的
资源,用的是绝对路径。

在使用Class.getResourceAsStream 时, 资源路径有两种方式, 一种以 / 开头,则这样的路径是指定绝对
路径, 如果不以 / 开头, 则路径是相对与这个class所在的包的。

在使用ClassLoader.getResourceAsStream时, 路径直接使用相对于classpath的绝对路径。

举例,下面的三个语句,实际结果是一样的:
   com.explorers.Test.class.getResourceAsStream("abc.jpg")
= com.explorers.Test.class.getResourceAsStream("/com/explorers/abc.jpg")
= ClassLoader.getResourceAsStream("com/explorers/abc.jpg")

posted @ 2010-07-28 16:31 BlakeSu 阅读(276) | 评论 (0)编辑 收藏

Standalone Java CAS Client

There's a variety of clients for CAS. The Java-based clients (JA-SIG, Yale, see JA-SIG website) typically handle the browser-based client interaction with CAS very well through ServletFilter implementations.

Now what about programmatic authentication, i.e. achieving authentication through non-browser based applications? There exists a CAS .NET client but I did not manage to find the appropriate Java implementation. So here goes - it is based on the Apache HttpClient.

In case I missed any existing implementation achieving the same purpose, let's look at the bright side: at least now I understand the CAS protocol :-)

My CAS client works within any application. It uses the HttpClient and behaves like a browser client as CAS requires cookie support.

Here's the code:
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.log4j.Logger;

/**
* The CasClient allows users to programmatically login
* to CAS protected services based on the CAS 2 protocol.
* This client behaves like a browser-client in terms of
* cookie handling.<br>
*
@author Mathias Richter
*/
public class CasClient
{
  
   
public static Logger LOG = Logger.getLogger( CasClient.class  );

   
public static final String LOGIN_URL_PART = "login";
   
public static final String SERVICE_VALIDATE_URL_PART = "serviceValidate";
   
public static final String TICKET_BEGIN = "ticket=";
   
private static final String LT_BEGIN = "name="lt" value="";
   public static final String CAS_USER_BEGIN = "<cas:user>";
   
public static final String CAS_USER_END = "</cas:user>";
  
   
private HttpClient fClient;
   
private String fCasUrl;
  
   
/**
    * Construct a new CasClient.
    *
    * 
@param casUrl The base URL of the CAS service to be used.
    
*/
   
public CasClient( String casBaseUrl )
   {
       
thisnew HttpClient(), casBaseUrl );
   }
  
   
/**
    * Construct a new CasClient which uses the specified HttpClient
    * for its HTTP calls.
    *
    * 
@param client
    * 
@param casBaseUrl
    
*/
   
public CasClient( HttpClient client, String casBaseUrl )
   {
       fClient 
= client;
       fCasUrl 
= casBaseUrl;
   }
  
   
/**
    * Authenticate the specified username with the specified password.
    * This will not yield any ticket, as no service is authenticated
    * against. This wil just set the CAS cookie in this client upon
    * successful authentication.
    *
    * 
@param username
    * 
@param password
    
*/
   
public void authenticate( String username, String password )
   {
       authenticate( 
null, username, password );
   }
  
   
/**
    * Validate the specified service ticket against the specified service.
    * If the ticket is valid, this will yield the clear text user name
    * of the autenticated user.<br>
    * Note that each service ticket issued by CAS can be used exactly once
    * to validate.
    *
    * 
@param serviceUrl
    * 
@param serviceTicket
    *
    * 
@return Clear text username of the authenticated user.
    
*/
   
public String validate( String serviceUrl, String serviceTicket )
   {
       String result 
= null;
       PostMethod method 
= new PostMethod( fCasUrl + SERVICE_VALIDATE_URL_PART );
       method.setParameter( 
"service", serviceUrl );
       method.setParameter( 
"ticket", serviceTicket );
       
try
       {
           
int statusCode = fClient.executeMethod(method);
           
if (statusCode != HttpStatus.SC_OK)
           {
               LOG.error( 
"Could not validate: " + method.getStatusLine() );
               method.releaseConnection();
           } 
else
           {   
               result 
= extractUser( new String( method.getResponseBody() ) );
           }
       } 
catch ( Exception x )
       {
           LOG.error( 
"Could not validate: " + x.toString () );
           x.printStackTrace();
       }
       method.releaseConnection();
       
return result;
   }
  
   
/**
    * Authenticate the specified user with the specified password against the
    * specified service.
    *
    * 
@param serviceUrl May be null. If a url is specified, the authentication will happen against this service, yielding a service ticket which can be validated.
    * 
@param username
    * 
@param password
    * 
@return A valid service ticket, if and only if the specified service URL is not null.
    
*/
   
public String authenticate( String serviceUrl, String username, String password )
   {
       String lt 
= getLt( serviceUrl );
       
if ( lt == null )
       {
           LOG.error( 
"Cannot retrieve LT from CAS. Aborting authentication for '" + username + "'" );
           
return null;
       }
       String result 
= null;
       PostMethod method 
= new PostMethod( fCasUrl + LOGIN_URL_PART );
       
if ( serviceUrl != null ) // optional
           method.setParameter( "service", serviceUrl );
       method.setParameter( 
"_eventId""submit" );
       method.setParameter(
"username", username );
       method.setParameter(
"password", password );
       method.setParameter(
"lt", lt );
       method.setParameter( 
"gateway""true" );
       
try
       {
           fClient.executeMethod(method);
           
if ( serviceUrl == null )
           {
               
if ( extractLt( new String( method.getResponseBody() ) ) != null ) // if CAS does not return a login page with an LT authentication was successful
               {
                   LOG.error( 
"Authentication for '" +  username + "' unsuccessful" );
                   
if ( LOG.isDebugEnabled() )
                       LOG.debug( 
"Authentication for '" + username + "' unsuccessful." );
               } 
else
               {
                   
if ( LOG.isDebugEnabled() )
                       LOG.debug( 
"Authentication for '" + username + "' unsuccessful." );
               }
           } 
else
           {
               Header h 
= method.getResponseHeader( "Location" );
               
if ( h != null )
                   result 
= extractServiceTicket( h.getValue() );
               
if ( result == null )
                   LOG.error( 
"Authentication for '" + username + "' unsuccessful." );
           }
       } 
catch ( Exception x )
       {
           LOG.error( 
"Could not authenticate'" + username + "':" + x.toString () );
       }
       method.releaseConnection();
       
return result;
   }
  
   
/**
    * Helper method to extract the user name from a "service validate" call to CAS.
    *
    * 
@param data Response data.
    * 
@return The clear text username, if it could be extracted, null otherwise.
    
*/
   
protected String extractUser( String data )
   {
       String user 
= null;
       
int start = data.indexOf( CAS_USER_BEGIN  );
       
if ( start >= 0 )
       {
           start 
+= CAS_USER_BEGIN.length();
           
int end = data.indexOf( CAS_USER_END );
           
if ( end > start )
               user 
= data.substring( start, end );
           
else
               LOG.warn( 
"Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
       } 
else
       {
           LOG.warn( 
"Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
       }
       
return user;
   }
  
   
/**
    * Helper method to extract the service ticket from a login call to CAS.
    *
    * 
@param data Response data.
    * 
@return The service ticket, if it could be extracted, null otherwise.
    
*/
   
protected String extractServiceTicket( String data )
   {
       String serviceTicket 
= null;
       
int start = data.indexOf( TICKET_BEGIN  );
       
if ( start > 0 )
       {
           start 
+= TICKET_BEGIN.length();
           serviceTicket 
= data.substring( start );
       }
       
return serviceTicket;
   }
  
   
/**
    * Helper method to extract the LT from a login form from CAS.
    *
    * 
@param data Response data.
    * 
@return The LT, if it could be extracted, null otherwise.
    
*/
   
protected String extractLt( String data )
   {
       String token 
= null;
       
int start = data.indexOf( LT_BEGIN  );
       
if ( start < 0 )
       {
           LOG.error( 
"Could not obtain LT token from CAS: LT Token not found in response." );
       } 
else
       {
           start 
+= LT_BEGIN.length();
           
int end = data.indexOf( """, start );
           token = data.substring( start, end );
       }       
       
return token;
   }
  
   
/**
    * This method requests the original login form from CAS.
    * This form contains an LT, an initial token that must be
    * presented to CAS upon sending it an authentication request
    * with credentials.<br>
    * If a service URL is provided (which is optional), this method
    * will post the URL such that CAS authenticates against the
    * specified service when a subsequent authentication request is
    * sent.
    *
    * 
@param serviceUrl
    * 
@return The LT token if it could be extracted from the CAS response.
    
*/
   
protected String getLt( String serviceUrl )
   {
       String lt 
= null;
       HttpMethod method 
= null;
       
if ( serviceUrl == null )
           method 
= new GetMethod( fCasUrl + LOGIN_URL_PART );
       
else
       {
           method 
= new PostMethod( fCasUrl + LOGIN_URL_PART );
           ( ( PostMethod ) method ).setParameter( 
"service", serviceUrl );
       }
       
try
       {
           
int statusCode = fClient.executeMethod(method);
           
if (statusCode != HttpStatus.SC_OK)
           {
               LOG.error( 
"Could not obtain LT token from CAS: " + method.getStatusLine() );
               method.releaseConnection();
           } 
else
           {
               Object o 
= method.getResponseHeaders() ;
               
return extractLt( new String( method.getResponseBody() ) );
           }
       } 
catch ( Exception x )
       {
           LOG.error( 
"Could not obtain LT token from CAS: " + x.toString () );
       }
       method.releaseConnection();
       
return lt;
   }
  
}

posted @ 2010-07-15 17:59 BlakeSu 阅读(400) | 评论 (0)编辑 收藏

java取文件换行符

System.getProperty("line.separator")

posted @ 2010-06-30 15:45 BlakeSu 阅读(299) | 评论 (0)编辑 收藏

禁止浏览器缓存

html
  <meta http-equiv="pragma" content="no-cache">
  
<meta http-equiv="cache-control" content="no-cache">
  
<meta http-equiv="expires" content="0">


servlet
          response.setHeader("pragma","no-cache");
          response.setHeader(
"cache-control","no-cache");
          response.setDateHeader(
"expires"0);


posted @ 2010-06-25 09:06 BlakeSu 阅读(238) | 评论 (0)编辑 收藏

frame 中跨域访问cookie(java)

response.addHeader("P3P","CP=CAO PSA OUR");

posted @ 2010-06-25 09:04 BlakeSu 阅读(399) | 评论 (0)编辑 收藏

vim的复制粘贴小结

原文地址 http://lsong17.spaces.live.com/blog/cns!556C21919D77FB59!603.trak


用vim这么久 了,始终也不知道怎么在vim中使用系统粘贴板,通常要在网上复制一段代码都是先gedit打开文件,中键粘贴后关闭,然后再用vim打开编辑,真的不 爽;上次论坛上有人问到了怎么在vim中使用系统粘贴板,印象里回复很多,有好几页的回复却没有解决问题,今天实在受不了了又在网上找办法,竟意外地找到 了,贴出来分享一下。

如果只是想使用系统粘贴板的话直接在输入模式按Shift+Inset就可以了,下面讲一下vim的粘贴板的基础知识,有兴趣的可以看看, 应该会有所收获的。
vim帮助文档里与粘贴板有关的内容如下:

  1. vim有12个粘贴板,分别是0、1、2、...、9、a、“、+;用:reg命令可以查看各个粘贴板里的内容。在vim中简单用y只是复制到 “(双引号)粘贴板里,同样用p粘贴的也是这个粘贴板里的内容;

  2. 要将vim的内容复制到某个粘贴板,需要退出编辑模式,进入正常模式后,选择要复制的内容,然后按"Ny完成复制,其中N为粘 贴板号(注意是按一下双引号然后按粘贴板号最后按y),例如要把内容复制到粘贴板a,选中内容后按"ay就可以了,有两点需要说明一下:
    • “号粘贴板(临时粘贴板)比较特殊,直接按y就复制到这个粘贴板中了,直接按p就粘贴这个粘贴板中的内容;
    • +号粘贴板是系统粘贴板,用"+y将内容复制到该粘贴板后可以使用Ctrl+V将其粘贴到其他文档(如firefox、gedit) 中,同理,要把在其他地方用Ctrl+C或右键复制的内容复制到vim中,需要在正常模式下按"+p;

  3. 要将vim某个粘贴板里的内容粘贴进来,需要退出编辑模式,在正常模式按"Np,其中N为粘贴板号,如上所述,可以按"5p将 5号粘贴板里的内容粘贴进来,也可以按"+p将系统全局粘贴板里的内容粘贴进来。

注意:在我这里,只有vim.gtk或vim.gnome才能使用系统全局粘贴板,默认的 vim.basic看不到+号寄存器。

posted @ 2010-06-18 14:21 BlakeSu 阅读(239) | 评论 (0)编辑 收藏

Linux下mail使用技巧

登录LINUX系统后,经常会看到"you have mail",却苦于不知道如何查看,相信菜鸟们都遇到过,偶在网上用“linux mail"找了很久,但大都是介绍mail服务器的,黄天总算没负有心人,在洪恩在找到一篇介绍基础的文章,不敢独享。
 
系统提供了用户 之间通信的邮件系统,当用户打开终端注册登录时发现系统给出如下信息:
    you have mail.

    这时用户可通过键入mail命令读取信件:

    $ mail

    mail程序将逐个显示用户的信件,并依照时间顺序,显示最新的信件。每显示一段信件,mail都询问用户是否要对该信件作些处理。若用户回答d,则表示 删除信件;若仅按回车键,表示对信件不作任何改动(信件仍旧保存,下次还可读这一信件);若回答p,则要求重复显示信件;s filename表示要把信件存入所命名的文件;若回答q,表示要从mail退出。

    我们在本章的第一个例子中演示了如何写一封信,作为练习,你可送信件给自己,然后键入mail读取自己发的信件,看看会有什么效果。(发信给自己是一种设 置备忘录的方法)。

    $mail frank 给自己写信

    subject: test

    This is a mail test

    CRL-d

    EOT

    $

    $mail 查看信件

    “/var/spool/mail/frank:”1 message 1 new

    >Nfrank@xteam.xteamlinux.comThu Mar 25 11:00 13/403 “test”

    &

    Message 1:

    From frank Thu Mar 25 11:00:25 1999/3/25

    Received: (fromfrank@localhost)

    by xteam.xteamlinux.com(8.8.4/8.8.4)

    id LAA05170 for frank;Thu 25 Mar 1999 11:00:25 GMT

    Date: Thu,25 Mar 1999 11:00:25 GMT

    From:RHS Linux User <frank@xteam.xteamlinux.com>

    Message-Id:<199903251142.LAA05170@xteam.xteamlinux.com>

    To:frank@xteam.xteamlinux.com

    Subject:test

    Status:R

    This is a mail test

    &

    mail命令还有很多其它用法,例如发送事先准备好的信件,或一次送信给若干人。还可以用其它方法送信件。

posted @ 2010-06-18 11:05 BlakeSu 阅读(182) | 评论 (0)编辑 收藏

Mysql中limit的用法详解

    Mysql中limit的用法:在我们使用查询语句的时候,经常要返回前几条或者中间某几行数据,这个时候怎么办呢?
  不用担心,mysql已经为我们提供了这样一个功能。

  SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset

LIMIT 子句可以被用于强制 SELECT 语句返回指定的记录数。LIMIT 接受一个或两个数字参数。参数必须是一个整数常量。
  如果给定两个参数,第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最大数目。初始记录行的偏移量是 0(而不是 1):
  为了与 PostgreSQL 兼容,MySQL 也支持句法: LIMIT # OFFSET #。

mysql> SELECT * FROM table LIMIT 5,10; // 检索记录行 6-15

//为了检索从某一个偏移量到记录集的结束所有的记录行,可以指定第二个参数为 -1:

mysql> SELECT * FROM table LIMIT 95,-1; // 检索记录行 96-last.

//如果只给定一个参数,它表示返回最大的记录行数目:

mysql> SELECT * FROM table LIMIT 5; //检索前 5 个记录行

//换句话说,LIMIT n 等价于 LIMIT 0,n。

注意limit 10和limit 9,1的不同:

例如:

1.Select * From cyclopedia Where ID>=(
    Select Max(ID) From (
      Select ID From cyclopedia Order By ID limit 90001
    ) As tmp
  ) limit 100;

2.Select * From cyclopedia Where ID>=(
    Select Max(ID) From (
      Select ID From cyclopedia Order By ID limit 90000,1
    ) As tmp
  ) limit 100;

 

    第1句是先取了前90001条记录,取其中最大一个ID值作为起始标识,然后利用它可以快速定位下100条记录

第2句择是仅仅取90000条记录后1条,然后取ID值作起始标识定位下100条记录

第1句执行结果.100 rows in set (0.23) sec

第2句执行结果.100 rows in set (0.19) sec

其实第2句完全可以简化成:
    Select * From cyclopedia Where ID>=(
   Select ID From cyclopedia limit 90000,1
)limit 100;

直接利用第90000条记录的ID,不用经过Max运算,这样做理论上效率因该高一些,但在实际使用中几乎看不到效果,
   因为本身定位ID返回的就是1条记录,Max几乎不用运作就能得到结果,但这样写更清淅明朗,省去了画蛇那一足.


Select Top 100 * From cyclopedia Where ID>=(
Select Top 90001 Max(ID) From (
Select ID From cyclopedia Order By ID
) As tmp
)

但不管是实现方式是存贮过程还是直接代码中,瓶颈始终在于MS-SQL的TOP总是要返回前N个记录,这种情况在数据量不大时感受不深,
   但如果成百上千万,效率肯定会低下的.相比之下MySQL的limit就有优势的多,执行:


Select ID From cyclopedia limit 90000
Select ID From cyclopedia limit 90000,1

的结果分别是:


90000 rows in set (0.36) sec
1 row in set (0.06) sec

而MS-SQL只能用Select Top 90000 ID From cyclopedia 执行时间是390ms,执行同样的操作时间也不及MySQL的360ms.

limit的offset(偏移量)用于记录较多的时候,记录较少时,偏移offset较小,直接使用limit较优。offset越大,后者越优。
 

1、offset比较小的时候。

select * from yanxue8_visit limit 10,10

多次运行,时间保持在0.0004-0.0005之间


Select * From yanxue8_visit Where vid >=(
  Select vid From yanxue8_visit Order By vid limit 10,1
) limit 10

多次运行,时间保持在0.0005-0.0006之间,主要是0.0006

结论:偏移offset较小的时候,直接使用limit较优。这个显示是子查询的原因。

2、offset大的时候。

select * from yanxue8_visit limit 10000,10

多次运行,时间保持在0.0187左右

Select * From yanxue8_visit Where vid >=(
  Select vid From yanxue8_visit Order By vid limit 10000,1
) limit 10

多次运行,时间保持在0.0061左右,只有前者的1/3。可以预先offset越大,后者越优。

mysql> SELECT * FROM table LIMIT 95,-1; // 检索记录行 96-last.

//如果只给定一个参数,它表示返回最大的记录行数目.

posted @ 2010-06-02 14:43 BlakeSu 阅读(441) | 评论 (0)编辑 收藏

枚举类型enum示例




public enum OrderStatus {
    A(
1), B(2), C(3), D(4), F(5), INCOMPLETE(6);
    
    
private final int value;
    
/**
     * Constructor.
     
*/
    
private OrderStatus(int value) {
        
this.value = value;
    }
    
    
/**
     * Get the value.
     * 
@return the value
     
*/
    
public int getValue() {
        
return value;
    }

}


posted @ 2010-06-02 13:33 BlakeSu 阅读(137) | 评论 (0)编辑 收藏

JS try.....catch的使用

<script language="javascript">
try
{
throw new Error(10,"asdasdasd")
}
catch (e)
{
alert(e.message);
alert(e.description)
alert(e.number)
alert(e.name)
throw new Error(10,"asdasdasd")
}

</script>  

在JavaScript可以使用try...catch来进行异常处理。例如:  

 

try {
foo.bar();
} catch (e) {
alert(e.name + ": " + e.message);
}

目前我们可能得到的系统异常主要包含以下6种:

  • EvalError: raised when an error occurs executing code in eval()  
  • RangeError: raised when a numeric variable or parameter is outside of its valid range  
  • ReferenceError: raised when de-referencing an invalid reference  
  • SyntaxError: raised when a syntax error occurs while parsing code in eval()  
  • TypeError: raised when a variable or parameter is not a valid type  
  • URIError: raised when encodeURI() or decodeURI() are passed invalid parameters  

上面的六种异常对象都继承自Error对象。他们都支持以下两种构造方法:

 

new Error();
new Error("异常信息");

手工抛出异常的方法如下:

 

try {
throw new Error("Whoops!");
} catch (e) {
alert(e.name + ": " + e.message);
}

如要判断异常信息的类型,可在catch中进行判断:

 

try {
foo.bar();
} catch (e) {
if (e instanceof EvalError) {
   alert(e.name + ":" + e.message);
}
else if (e instanceof RangeError) {
   alert(e.name + ": " + e.message);
}
// etc
}

Error具有下面一些主要属性:

  • description: 错误描述 (仅IE可用).  
  • fileName: 出错的文件名 (仅Mozilla可用).  
  • lineNumber: 出错的行数 (仅Mozilla可用).  
  • message: 错误信息 (在IE下同description)  
  • name: 错误类型.  
  • number: 错误代码 (仅IE可用).  
  • stack: 像Java中的Stack Trace一样的错误堆栈信息 (仅Mozilla可用).  

因此为了更好的了解错误信息我们可以将catch部分改为如下形式:  

 

try {
foo.bar();
} catch (e) {
if (browserType != BROWSER_IE) {                            
   alert("name: " + e.name +
    "message: " + e.message +
    "lineNumber: " + e.lineNumber +
    "fileName: " + e.fileName +
    "stack: " + e.stack);        
}
else {                    
   alert("name: " + e.name +     
    "errorNumber: " + (e.number & 0xFFFF ) +
    "message: " + e.message");        
}
}

JavaScript中的throw命令事实上可以抛出任何对象,并且我们可以在catch接受到此对象。例 如:

 

try {
throw new Date(); // 抛出当前时间对象
} catch (e) {
alert(e.toLocaleString()); // 使用本地格式显示当前时间
}

posted @ 2010-06-02 10:38 BlakeSu 阅读(323) | 评论 (0)编辑 收藏

深拷贝

import java.io.*;

public class ObjectCloner
{
   
// so that nobody can accidentally create an ObjectCloner object
   private ObjectCloner(){}
   
// returns a deep copy of an object
   static public Object deepCopy(Object oldObj) throws Exception
   {
      ObjectOutputStream oos 
= null;
      ObjectInputStream ois 
= null;
      
try
      {
         ByteArrayOutputStream bos 
= new ByteArrayOutputStream(); 
         oos 
= new ObjectOutputStream(bos); 
         
// serialize and pass the object
         oos.writeObject(oldObj);   
         oos.flush();               
         ByteArrayInputStream bin 
= new ByteArrayInputStream(bos.toByteArray()); 
         ois 
= new ObjectInputStream(bin);
         
// return the new object
         return ois.readObject();
      }
      
catch(Exception e)
      {
         System.out.println(
"Exception in ObjectCloner = " + e);
         
throw(e);
      }
      
finally
      {
         oos.close();
         ois.close();
      }
   }
   
}

posted @ 2010-05-25 09:30 BlakeSu 阅读(165) | 评论 (0)编辑 收藏

mysql convert int to char/varchar

select cast(1 as char)

char 不能换成varchar,否则会报错。

posted @ 2010-05-12 17:12 BlakeSu 阅读(2884) | 评论 (0)编辑 收藏

How to check Linux distribution and version?

If u are on an unknown server and keen to know it’s linux distribution info, you can check the linux distribution info by just a single command (eg. version, codename, etc). Just tested this command in UBuntu and CentOS, both return as what i expected. :)

To check linux distribution and version, follow the steps below:-

  • Start your terminal and enter the command below to show your the linux distribution info:-
    $ cat /etc/*-release
  • Here’s my result in one of my my Ubuntu box:-
    $ cat /etc/*-release
    DISTRIB_ID=Ubuntu
    DISTRIB_RELEASE=9.10
    DISTRIB_CODENAME=karmic
    DISTRIB_DESCRIPTION="Ubuntu 9.10"

    Cool right!

posted @ 2010-05-08 13:29 BlakeSu 阅读(678) | 评论 (0)编辑 收藏

Eclipse集成windows资源管理器简单方法

Run-->External Tools-->External tools configurations
new 一个 program
location 里面填 :C:\WINDOWS\explorer.exe
Arguments 里面填: ${container_loc}
点击 Run

posted @ 2010-05-08 08:40 BlakeSu 阅读(255) | 评论 (0)编辑 收藏

commons lang 比较有用的类

ArrayUtils                 //简化数组的操作
LocaleUtils
SerializationUtils
StringEscapeUtils
StringUtils
SystemUtils
Validate                   //输入参数验证
NestableException
NestableRuntimeException
StopWatch          //秒表类

posted @ 2010-04-26 10:16 BlakeSu 阅读(202) | 评论 (0)编辑 收藏

xmind 当真不错

xmind是绘制思维导图的工具。
使用之后,发现绘制组织结构图和wbs都很方便。
软件基于eclipse框架开发,反应速度和操作性也都很不错。
更重要的,图形的效果也是专业级的 :)

posted @ 2010-04-23 09:51 BlakeSu 阅读(237) | 评论 (0)编辑 收藏

Java 中serialVersionUID的解释

serialVersionUID作用:
       序列化时为了保持版本的兼容性,即在版本升级时反序列化仍保持对象的唯一性。
有两种生成方式:
       一个是默认的1L,比如:private static final long serialVersionUID = 1L;
       一个是根据类名、接口名、成员方法及属性等来生成一个64位的哈希字段,比如:
       private static final   long     serialVersionUID = xxxxL;

当你一个类实现了Serializable接口,如果没有定义serialVersionUID,Eclipse会提供这个
     提示功能告诉你去定义 。在Eclipse中点击类中warning的图标一下,Eclipse就会
     自动给定两种生成的方式。如果不想定义它,在Eclipse的设置中也
      可以把它关掉的,设置如下:
        Window ==> Preferences ==> Java ==> Compiler ==> Error/Warnings ==>
        Potential programming problems
        将Serializable class without serialVersionUID的warning改成ignore即可。

如果你没有考虑到兼容性问题时,就把它关掉,不过有这个功能是好的,只要任何类别实现了Serializable这个接口的话,如果没有加入 serialVersionUID,Eclipse都会给你warning提示,这个serialVersionUID为了让该类别 Serializable向后兼容。

如果你的类Serialized存到硬盘上面后,可是后来你却更改了类别的field(增加或减少或改名),当你Deserialize时,就会出现 Exception的,这样就会造成不兼容性的问题。

但当serialVersionUID相同时,它就会将不一样的field以type的预设值Deserialize,可避开不兼容性问题。

posted @ 2010-04-08 10:37 BlakeSu 阅读(151) | 评论 (0)编辑 收藏

spring 相关

ApplicationContext wac = WebApplicationContextUtils          .getRequiredWebApplicationContext(config.getServletContext());

posted @ 2010-04-06 13:01 BlakeSu 阅读(146) | 评论 (0)编辑 收藏

wesphere6.1修改默认端口

环境->虚拟主机->default_host->其它属性(主机别名)->修改端口
服务器->应用程序服务器->server1->端口->WC_defaulthost->修改端口

posted @ 2010-04-02 10:36 BlakeSu 阅读(216) | 评论 (0)编辑 收藏

jquery validate自定义验证方法


 /* 追加自定义验证方法 */   
 
// 身份证号码验证   
 jQuery.validator.addMethod("idcardno"function(value, element) {
   
return this.optional(element) || isIdCardNo(value);   
 }, 
"请正确输入身份证号码");
 
  
//字母数字
 jQuery.validator.addMethod("alnum"function(value, element) {
   
return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
 }, 
"只能包括英文字母和数字");
 
  
// 手机号码验证   
 jQuery.validator.addMethod("cellphone"function(value, element) {
   
var length = value.length;
   
return this.optional(element) || (length == 11 && /^(1\d{10})$/.test(value));
 }, 
"请正确填写手机号码"); 
 
  
// 电话号码验证   
 jQuery.validator.addMethod("telephone"function(value, element) {
   
var tel = /^(\d{3,4}-?)?\d{7,9}$/g;
   
return this.optional(element) || (tel.test(value));
 }, 
"请正确填写电话号码");
 
 
// 邮政编码验证
 jQuery.validator.addMethod("zipcode"function(value, element) {
   
var tel = /^[0-9]{6}$/;
   
return this.optional(element) || (tel.test(value));
 }, 
"请正确填写邮政编码");
 
  
// 汉字
 jQuery.validator.addMethod("chcharacter"function(value, element) {
   
var tel = /^[\u4e00-\u9fa5]+$/;
   
return this.optional(element) || (tel.test(value));
 }, 
"请输入汉字");
 
 
/**
 * 身份证号码验证
 *
 
*/
function isIdCardNo(num) {

 
var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);
 
var parityBit=new Array("1","0","X","9","8","7","6","5","4","3","2");
 
var varArray = new Array();
 
var intValue;
 
var lngProduct = 0;
 
var intCheckDigit;
 
var intStrLen = num.length;
 
var idNumber = num;
   
// initialize
     if ((intStrLen != 15&& (intStrLen != 18)) {
         
return false;
     }
     
// check and set value
     for(i=0;i<intStrLen;i++) {
         varArray[i] 
= idNumber.charAt(i);
         
if ((varArray[i] < '0|| varArray[i] > '9') && (i != 17)) {
             
return false;
         } 
else if (i < 17) {
             varArray[i] 
= varArray[i] * factorArr[i];
         }
     }
     
     
if (intStrLen == 18) {
         
//check date
         var date8 = idNumber.substring(6,14);
         
if (isDate8(date8) == false) {
            
return false;
         }
         
// calculate the sum of the products
         for(i=0;i<17;i++) {
             lngProduct 
= lngProduct + varArray[i];
         }
         
// calculate the check digit
         intCheckDigit = parityBit[lngProduct % 11];
         
// check last digit
         if (varArray[17!= intCheckDigit) {
             
return false;
         }
     }
     
else{        //length is 15
         //check date
         var date6 = idNumber.substring(6,12);
         
if (isDate6(date6) == false) {

             
return false;
         }
     }
     
return true;
     
 }
/**
 * 判断是否为“YYYYMM”式的时期
 *
 
*/
function isDate6(sDate) {
   
if(!/^[0-9]{6}$/.test(sDate)) {
      
return false;
   }
   
var year, month, day;
   year 
= sDate.substring(04);
   month 
= sDate.substring(46);
   
if (year < 1700 || year > 2500return false
   
if (month < 1 || month > 12return false
   
return true
}
/**
 * 判断是否为“YYYYMMDD”式的时期
 *
 
*/
function isDate8(sDate) {
   
if(!/^[0-9]{8}$/.test(sDate)) {
      
return false;
   }
   
var year, month, day;
   year 
= sDate.substring(04);
   month 
= sDate.substring(46);
   day 
= sDate.substring(68);
   
var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
   
if (year < 1700 || year > 2500return false
   
if (((year % 4 == 0&& (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
   
if (month < 1 || month > 12return false
   
if (day < 1 || day > iaMonthDays[month - 1]) return false
   
return true
}




posted @ 2010-03-30 11:30 BlakeSu 阅读(3010) | 评论 (2)编辑 收藏

Mozilla Thunderbird的一些设置

为了在windows和linux平台公用相同的邮件客户端和邮件内容,主要是有时候切换操作系统又要看以前的邮件。最后找到了 thunderbird(下面简称TB)客户端。这个客户端就是有点慢,倒是能满足我的要求。但是它的默认设置有时候有点不符合我们的使用习惯,我对它的 设置作了下面的一些修改:

    1:转发邮件
       默认的设置转发把邮件的内容作为附件转发。这样有两个不好的地方:第一,如果邮件有附件,这个附件不能转发;第二,接收方必须要用TB客户端了,否则打不 开。
       修改:编辑 -> 首选项 -> 编写 -> 常规:转发消息改成内联
   
    2:其它邮件客户端接收TB发的中文附件是乱码
       这个是标准问题,TB使用的是新的标准,但是别的客户端使用的是旧的标准(具体那个标准忘了,google一下就可以了)。这样就会出现乱码了。
       修改:编辑 -> 首选项 -> 高级 -> 配置编辑器:mail.strictly_mime.parm_folding 改成0或者1

    3:自动打开附件
       TB默认的是在打开邮件的时候同时自动打开邮件的附件。这样的话,如果附件大就很头痛。
       修改:编辑 -> 首选项 -> 高级 -> 配置编辑器:
          mail.inline_attachments   改成faulse
          mail.content_disposition.type   改成1

    4:回复邮件时回复的邮件内容在下面
       TB默认的回复邮件的回复内容是在下面的,这样如果邮件来回几次,回复比较多,看起来很不方便。
       修改:编辑 -> 首选项 -> 高级 -> 配置编辑器:Mail.identify.default.reply_on_top值由0改为1
  
    还有一个问题没有解决,就是有时候在TB中打开一个文件夹,它会重新建索引还是什么的,这时候打开一个文件夹比较慢。看网上有说把这个文件夹重命名,再创 建一个同名的文件夹,最后把老的文件夹的内容拷贝到新的里面就好了,这个没有试过。不过这个也不是特别大的问题,就没有继续搞了,什么时候有空再看看,到 时候再贴上来。

posted @ 2010-03-19 16:39 BlakeSu 阅读(671) | 评论 (0)编辑 收藏

tar命令详解

格式:  tar  选项  文件目录列表
功能:  对文件目录进行打包备份
选项:
-c  建立新的归档文件
-r  向归档文件末尾追加文件
-x  从归档文件中解出文件
-O  将文件解开到标准输出
-v  处理过程中输出相关信息
-f  对普通文件操作
-z  调用gzip来压缩归档文件,与-x联用时调用gzip完成解压缩
-Z  调用compress来压缩归档文件,与-x联用时调用compress完成解压缩  
例如:
1.将当前目录下所有.txt文件打包并压缩归档到文件this.tar.gz,我们可以使用
tar czvf this.tar.gz ./*.txt
2.将当前目录下的this.tar.gz中的文件解压到当前目录我们可以使用
tar xzvf this.tar.gz ./

posted @ 2010-03-18 17:21 BlakeSu 阅读(192) | 评论 (0)编辑 收藏

websphere6.1 设定虚拟机参数

Application Servers > server1 > Process Definition > Java Virtual Machine > Custom Properties

虚拟机参数在命令行的形式为 -Dproperty=value,在程序中可以用System.getProperty("property")取值。
利用这个特性可以对程序运行进行控制,避免代码的修改。




posted @ 2010-03-15 09:57 BlakeSu 阅读(250) | 评论 (0)编辑 收藏

firefox3.6扩展和插件安装位置

地址栏输入about:support,在打开的页面有打开配置文件夹的按钮;
扩展在Extensions文件夹下,插件在安装文件夹下的plugin和其他目录。

posted @ 2010-03-15 09:22 BlakeSu 阅读(409) | 评论 (0)编辑 收藏

xfire 动态客户端


import java.net.URL;

import org.codehaus.xfire.client.Client;

public class XfireClient
{

    
public static void main(String[] args)
    {
        DyClient();
    }

    
/**
     * You get a DynamicClient when you create a Client with the URL of a WSDL
     
*/
    
public static void DyClient()
    {
        
try
        {
            Client client 
= new Client(
                    
new URL(
                            
"http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx?wsdl"));
            Object[] results 
= client.invoke("qqCheckOnline",
                    
new Object[] { "31506173" });
            System.out.println((String) results[
0]);

        }
        
catch ( Exception e)
        {
            e.printStackTrace();
        }
    }
}




必须jar:
commons-codec-1.3.jar
commons-httpclient-3.0.jar
commons-logging-1.0.4.jar
jdom-1.0.jar
wsdl4j-1.6.1.jar
xfire-all-1.2.6.jar
XmlSchema-1.1.jar

posted @ 2010-03-08 16:00 BlakeSu 阅读(332) | 评论 (0)编辑 收藏