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

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

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

    隨筆 - 40, 文章 - 0, 評(píng)論 - 20, 引用 - 0
    數(shù)據(jù)加載中……

    2005年11月23日

    J2me開發(fā)


    一些資料:




    http://www.csdn.net/subject/j2meTools/


    http://news.csdn.net/news/newstopic/24/24127.shtml



    posted @ 2006-11-01 15:30 月亮 閱讀(212) | 評(píng)論 (0)編輯 收藏

    游戲

    有個(gè)輸家,就一定有個(gè)贏家。我是輸家,但我四周望了一圈,卻沒看到半個(gè)贏家,我想,贏家應(yīng)該也是我了,你說呢?

    posted @ 2006-09-12 15:35 月亮 閱讀(206) | 評(píng)論 (1)編輯 收藏

    vi命令詳解

    vi命令是unix下常用而重要命令,可在全屏幕方式下編輯一個(gè)或多個(gè)文件。若在vi執(zhí)行時(shí)?
    沒有指定一個(gè)文件,那么vi命令會(huì)自動(dòng)產(chǎn)生一個(gè)無名的空的工作文件。若指定的文件不存在,?
    那么就按指定的文件名創(chuàng)建一個(gè)新的文件。若對文件的修改不保存的話,v?i命令并不改變原?
    來文件的內(nèi)容。?

      注意:vi命令并不鎖住所編輯的文件,因此多個(gè)用戶可能在同時(shí)編輯一個(gè)文件,那么最后?
    保存的文件版本將被保留。?

    下面是vi命令使用的一些選項(xiàng)及含義:??????????

      -c?sub-command?在對指定的文件編輯前,先執(zhí)行指定的命令?sub-command?.?

      -r?filename?恢復(fù)指定的文件filename?.??????????

      -R?將指定的文件以只讀的方式放入編輯器中,這樣不會(huì)保存對文件的任何修?改。?

      -y?number?將編輯窗口的大小設(shè)為number行。??????????

      下面是vi編輯所處的三種模式:??????????

      .命令模式?進(jìn)入vi時(shí)所處的模式。在此模式下用戶可輸入各種子命令對進(jìn)行*作,如刪除行、?
    粘貼行、移向下一個(gè)字、移向不同行等。?

      .文本輸入模式?在此模式下可以修改一行的內(nèi)容并增添新行。在命令模式下鍵入a?、i?或?
    c鍵可進(jìn)入文本輸入模式,按Escape鍵可返回命令模式。?

      .命令項(xiàng)模式?在此模式下,可以通過子命令輸入更多的參數(shù)。如:w子命令要求輸入一文?
    件名,"/"子命令要求輸入一個(gè)查找項(xiàng)。用戶使用Escape鍵返回命令模式。?


    下面是自命令模式下執(zhí)行的,在同一行上移動(dòng)的自命令:??????????

      h?將光標(biāo)左移一格。??????????

      l?將光標(biāo)右移一格。??????????

      j?將光標(biāo)下移一格。??????????

      k?將光標(biāo)上移一格。??????????

      w?將光標(biāo)移到下一個(gè)小字的前面。??????????

      W?將光標(biāo)移到下一個(gè)大字的前面。??????????

      b?將光標(biāo)移到前一個(gè)小字的前面。??????????

      B?將光標(biāo)移到前一個(gè)大字的前面。??????????

      e?將光標(biāo)移到下一個(gè)小字的后面。??????????

      E?將光標(biāo)移到前一個(gè)大字的后面。??????????

      fc?把光標(biāo)移到同一行的下一個(gè)c字符處。??????????

      Fc?把光標(biāo)移到同一行的前一個(gè)c字符處。??????????

      tc?把光標(biāo)移到同一行的下一個(gè)字符c的前一格。??????????

      Tc?把光標(biāo)移到同一行的前一個(gè)字符c的后一格。??????????

      number|?把光標(biāo)移到遞number列上。??????????

    下面是命令模式下在行間移動(dòng)的子命令:??????????

      +或Enter?把光標(biāo)移至下一行第一個(gè)非空白字符。??????????

      -?把光標(biāo)移至上一行第一個(gè)非空白字符。??????????

      0?把光標(biāo)移到當(dāng)前行的第一個(gè)字符處。??????????

      $?把光標(biāo)移到當(dāng)前行的最后一個(gè)字符處。??????????

      H?把光標(biāo)移到屏幕最頂端一行。??????????

      L?把光標(biāo)移到屏幕最底端一行。??????????

      M?把光標(biāo)移到屏幕中間。??????????

    下面是命令模式下改變屏幕顯示的子命令:??????????

      z-?把當(dāng)前行作為屏幕的最后一行,并重新顯示屏幕。??????????

      z.?把當(dāng)前行作為屏幕的中間一行,并重新顯示屏幕。??????????

      Ctrl+l?重新顯示屏幕當(dāng)前內(nèi)容。??????????

      /pattern/z-?尋找pattern的下一個(gè)位置,并把所在行設(shè)為屏幕的最后一行。?

    下面是在命令模式下用來顯示頁面的子命令:??????????

      Ctrl?+?f向后滾一頁。??????????

      Ctrl?+?d向后滾半頁。??????????

      Ctrl?+?b向前滾一頁。??????????

      Ctrl?+?u向前滾半頁。??????????

      Ctrl?+?e屏幕向下滾一行。??????????

      Ctrl?+?y屏幕項(xiàng)上滾一行。??????????

    下面是在命令模式下用來查找字符串所使用的子命令:??????????

      /pattern?向后尋找指定的pattern?,若遇到文件尾,則從頭再開始。?

      ?pattern?向前尋找指定的pattern?,若遇到文件頭,則從尾再開始。?

      n?在上次指定的方向上,再次執(zhí)行上次定義的查找。??????????

      N?在上次指定的方向的相反方向上,再次執(zhí)行上次定義的查找。??????????

      /pattern/+number?將光標(biāo)停在包含pattern的行后面第number行上。?

      /pattern/-number?將光標(biāo)停在包含pattern的行前面第number行上。?

      %?移到匹配的"()"或"{}"上。??????????

    下面是在文本輸入模式下用來輸入文本的子命令(用戶可在任何時(shí)候按Escape返回到命令模式):?

      a?在光標(biāo)之后開始輸入文本。??????????

      A在行尾開始輸入文本。??????????

      i在光標(biāo)之前開始輸入文本。??????????

      I在行首第一個(gè)非空白字符前輸入文本。??????????

      o在光標(biāo)所在行后插入一空行。??????????

      O在光標(biāo)所在行前插入一空行。??????????

    下面是在命令模式下改變文本所使用的子命令(用戶可在任何的時(shí)候按Escape鍵返回到命令模式):?

      cc或S?修改一整行。??????????

      C?改變一行光標(biāo)位置以后的部分。??????????

      cw?改變光標(biāo)所在單詞。??????????

      dd刪除當(dāng)前行。??????????

      D?刪除光標(biāo)所在行光標(biāo)后面的內(nèi)容。??????????

      dw刪除光標(biāo)所在的單詞。??????????

      J?把下一行內(nèi)容加到本行行尾。??????????

      rc把光符所在字符替換成c?.??????????

      R?覆蓋本行內(nèi)容。??????????

      u恢復(fù)上一次的修改。??????????

      x刪除光標(biāo)所在的字符。??????????

      ~?改變光標(biāo)所在出字符的大小寫。??????????

      .?重復(fù)上一個(gè)*作。??????????

      <<把當(dāng)前行移到左邊。??????????

      >>把當(dāng)前行移到右邊。??????????

    下面是用于文件中拷貝文本的字命令:??????????

      p?將緩沖區(qū)內(nèi)容取到光標(biāo)所在行的下面一行。??????????

      P?將緩沖區(qū)內(nèi)容取到光標(biāo)所在行的上面一行。??????????

      "bd?將文本刪除至有名緩沖區(qū)b?.??????????

      "bp?張貼有名緩沖區(qū)b中內(nèi)容。??????????

      yy把當(dāng)前行放入緩沖區(qū)。??????????

      Y?把當(dāng)前行放入緩沖區(qū)。??????????

      Yw把光標(biāo)所在的單詞放入緩沖區(qū)。??????????

    下面是用于保存文件的子命令:??????????

      :w?回寫修改后的文件。??????????

      :w?filename?當(dāng)filename不存在時(shí),把修改后的文件存為文件filename?,當(dāng)文件filename?
    存在時(shí),報(bào)錯(cuò)。?

      !w?filename?如果文件filename存在時(shí),把修改后的文件保存為文件filename?.?

    下面列出了在vi編輯的多個(gè)文件之間切換所用的子命令:??????????

      :n開始編輯vi激活的文件列表中的下一個(gè)文件。??????????

      :n?filenames?指定將被編輯的新的文件列表。??????????

    下面列出了用于在當(dāng)前文件和另外一個(gè)文件間切換的子命令:??????????

      :e?filename?使用filename激活vi?(在vi中裝入另一個(gè)文件filename)。?

      e!重新裝入當(dāng)前文件,若當(dāng)前文件有改動(dòng),則丟棄以前的改動(dòng)。??????????

      :e+filename?使用filename激活vi?,并從文件尾部開始編輯。?

      :e+number?filename?使用filename激活vi?,并在第number行開始編輯。?

      :e#?開始編輯另外一個(gè)文件。??????????

    下面是在本文件中加入其他文件代碼所使用的子命令:??????????

      :r?filename讀取filename文件,并將其內(nèi)容加到當(dāng)前文件后。???

      :r?!?command執(zhí)行command文件,并將其輸出加到當(dāng)前文件后。???

    下面是vi中其他的子命令:??????????

      ctrl+g?取得正在編輯文件的有關(guān)信息。??????????

      :sh啟動(dòng)sh?,從sh中返回可用exit或ctrl+d?.??????????

      :!?Command?執(zhí)行命令command?.??????????

      !!重新執(zhí)行上次的:!?Command子命令。??????????

      :q退出vi?,若用戶對編輯的文件有所修改,系統(tǒng)不會(huì)讓用戶使用q命令退出。???

      :q!退出vi而不管是否對文件有改動(dòng)。??????????

      ZZ或:wq?保存對文件的修改并退出vi?.??????????

      用戶可在一個(gè)特殊的文件.exrc中定義特殊的vi命令。在vi中使用這些命令時(shí),必須在該?
    命令前加上一個(gè)冒號(hào)(?:)?。

    posted @ 2006-05-13 15:13 月亮 閱讀(341) | 評(píng)論 (0)編輯 收藏

    精通Log4j

    ?log4j雖然總的來說是比較容易使用的,但是要是想比較精通的操縱它還是有很多地方值得探討的。
    ??? 這幾天有空,把項(xiàng)目中大家用到的log4j實(shí)現(xiàn)的功能分了一下類,大致分為下面三類:
    ??? <1>所有的日志信息都輸出到log.log.
    ??? <2>對于一些特殊的日志(如啟動(dòng)時(shí)候的日志),輸出到log/startup/startup.log.
    ??? <3>對于某些特殊包下面的日志,如com.aspire包下面的error信息都輸出到error.log???
    ??? 有了這幾個(gè)功能,相信對于大部分的系統(tǒng)都是夠用的了,下面這個(gè)例子就是實(shí)現(xiàn)了這幾個(gè)功能:
    ??? (至于其他的一些配置,如格式這些的就不說明,有很多這種資料)
    ???
    ??? ***********? log4j 配置文件? ************???
    ???
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration xmlns:log4j="

    <appender name="file" class="org.apache.log4j.RollingFileAppender">
    ?<param name="File" value="log.log"/>
    ?<layout class="org.apache.log4j.PatternLayout">
    ?<param name="ConversionPattern" value=" %d{ISO8601} [%c]- %m%n"/>
    ?</layout>
    </appender>

    <appender name="error" class="org.apache.log4j.RollingFileAppender">
    ??<param name="File" value="error.log"/>
    ??<param name="MaxBackupIndex" value="300"/>
    ??<param name="Encoding" value="GB2312"/>
    ??<param name="MaxFileSize" value="20MB"/>
    ??<layout class="org.apache.log4j.PatternLayout">
    ???<param name="ConversionPattern" value="%d{ISO8601} %p [%c] - [%m]%n"/>
    ??</layout>
    ??? <filter class="org.apache.log4j.varia.LevelRangeFilter">
    ??<!-- 過濾,只記錄error信息-->
    ??<param name="LevelMin" value="error"/>
    ??<param name="LevelMax" value="error"/>
    ??<param name="acceptOnMatch" value="true"/>
    ??? </filter>
    </appender>
    <appender name="startup" class="com.aspire.TimeSizeRollingFileAppender">
    ??<!--該類使自己從FileAppender派生,可以自己控制輸出文件的路徑 -->
    ??<param name="File" value="log/startup/startup.log" />
    ??<param name="Encoding" value="GBK" />
    ??<layout class="org.apache.log4j.PatternLayout">
    ???<param name="ConversionPattern" value="%m %d{ISO8601}- %m%n %p %l%n" />
    ??</layout>
    </appender>

    <logger name="biz.startup">
    <!--Logger logger = Logger.getLogger("biz.startup") 可以這樣來調(diào)用本logger-->
    ??<level value="debug" />
    ??<appender-ref ref="startup" />
    </logger>

    <logger name="com.aspire" additivity="false">
    <!--Log log = LogFactory.getLog(TestLog4j.class) 此時(shí)如果TestLog4j
    ??? 位于com.aspire包下面,那么使用本logger
    ?-->
    ??<level value="debug"/>
    ??<appender-ref ref="error"/>
    </logger>
    <root>
    <level value="info"/>
    <!-- 默認(rèn)輸出到log.log-->
    <appender-ref ref="file"/>
    </root>
    </log4j:configuration>

    ***********? log4j 配置文件結(jié)束 ************

    **********? 派生的TimeSizeRollingFileAppender類*****
    package com.aspire;

    import org.apache.log4j.FileAppender;
    import org.apache.log4j.spi.ErrorCode;
    import java.io.File;
    import java.io.IOException;

    public class TimeSizeRollingFileAppender
    ??? extends FileAppender
    ??? implements ErrorCode {

    ? private final static String FS = System.getProperty("file.separator");
    ? public TimeSizeRollingFileAppender() {
    ? }
    ? public void setFile(String file) {
    ??? String val = file.trim();
    ??? File domain = new File(".");
    ??? try {
    ????? fileName = domain.getCanonicalPath() + FS + val;
    ??? }
    ??? catch (IOException ex) {
    ????? ex.printStackTrace();
    ??? }
    ? }
    }

    ********** TimeSizeRollingFileAppender 類結(jié)束 ******

    ************ 調(diào)用示例 TestLog4j類 **************
    package com.aspire;

    import org.apache.log4j.Logger;
    import org.apache.log4j.LogManager;
    import org.apache.commons.logging.LogFactory;
    import org.apache.log4j.xml.DOMConfigurator;
    import org.apache.commons.logging.Log;

    public class TestLog4j {
    ? private Logger logger = Logger.getLogger("biz.startup");
    ? private Log log = LogFactory.getLog(TestLog4j.class);

    ? public static void config(){
    ??? DOMConfigurator.configure("conf\\log4jConf.xml");
    ? }
    ? public void Test(){
    ??? /**
    ???? * error > warn > info > debug
    ???? */
    ??? logger.error("*****error*****");
    ??? logger.debug("****debug*****");
    ??? logger.warn("*****warn******");
    ??? logger.info("*****info******");
    ??? log.error("中華之崛起!");
    ? }
    ? public static void main(String [] argv){
    ??? TestLog4j t = new TestLog4j();
    ??? TestLog4j.config();
    ??? t.Test();
    ? }
    }

    ***************? TestLog4j end ***********

    posted @ 2006-04-26 12:59 月亮 閱讀(400) | 評(píng)論 (0)編輯 收藏

    23種經(jīng)典的設(shè)計(jì)模式_Prototype模式(原形模式)

    很多時(shí)候,創(chuàng)建對象的時(shí)候,只是在某些屬性值上有區(qū)別,而大部分都很相似,但是這樣的對象的初始化相對來說比較復(fù)雜,而且
    需要耗費(fèi)較長的時(shí)間或資源,這種情況下,我們可以考慮使用Prototype模式。我覺得這種模式實(shí)用于這樣的情況:如果該類的用戶對于該
    類的對象是怎么創(chuàng)建的,對類的內(nèi)部結(jié)構(gòu)這些都不關(guān)心的情況,并且該類的創(chuàng)建過程比較費(fèi)時(shí)或資源時(shí),可以考慮使用該模式。下面是該模式的
    一個(gè)例子:

    Prototype 類

    package com.moonsoft;

    import java.lang.Cloneable;
    public class Prototype implements Cloneable {
    ?
    ?public String myname;
    ?
    ?Prototype(){
    ??System.out.println("start:"+System.currentTimeMillis());
    ??for( int i=0; i< 9999999; i++){???
    ??}
    ??System.out.println("end:"+System.currentTimeMillis());
    ?}
    ?
    ?public Object clone(){
    ??Object o = null;
    ??try{
    ???o = super.clone();???
    ??}
    ??catch(CloneNotSupportedException ex){
    ???ex.printStackTrace();
    ??}
    ??return o;
    ?}
    ?
    ?public void whoami(){
    ??System.out.println(myname);
    ?}
    }


    測試類

    package com.moonsoft;

    public class Test {
    ?
    ?public static void main(String [] argv){
    ??Prototype? p = new Prototype();
    ??p.whoami();
    ??p.myname = "loucy";
    ??Prototype? p1 = (Prototype)p.clone();
    ??p1.whoami();?
    ??
    ?}
    }

    posted @ 2006-04-16 15:21 月亮 閱讀(556) | 評(píng)論 (0)編輯 收藏

    小技巧_jsp緩存問題的解決

    如果一直為jsp的緩存問題困擾的話,可以試試在jsp中加入以下幾句話:

    <head>
    <meta http-equiv="Cache-Control" content="max-age=0" forua="true" />
    <meta http-equiv="Cache-Control" content="no-cache" forua="true"/>
    <meta http-equiv="Cache-Control" content="must-revalidate" forua="true" />
    </head>

    max-age=30 就表示緩存的最長存在時(shí)間是30s,no-cache表示無緩存,must-revalidate表示每次訪問必須重新驗(yàn)證是否有更新!

    posted @ 2006-04-04 15:11 月亮 閱讀(666) | 評(píng)論 (0)編輯 收藏

    用Java實(shí)現(xiàn)的Html web服務(wù)器

    ? 馬上就要開始轉(zhuǎn)到新的項(xiàng)目組,做一個(gè)全新的項(xiàng)目了,對于HTTP協(xié)議需要一定的了解,所以周末自己用Java寫了一個(gè)簡單的web服務(wù)器試試,只能實(shí)現(xiàn)簡單的html文件瀏覽。

    主要包括三個(gè)類:WebServer(監(jiān)聽瀏覽器請求),SocketThread(處理瀏覽器請求的進(jìn)程),StringUtil(實(shí)現(xiàn)一些公共的操作),下面是三個(gè)類的代碼.


    ----WebServer----
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;

    public class WebServer {
    ?
    ?public static void main(String[] argv) throws IOException {
    ??ServerSocket servSocket = new ServerSocket(StringUtil.LISTENING_PORT);
    ??try {
    ???while (true) {
    ????Socket socket = servSocket.accept();
    ????new SocketThread(socket).start();
    ???}
    ??} finally {
    ???servSocket.close();
    ??}
    ?}
    }

    ---SocketThread------
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.PrintStream;
    import java.io.Writer;
    import java.net.Socket;

    public class SocketThread extends Thread {
    ?private Socket socket = null;

    ?public SocketThread(Socket s) {
    ??this.socket = s;
    ?}

    ?public void run() {
    ??try {
    ???if (socket == null) {
    ????throw new Exception("==>SOCKET為空<==");
    ???}
    ???BufferedReader reader = new BufferedReader(new InputStreamReader(
    ?????socket.getInputStream()));
    ???String fileName = "";
    ???while (true) {
    ????String str = reader.readLine();
    ????if (str == null || str.length() <= 0) {
    ?????break;
    ????}
    ????//System.out.println("===>"+str);
    ????if (StringUtil.isGetRequestInfo(str)) {
    ?????fileName = StringUtil.getFileName(str);
    ?????break;
    ????}
    ???}
    ???//System.out.println("===>客戶機(jī)IP==>"+socket.getInetAddress().toString());
    ???//System.out.println("===>客戶機(jī)端口==>"+socket.getPort());???
    ???/*
    ??? BufferedWriter writer = new BufferedWriter(new
    ??? OutputStreamWriter(socket.getOutputStream()));
    ??? */
    ???PrintStream outputStream = new PrintStream(socket.getOutputStream());
    ???File file = new File(StringUtil.WEBPATH + fileName);
    ???if (file.exists()) { //如果文件存在
    ????StringUtil.sendHttpHead(outputStream, file);
    ????StringUtil.sendFile(outputStream, file);
    ????outputStream.flush();
    ???} else { //文件沒找到,返回404頁面
    ????StringUtil.send404Page(outputStream);
    ????outputStream.flush();
    ???}
    ??} catch (Exception e) {
    ???e.printStackTrace();
    ??} finally {
    ???try {
    ????socket.close();
    ???} catch (Exception e) {
    ???}
    ??}
    ?}

    }



    ---StringUtil-----
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.PrintStream;

    /**
    ?* @author xiaoliang
    ?*/
    public class StringUtil {

    ?// 服務(wù)器監(jiān)聽的端口
    ?public static final int LISTENING_PORT = 8080;

    ?// 服務(wù)器文件的位置
    ?public static final String WEBPATH = "E:";

    ?/**
    ? * 判斷該字符串是不是瀏覽器發(fā)送過來的請求頭信息
    ? * @param str
    ? * @return
    ? */
    ?public static boolean isGetRequestInfo(String str) {
    ??if (str == null || str.length() <= 0)
    ???return false;
    ??boolean isGetStr = true;
    ??if (str.indexOf("GET") != 0) {
    ???isGetStr = false;
    ??}
    ??if (str.indexOf("HTTP/") <= 0) {
    ???isGetStr = false;
    ??}
    ??return isGetStr;
    ?}

    ?/**
    ? * 獲得請求信息中的文件名,默認(rèn)為index.html
    ? *
    ? * @param str
    ? * @return
    ? */
    ?public static String getFileName(String str) {
    ??String fileName = "index.html", s;
    ??int httpIndex = str.lastIndexOf("HTTP/");
    ??s = str.substring(3, httpIndex);
    ??s = s.trim();
    ??if (s != null && s.length() > 0 && s.indexOf(".") > 0) {
    ???fileName = s;
    ??}
    ??return fileName;
    ?}

    ?/**
    ? * 發(fā)送文件到客戶端
    ? *
    ? * @param out
    ? * @param file
    ? */
    ?public static void sendFile(PrintStream out, File file) {
    ??try {
    ???DataInputStream in = new DataInputStream(new FileInputStream(file));
    ???int length = (int) file.length();
    ???byte[] buffer = new byte[length];
    ???in.readFully(buffer);
    ???out.write(buffer, 0, length);
    ???in.close();
    ??} catch (Exception e) {
    ???e.printStackTrace();
    ??}
    ?}

    ?/**
    ? * 發(fā)送返回的頭部信息
    ? * @param out
    ? */
    ?public static void sendHttpHead(PrintStream outputStream, File file) {
    ??try {
    ???outputStream.println("HTTP/1.0200OK");
    ???outputStream.println("Content_Type:text/htm1");
    ???outputStream.println("Content_Length:" + file.length());
    ???outputStream.println("Server:moon webserver 1.0");
    ???outputStream.println("");
    ??} catch (Exception e) {
    ???e.printStackTrace();
    ??}
    ?}

    ?/**
    ? * 返回404頁面
    ? * @param out
    ? */
    ?public static void send404Page(PrintStream out) {
    ??try {
    ???out.println("HTTP /1.0 404 no found");
    ???out.println("Content_type:text/html");
    ???out.println("");
    ???out.println("Error404:file not found!");
    ??} catch (Exception e) {
    ???e.printStackTrace();
    ??}
    ?}
    ?
    ?public static void main(String[] argv) {
    ??String str = "GET /11.html HTTP/1.1";
    ??str = StringUtil.getFileName(str);
    ??System.out.println("==>" + str + "<==");
    ??File file = new File(StringUtil.WEBPATH + str);
    ??if (file.exists()) {
    ???System.out.println("exists");
    ??} else {
    ???System.out.println("not exists");
    ??}
    ?}

    }

    posted @ 2006-03-28 13:55 月亮 閱讀(454) | 評(píng)論 (0)編輯 收藏

    Apache FileUpload 使用

    FileUpload 組件使用注意:
    1>
    首先創(chuàng)建一個(gè)HTML頁面。注意,凡是要上載文件的表單都必須設(shè)置enctype屬性,且屬性的值必須是multipart/form-data,同時(shí)請求方法必須是POST.
    <form name="myform" action="fileuploaddemo.jsp"  method="post" enctype="multipart/form-data">
     
    2>commons-fileupload-1.1.jar和commons-io-1.1.jar 兩個(gè)包都要引入,
    因?yàn)樵趐arseRequest(request)的類有關(guān)繼承于DiskFileItem類。

    3>示例
          //檢查表單是否正確
          boolean isMultipart = FileUpload.isMultipartContent(request);
          DiskFileItemFactory  factory = new DiskFileItemFactory();
          ServletFileUpload upload = new ServletFileUpload(factory);
          //文件最大,設(shè)為-1表示不受限制
          upload.setSizeMax(4096);
          //解析請求,把解析的結(jié)果放在一個(gè)List里面
          List items = upload.parseRequest(request);
          //緩存大小,設(shè)為-1表示不受限制
          factory.setSizeThreshold(4096);
          //設(shè)置臨時(shí)目錄
          factory.setRepository(new File("D:\\temp"));
          Iterator iter = items.iterator();
          while( iter.hasNext() ){
            FileItem item  = (FileItem)iter.next();
            //檢查是一個(gè)普通的表單域還是File組件
            if( !item.isFormField() ){
              System.out.println("FileName:==>"+item.getName());
              System.out.println("FieldName:==>"+item.getFieldName());
              System.out.println("Size:==>"+item.getSize());
              //item.getName 返回的是完整的文件名,如:E:\\xx\11.doc
              //所以這里用一個(gè)fullFile來取文件名
              File fullFile  = new File(item.getName());
              File uploadedFile = new File("D:\\ftp\\",fullFile.getName());
              item.write(uploadedFile);
            }
          }

    posted @ 2006-03-06 12:33 月亮 閱讀(1849) | 評(píng)論 (1)編輯 收藏

    EJB QL

    從一個(gè)表users中查詢記錄,如果是寫成
    select  i from  users as  i  where i.name=?1則編譯EJB的時(shí)候會(huì)報(bào)錯(cuò),但是如果把users 首字母大寫就OK了。
    select  i from  Users as  i  where i.name=?1

    posted @ 2006-02-27 23:34 月亮 閱讀(245) | 評(píng)論 (0)編輯 收藏

    EJb 會(huì)話Bean

    在EJB容器中,SessionBean主要有兩種:無狀態(tài)(stateless)和有狀態(tài)(stateful)。
    1、無狀態(tài)EJB,類似Servlet,它只提供一個(gè)引用(Bean instance),被所有客戶端使用,不保留某個(gè)客戶的單獨(dú)信息。
    例如:在某無狀態(tài)EJB中,有一個(gè)數(shù)據(jù)成員(變量) i_count (整型,用于訪問計(jì)數(shù),初始值為0,訪問一次累加1),它是公共的。某客戶端訪問后,值累加為1。另一個(gè)客戶端訪問時(shí)是已經(jīng)變化了的值為1。

    2、有狀態(tài)EJB,類似數(shù)據(jù)庫的Connect鏈接,也類似線程守護(hù),它提供引用池(Bean instance pool),每個(gè)客戶端會(huì)有單獨(dú)的信息。
    例如:在某有狀態(tài)EJB中,有一個(gè)數(shù)據(jù)成員(變量) i_count (整型,用于訪問計(jì)數(shù),初始值為0,訪問一次累加1),它對每個(gè)客戶端來說是隔離的。某客戶端訪問后,值累加為1。另一個(gè)客戶端訪問時(shí)還是原來的值為0。

    這里提到的數(shù)據(jù)成員(變量) i_count ,在EJB規(guī)范中稱作:conversational state 。對它的要求也很多的,例如類型為 Serializable objects。還有,還要在ejbActivate(),ejbPassivate(),ejbRemove()等生命周期約定的方法中處理。詳見EJB規(guī)范吧。

    我的感想:在看第一遍書時(shí),還一點(diǎn)感覺都沒有,根本就看不明白SessionBean中的session與Servlet容器中的session有什么區(qū)別。
    動(dòng)手編程后,才感覺到EJB只是比Servlet更規(guī)范,更重量而已。真正的區(qū)別就是接口協(xié)議一個(gè)是基于HTTP,一個(gè)是基于RMI/IIOP。Servlet與無狀態(tài)的SessionBean在Session上是一樣的控制。Servlet中的Session對象與有狀態(tài)的SessionBean是一樣的控制。
    對于應(yīng)用,例如有一個(gè)購物車,要記錄正在采購的物品信息,沒有EJB時(shí),我們一般是存在Servlet容器中的session中。有了EJB,則可以存儲(chǔ)在有狀態(tài)的SessionBean中,并且該次有狀態(tài)的sessionBean的instance還得保存在Servlet的session中。這樣的好處是:至少可以減輕Servlet容器的負(fù)載。



    轉(zhuǎn)自:
    http://zengabo.blogchina.com/blog/527365.html

    posted @ 2006-02-22 16:35 月亮 閱讀(253) | 評(píng)論 (0)編輯 收藏

    Ibatis示例


    1.將ibatis 的jar 包添加到工程中

    2.先新建一個(gè)xml文件 SqlMap.xml,在這個(gè)文件中定義使用了哪些ibatis資源文件
    <?xml version="1.0" encoding="gb2312"?>
    <!DOCTYPE sql-map-config PUBLIC "-//iBATIS.com//DTD SQL Map Config 1.0//EN"
        "<sql-map-config>
      <sql-map  resource="com/montersoft/ibatis/common/monter.xml"/>
    </sql-map-config>

    3.定義資源文件monter.xml
    <?xml version="1.0" encoding="gb2312"?>
    <!DOCTYPE sql-map
        PUBLIC "-//iBATIS.com//DTD SQL Map 1.0//EN"
        "
    <sql-map name="monter">
       <result-map name="monterInfo" class="java.util.HashMap">
         <property name="id"  column="id" type="VARCHAR"/>
         <property name="name" column="name" type="VARCHAR"/>
         <property name="age"  column="age"  type="NUMBERIC"/>
       </result-map>  
       <dynamic-mapped-statement name="monter_getByPk" result-map="monterInfo">
       select id,name,age from monter where id = #id#
       </dynamic-mapped-statement>
    </sql-map>

    **注意dynamic-mapped-statement的name 必須唯一

    4.定義一個(gè)公共類來生成SqlMap
    package com.montersoft.ibatis.common;
    import java.io.Reader;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import com.ibatis.common.resources.Resources;
    import com.ibatis.db.sqlmap.SqlMap;
    import com.ibatis.db.sqlmap.XmlSqlMapBuilder;
    public class SqlMapUtil { 
     private static Log loger = LogFactory.getLog(SqlMapUtil.class);
     public  static SqlMap  sqlMap ; 
     public static SqlMap loadSqlMap(){
      Reader reader = null;
      try{
       reader = Resources.getResourceAsReader("com/montersoft/ibatis/common/SqlMap.xml");
       return XmlSqlMapBuilder.buildSqlMap(reader);
      }
      catch(Exception e){   
       loger.error("there is a error=>"+e.getMessage());
      }
      return null;
     } 
     public static SqlMap getSqlMap(){
      if( sqlMap == null )
       sqlMap = loadSqlMap();
      return sqlMap;
     } 
    }
    5.再新建DAO,Vo,
    public interface  IVO { 
    }
    public class MonterVo implements IVO{ 
     public String id ;
     public String name;
     public int age;
     ...省去 get ,set 方法
    }
    public class MonterDao { 
       public IVO getBkPK(Connection conn,IVO vo) throws Exception{
        try{    
        Object map  =  SqlMapUtil.getSqlMap().
           getMappedStatement("monter_getByPk").executeQueryForObject(conn,vo);
        return   copyMap2Vo(map);
        }
        catch(Exception e){       
            throw new Exception(e.getMessage());
        }
       }  
       private IVO copyMap2Vo(Object map){
        MonterVo vo = new MonterVo();
      try{
       BeanUtils.copyProperties(vo,map);
      }
      catch(Exception e){
       e.printStackTrace();
      }
      return vo;
     }
    }

    6.至此就建立了一個(gè)簡單的ibatis示例.

    posted @ 2006-01-06 16:39 月亮 閱讀(329) | 評(píng)論 (0)編輯 收藏

    通過weblogic的數(shù)據(jù)源獲得數(shù)據(jù)庫連接的方法

    通過weblogic的數(shù)據(jù)源獲得數(shù)據(jù)庫連接的方法:

    package com.moonsoft.datasource;

    import javax.naming.NamingException;
    import java.util.Hashtable;
    import javax.naming.InitialContext;
    import java.sql.Connection;
    import javax.sql.DataSource;
    import java.sql.SQLException;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;

    public class TestDataSource {

      public static String WEB_URL = "t3://localhost:9000";
      public static String DATA_SOURCE = "JDBCDS";
      public static String weblogic_context_factory =
          "weblogic.jndi.WLInitialContextFactory";
      public TestDataSource() {
      }
      public static Object lookUp() throws NamingException {
        Hashtable env = new Hashtable();
        env.put(InitialContext.INITIAL_CONTEXT_FACTORY, weblogic_context_factory);
        env.put(InitialContext.PROVIDER_URL, WEB_URL);
        InitialContext tempContext = new InitialContext(env);
        return tempContext.lookup(DATA_SOURCE);
      }
      public static Connection getConnection() throws SQLException {
        Connection conn = null;
        try {
          DataSource ds = (DataSource) lookUp();
          if (ds == null) {
            throw new SQLException("查詢到空數(shù)據(jù)源!");
          }
          conn = ds.getConnection();
        }
        catch (NamingException ex) {
          ex.printStackTrace();
        }
        return conn;
      }
      public static void releaseConnection(Connection conn, PreparedStatement sta,
                                           ResultSet rs) {
        try {
          if (rs != null) {
            rs.close();
          }
          if (sta != null)
            sta.close();
          if (conn != null)
            conn.close();
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
      }
      public static void testSearch() {
        Connection conn = null;
        PreparedStatement sta = null;
        ResultSet rs = null;
        try {
          conn = getConnection();
          String sql = "select * from admin_config where config_name like ?";
          sta = conn.prepareStatement(sql);
          sta.setString(1,"%Sms%");
          rs = sta.executeQuery();
          if (rs != null) {
            while (rs.next()) {
              System.out.println(rs.getString(1));
            }
          }
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
        finally {
          releaseConnection(conn,sta,rs);
        }
      }
      public static void main(String [] argv){
        testSearch();
      }
    }

    posted @ 2006-01-05 10:51 月亮 閱讀(1239) | 評(píng)論 (0)編輯 收藏

    一個(gè)設(shè)計(jì)中使用比較多的模式

    如果是在需求還沒確定或者是在兩個(gè)類實(shí)現(xiàn)相近功能時(shí)候,會(huì)大量使用下面的方式:
    --抽象類,注意其中的newInstance方法的實(shí)現(xiàn)
    package com.moonsoft.design;
    public  abstract class Moon {
      public static Moon newInstance(String classStr){
        Class re;
        try {
          re =  Class.forName(classStr);
          return (Moon)re.newInstance();
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
        return null;
      }
      public abstract void  println();
    }
    --從Moon類派生出來的一個(gè)字類,提供println方法的一種實(shí)現(xiàn)方式
    package com.moonsoft.design;
    public class Moon1 extends Moon {
      public void println(){
        System.out.println("I am moon1");
      }
      public void myprintln(){
        System.out.println("I am moon1 myprintln");
      }
    }
    --從Moon類派生出來的另一個(gè)字類,提供println方法的另一種實(shí)現(xiàn)方式
    package com.moonsoft.design;
    public class Moon2 extends Moon {
       public void println(){
        System.out.println("I am moon2!");
      }
    }
    --調(diào)用
     Moon moon = Moon.newInstance("com.moonsoft.design.Moon1");
     moon.println();
     或
     Moon moon = Moon.newInstance("com.moonsoft.design.Moon2");
     moon.println();

    posted @ 2006-01-04 16:41 月亮 閱讀(101) | 評(píng)論 (0)編輯 收藏

    JSP標(biāo)簽的使用方法


    如要在JSP頁面上有一個(gè)鏈接,Url值是通過參數(shù)輸入的,用JSP標(biāo)簽的實(shí)現(xiàn)步驟(當(dāng)然實(shí)際中不會(huì)用標(biāo)簽來完成這么簡單的功能):

    <一>.先從javax.servlet.jsp.tagext.BodyTagSupport派生一個(gè)新的類,并重載它的doStartTag()方法.如果是想要傳入?yún)?shù)的話,則還要在Bean中加入想要的變量,如這里要傳入一個(gè)url值,所以添加一個(gè)參數(shù):linkUrl. 最后代碼如下:

    package com.moonsoft.jsptag;
    import javax.servlet.jsp.tagext.BodyTagSupport;
    import javax.servlet.jsp.JspTagException;
    import javax.servlet.jsp.JspException;
    public class UrlLinkTag extends BodyTagSupport  {
      private String linkUrl;
      public UrlLinkTag() {
      }
      public String getLinkUrl() {
        return linkUrl;
      }
      public void setLinkUrl(String linkUrl) {
        this.linkUrl = linkUrl;
      }
      public int doStartTag() throws JspException{
        try {
          this.pageContext
              .getOut().print("<a href=\'"+linkUrl+"\' >"+linkUrl+"</a>");
        }
        catch (Exception ex) {
          ex.printStackTrace();
        }
        return 0;
      }
    }

    <二>新建一個(gè)tld文件,內(nèi)容如下:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
     " <taglib>
            <tlibversion>1.0</tlibversion>
     <jspversion>1.1</jspversion>
     <shortname>buttons</shortname>
     <uri>http://www.borland.com/jbuilder/internetbeans.tld</uri>
     <info>
     JSP tag extensions for InternetBeans Express
      </info>
        <tag>
     <name>urllink</name>
     <tagclass>com.moonsoft.jsptag.UrlLinkTag</tagclass>
     <bodycontent>jsp</bodycontent>
     <attribute>
      <name>linkUrl</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
     </attribute>
        </tag>
       </taglib>
      
    <三>在web.xml中引入這個(gè)taglib,在其中加入:

    <taglib>
        <taglib-uri>/moon</taglib-uri>
        <taglib-location>/WEB-INF/classes/com/moonsoft/jsptag/UrlLinkTag.tld</taglib-location>
    </taglib>


    <四>在jsp中引入這個(gè)標(biāo)簽
    <%@ taglib uri="/moon" prefix="mylinkurl" %>
    這里uri是和web.xml中配置的taglib-uri對應(yīng)的,prefix值只是在本jsp頁面作為標(biāo)示用.

    下面就可以在jsp中使用這個(gè)標(biāo)簽了:

    <mylinkurl:urllink linkUrl="

    這里面的mylinkurl為在本jsp頁面中設(shè)置的prefix值,urllink為tld文件中tag name,linkUrl為輸入的參數(shù)

    這樣就在jsp頁面上加入了一個(gè):
    <a >http://www.baidu.com</a>鏈接

    posted @ 2005-12-29 13:47 月亮 閱讀(1430) | 評(píng)論 (0)編輯 收藏

    Java Excel 使用攻略

     現(xiàn)在正在做的項(xiàng)目中涉及大量的Excel文件導(dǎo)出導(dǎo)入操作,都是使用Java Excel來操作。

    Java Excel是一開放源碼項(xiàng)目,通過它Java開發(fā)人員可以讀取Excel文件的內(nèi)容、創(chuàng)建新的Excel文件、更新已經(jīng)存在的Excel文件。下面我寫了一個(gè)簡單的例子,展示基本的讀取,新建,更新(包括常見格式的設(shè)置:字體,顏色,背景,合并單元格),拷貝操作,有這些其實(shí)已經(jīng)基本足夠應(yīng)付大部分問題了。下面是例的源代碼:

    import java.io.*;
    import java.util.Date;

    import jxl.*;
    import jxl.format.Colour;
    import jxl.format.UnderlineStyle;
    import jxl.read.biff.BiffException;
    import jxl.write.*;
    import jxl.format.UnderlineStyle;
    import jxl.format.CellFormat;;

    public class OperateExcel {
     
     /**
      * Read data from a excel file
      */
     public static void  readExcel(String excelFileName){
      Workbook  rwb = null;  
      try{
       InputStream stream = new FileInputStream(excelFileName);
       rwb = Workbook.getWorkbook(stream);
       Sheet  sheet = rwb.getSheet(0);
       Cell   cell  = null;
       int columns = sheet.getColumns();
       int rows    = sheet.getRows();
       for( int i=0 ; i< rows ; i++ )
        for( int j=0 ; j< columns ; j++){
         //attention: The first parameter is column,the second parameter is row.  
         cell = sheet.getCell(j,i);    
         String str00 = cell.getContents();
         if( cell.getType() == CellType.LABEL )
           str00 += " LAEBL";
         else if( cell.getType() == CellType.NUMBER)
           str00 += " number";
         else if( cell.getType() == CellType.DATE)
           str00 += " date"; 
         System.out.println("00==>"+str00);
        } 
       stream.close();
      }
      catch(IOException e){  
       e.printStackTrace();
      }
      catch(BiffException e){
       e.printStackTrace();
      } 
      finally{  
       rwb.close();
      }
     }
     /**
      * create a new excelFile
      * @param excelFileName create name
      */
     public static void createExcelFile(String excelFileName){
      try{
       WritableWorkbook wwb = Workbook.createWorkbook(new File(excelFileName));
       WritableSheet     ws  = wwb.createSheet("sheet1",0);
       //also,The first parameter is  column,the second parameter is row.
       // add normal label data
       Label label00 = new Label(0,0,"Label00");
       ws.addCell(label00);
       //add font formating data   
       WritableFont  wf = new WritableFont(WritableFont.TIMES, 18, WritableFont.BOLD , true);
       WritableCellFormat wff = new WritableCellFormat(wf);
       Label label10 = new Label(1,0,"Label10",wff);
       ws.addCell(label10);
       //add color font formating data
       WritableFont wf_color = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false,UnderlineStyle.DOUBLE_ACCOUNTING,Colour.RED);
       WritableCellFormat wff_color = new WritableCellFormat(wf_color);
       wff_color.setBackground(Colour.GRAY_25); //set background coloe to gray  
       Label label20 = new Label(2,0,"Label20",wff_color);   
       ws.addCell(label20);
       
       //合并單元格
       WritableFont wf_merge = new WritableFont(WritableFont.ARIAL,10,WritableFont.NO_BOLD,false,UnderlineStyle.DOUBLE_ACCOUNTING,Colour.GREEN);
       WritableCellFormat wff_merge = new WritableCellFormat(wf_merge);
       wff_merge.setBackground(Colour.BLACK);
       Label label30 = new Label(3,0,"Label30",wff_merge);   
       ws.addCell(label30);
       Label label40 = new Label(4,0,"Label40");
       ws.addCell(label40);
       Label label50 = new Label(5,0,"Label50");
       ws.addCell(label50);
         //合并 (0,3) (4,0)
         //attention : 如果合并后面的列不為空,那么就把后面格的內(nèi)容清空,格式也是按前一個(gè)單元格的格式
       ws.mergeCells(3,0,4,0);
       
       //添加Number格式數(shù)據(jù)
       jxl.write.Number labelN = new jxl.write.Number(0, 1, 3.1415926);
       ws.addCell(labelN);
       
       //添加帶有formatting的Number對象
       jxl.write.NumberFormat nf = new jxl.write.NumberFormat("#.##");
       jxl.write.WritableCellFormat wcfN = new jxl.write.WritableCellFormat(nf);
       jxl.write.Number labelNF = new jxl.write.Number(1, 1, 3.1415926, wcfN);
       ws.addCell(labelNF);
       
       //添加Boolean對象
       jxl.write.Boolean labelBoolean = new jxl.write.Boolean(2,1,false);
       ws.addCell(labelBoolean);
       
       //添加DateTime對象
       DateTime labelDT = new DateTime(3,1,new Date());
       ws.addCell(labelDT);
       
       //添加帶有格式的DataTime數(shù)據(jù)
       DateFormat dtf = new DateFormat("yyyy-MM-dd hh:mm:ss");
       WritableCellFormat wcfDt = new WritableCellFormat(dtf);   
       wcfDt.setBackground(Colour.YELLOW);
       DateTime labelDT_format =  new DateTime(4,1,new java.util.Date(),wcfDt);
       ws.addCell(labelDT_format);
       ws.mergeCells(4,1,5,1); //比較長,用兩列來顯示     
       
       wwb.write();
       wwb.close();
      }
      catch(IOException e){
       e.printStackTrace();
      }
      catch(WriteException e){
       e.printStackTrace();
      }  
     }
     /**
      * 如何更新Excel文件
      * @param fileName
      */
     public static void updateExcel(String fileName){  
      try{
       jxl.Workbook rw = jxl.Workbook.getWorkbook(new File(fileName));
       WritableWorkbook wwb = Workbook.createWorkbook(new File(fileName),rw);
       //這里其實(shí)執(zhí)行的是一次copy操作,把文件先讀到內(nèi)存中,修改后再保存覆蓋原來的文件來實(shí)現(xiàn)update操作
       WritableSheet ws  = wwb.getSheet(0);
       WritableCell wc = ws.getWritableCell(0,0);
       if( wc.getType() == CellType.LABEL){
        Label l = (Label)wc;
        l.setString(wc.getContents()+"_new");
       }
       wwb.write();
       wwb.close();
      }
      catch(IOException e){
       e.printStackTrace();
      }
      catch(WriteException e){
       e.printStackTrace();
      } 
      catch(BiffException e){
       e.printStackTrace();
      }
     }
     /**
      * 如何copy Excel文件
      * @param fileName
      */
     public static void copyExcel(String sourFileName,String destFileName){  
      try{
       jxl.Workbook rw = jxl.Workbook.getWorkbook(new File(sourFileName));
       WritableWorkbook wwb = Workbook.createWorkbook(new File(destFileName),rw);
       wwb.write();
       wwb.close();
      }
      catch(IOException e){
       e.printStackTrace();
      }
      catch(WriteException e){
       e.printStackTrace();
      } 
      catch(BiffException e){
       e.printStackTrace();
      }
     }
     
     public static void main(String [] argv){
      //OperateExcel.readExcel("E:\\test.xls");
      //OperateExcel.createExcelFile("E:\\test1.xls");
      //OperateExcel.updateExcel("E:\\test.xls");
      OperateExcel.copyExcel("E:\\test.xls","E:\\moon.xls");
     }

    }


    posted @ 2005-12-06 15:06 月亮 閱讀(2200) | 評(píng)論 (4)編輯 收藏

    執(zhí)行過程中動(dòng)態(tài)執(zhí)行方法

    在編程中可能回碰到一些到實(shí)際運(yùn)行時(shí)才指定要調(diào)用的方法的需要,最典型的是Struct的DispatchAction類,
    它能根據(jù)用戶頁面請求參數(shù)的不同來調(diào)用不同的方法來處理用戶請求。我下面寫了一個(gè)簡單的例子來簡單演示其
    實(shí)現(xiàn)方法:

    package learn;
    import java.lang.NoSuchMethodException;
    import java.lang.reflect.Method;
    import java.util.Date;

    public class TestMethod{
        protected Class clazz = this.getClass();
        protected Class[] no_parameter = {};  //方法無參數(shù)
        protected Class[] string_parameter = {String.class}; //以String 為參數(shù)
        protected Class[] int_parameter = {int.class};  //以int為參數(shù)
        protected Class[] multi_parameter = {String.class,Date.class}; //多個(gè)參數(shù),第一個(gè)為String,第二二個(gè)為Date   
       
        public void method1(){
          System.out.println("method1");
        }
       
        public void method2(String str){
          System.out.println("method2=>"+str);
        }
       
        public void method3(int i){
          System.out.println("method2=>"+i);
        }
       
        public void method4(String str,Date date){
          System.out.println("method4=>"+str+"==="+date.toLocaleString());
        }
       
        public void execute(String methodName,int type,java.util.List list) throws Exception{
          try {
            Method  m = getMethod(methodName,type);
            int size = (list != null )? list.size():0;
            Object o [] = new Object[size];
            for( int i =0 ; i< size ; i++ )
              o[i] = list.get(i);  //準(zhǔn)備參數(shù)
            m.invoke(this,o);
          }
          catch (Exception ex) {
            ex.printStackTrace();
            throw new Exception(ex.getMessage());
          }
        }
       
        private Method getMethod(String name,int type)throws NoSuchMethodException{
            Method m = null;
            switch(type){
              case 1:
                m = clazz.getMethod(name,no_parameter);
                break;
              case 2:
                m = clazz.getMethod(name,string_parameter);
                break;
              case 3:
                m = clazz.getMethod(name,int_parameter);
                break;
              case 4:
                m = clazz.getMethod(name,multi_parameter);
                break;
              default:
                m = clazz.getMethod(name,no_parameter);
            }
            return m;
        }
       
        public static void main(String [] argv){
          TestMethod testMethod = new TestMethod();
          try{
            java.util.List list = new java.util.ArrayList();
            testMethod.execute("method1", 1, list);
            list.add("
    http://www.tkk7.com/minmoon");
            testMethod.execute("method2", 2, list);
            list.clear();
            list.add("
    mailTo:xiaoliang@aspire-tech.com");
            list.add(new Date());
            testMethod.execute("method4",4,list);
          }
          catch(Exception e){
            e.printStackTrace();
          }
        }
    }

    其中幾個(gè)關(guān)鍵的地方說明一下:
      clazz.getMethod(name,multi_parameter);  其中multi_parameter是要根據(jù)實(shí)際方法的參數(shù)來定義的。
      m.invoke(this,o);   o是要傳入方法的參數(shù)列表。

    posted @ 2005-11-23 00:18 月亮 閱讀(485) | 評(píng)論 (0)編輯 收藏

    主站蜘蛛池模板: 国产成人精品亚洲2020| 99无码人妻一区二区三区免费| 亚洲av永久无码精品三区在线4| 亚洲午夜日韩高清一区| 天天摸天天操免费播放小视频| 日韩电影免费在线观看| 免费视频精品一区二区| 亚洲色无码国产精品网站可下载| 亚洲人成依人成综合网| 亚洲免费视频一区二区三区| 日本特黄特色aa大片免费| 97人妻无码一区二区精品免费| 国产真人无码作爱视频免费| 一级一级一级毛片免费毛片| 在线亚洲v日韩v| 亚洲高清一区二区三区电影| 亚洲一区二区三区在线观看网站| 亚洲日本在线播放| 亚洲黄色在线视频| 亚洲综合日韩中文字幕v在线| 亚洲午夜久久久影院伊人| 亚洲一区二区高清| 亚洲精品岛国片在线观看| 免费在线视频一区| 亚洲成av人片不卡无码久久| 亚洲阿v天堂在线2017免费| 国产成人免费高清在线观看| 国产91在线免费| 无码国产亚洲日韩国精品视频一区二区三区| 女人18毛片a级毛片免费视频| 免费无码看av的网站| 色视频色露露永久免费观看| 精品国产免费观看久久久| 老司机永久免费网站在线观看| 国产精品免费一级在线观看| 免费在线观看亚洲| 亚洲精品A在线观看| 亚洲中久无码永久在线观看同| 亚洲人成网亚洲欧洲无码久久| 亚洲av一综合av一区| 久久久久久亚洲av成人无码国产|