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

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

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

    posts - 23,comments - 12,trackbacks - 0


     

    問題:JavaBean的一個寫文件方法,獨立調試正常。但移到Struts下,通過Action調用時,

    拋出異常。


     

    原因:文件路徑問題
    解決方法:
    1.修改原來JavaBean里帶前綴路徑的文件---"resources/users.properties"
    為"users.properties"
    2.將struts框架下的源文件users.properties,直接移到src下
    3.重新編譯,部署
    4.運行這個注冊組件成功后,可以到$服務器主目錄$/bin下,查看這個已經寫過的
    users.properties文件
    以上問題,曾嘗試將resources/user.properite改為絕對路徑"d:/users.properties",
    或改為相對路徑"/resources/properties",或直接向JavaBean中傳入路徑參數path,
    path=request.getRealPath("")(或request.getContextPath)等,均沒有調試成功。
    故記錄下來,希望其它網友遇到時,不必再做這樣的重復勞動。
    附:
    1.Action中調用方法:
    UserDirectory.getInstance().setUser(userName,password1);
    2.JavaBean的縮略代碼:
    UserDirectory.java
    import java.io.IOException;
    import java.io.FileOutputStream;
    import java.util.Enumeration;
    import java.util.Properties;
    public class UserDirectory {
     private static final String UserDirectoryFile = "users.properties";
     private static final String UserDirectoryHeader = "${user}=${password}";
     public static UserDirectory getInstance() throws UserDirectoryException {
      if (null == userDirectory) {
       userDirectory = new UserDirectory();
      }
       return userDirectory;
     }
     
      public void setUser(String userId, String password) throws
       UserDirectoryException {
       if ( (null == userId) || (null == password)) {
        throw new UserDirectoryException();
       }try {
        p.put(fixId(userId), password);
        p.store(new FileOutputStream(UserDirectoryFile),UserDirectoryHeader);
       }catch (IOException e) {
        throw new UserDirectoryException();
       }
      }
     }
    posted @ 2005-09-07 13:39 my java 閱讀(1512) | 評論 (1)編輯 收藏
    • char charAt(int index)

      returns the character at the specified location.

    • int compareTo(String other)

      returns a negative value if the string comes before other in dictionary order, a positive value if the string comes after other in dictionary order, or 0 if the strings are equal.

    • boolean endsWith(String suffix)

      returns true if the string ends with suffix.

    • boolean equals(Object other)

      returns true if the string equals other.

    • boolean equalsIgnoreCase(String other)

      returns true if the string equals other, except for upper/lowercase distinction.

    • int indexOf(String str)

    • int indexOf(String str, int fromIndex)

      return the start of the first substring equal to str, starting at index 0 or at fromIndex.

    • int lastIndexOf(String str)

    • int lastIndexOf(String str, int fromIndex)

      return the start of the last substring equal to str, starting at the end of the string or at fromIndex.

    • int length()

      returns the length of the string.

    • String replace(char oldChar, char newChar)

      returns a new string that is obtained by replacing all characters oldChar in the string with newChar.

    • boolean startsWith(String prefix)

      returns true if the string begins with prefix.

    • String substring(int beginIndex)

    • String substring(int beginIndex, int endIndex)

      return a new string consisting of all characters from beginIndex until the end of the string or until endIndex (exclusive).

    • String toLowerCase()

      returns a new string containing all characters in the original string, with uppercase characters converted to lower case.

    • String toUpperCase()

      returns a new string containing all characters in the original string, with lowercase characters converted to upper case.

    • String trim()

      returns a new string by eliminating all leading and trailing spaces in the original string.

    字符串與基本數據類型的轉換間的轉換必須使用JSP中的對象函數
    Boolean.getBoolean(String)
    Byte.parseByte(String)
    Short.parseShort(String)
    Integer.parseInt(String)
    Long.parseLong(String)
    Float.parseDouble(String)
    Double.parseDouble(String)
    String.valueOF(數據)


    Array

  • static void arraycopy(Object from, int fromIndex, Object to, int toIndex, int count)

    Parameters:

    from

    an array of any type (Chapter 5 explains why this is a parameter of type Object)

     

    fromIndex

    the starting index from which to copy elements

     

    to

    an array of the same type as from

     

    toIndex

    the starting index to which to copy elements

     

    count

    the number of elements to copy

    copies elements from the first array to the second array.

    java.util.Arrays 1.2

     

    • static void sort(Xxx[] a)

      Parameters:

      a

      an array of type int, long, short, char, byte, boolean, float or double

      sorts the array, using a tuned QuickSort algorithm.

    • static int binarySearch(Xxx[] a, Xxx v)

      Parameters:

      a

      a sorted array of type int, long, short, char, byte, boolean, float or double

       

      v

      a value of the same type as the elements of a

      uses the BinarySearch algorithm to search for the value v. If it is found, its index is returned. Otherwise, a negative value r is returned; -r - 1 is the spot at which v should be inserted to keep a sorted.

    • static void fill(Xxx[] a, Xxx v)

      Parameters:

      a

      an array of type int, long, short, char, byte, boolean, float or double

       

      v

      a value of the same type as the elements of a

      sets all elements of the array to v.

    • static boolean equals(Xxx[] a, Object other)

      Parameters:

      a

      an array of type int, long, short, char, byte, boolean, float or double

       

      other

      an object

      returns true if other is an array of the same type, if it has the same length, and if the elements in corresponding indexes match.

  • eg: 

     int[] smallPrimes = {2, 3, 5, 7, 11, 13};
      int[] luckyNumbers = {1001, 1002, 1003, 1004, 1005, 1006, 1007};
      System.arraycopy(smallPrimes, 2, luckyNumbers, 3, 3);
      for (int i = 0; i < luckyNumbers.length; i++)
         System.out.println(i + ": " + luckyNumbers[i]);

    posted @ 2005-09-05 13:56 my java 閱讀(337) | 評論 (0)編輯 收藏

    dateadd()函數

    dateadd(datepart,number,date)

    例:
    dateadd(month,1,getdate())
    posted @ 2005-09-05 13:50 my java 閱讀(274) | 評論 (0)編輯 收藏


    1、Message.java
    public class Message {

     public static void main(String[] args) {
        if (args[0].equals("-h"))
              System.out.print("Hello,");
           else if (args[0].equals("-g"))
              System.out.print("Goodbye,");
           // print the other command line arguments
           for (int i = 1; i < args.length; i++)
              System.out.print(" " + args[i]);
           System.out.println("!");

     }
    }

    test:
    java Message -g cruel world



    import java.util.*;
    import javax.swing.*;
    public class FirstSample {

     public static void main(String[] args) {
           String input = JOptionPane.showInputDialog
              ("How many numbers do you need to draw?");
           int k = Integer.parseInt(input);

           input = JOptionPane.showInputDialog
              ("What is the highest number you can draw?");
           int n = Integer.parseInt(input);

           // fill an array with numbers 1 2 3 . . . n
           int[] numbers = new int[n];
           for (int i = 0; i < numbers.length; i++)
           {    numbers[i] = i + 1;
           System.out.println(numbers[i]);
           }
           // draw k numbers and put them into a second array

           int[] result = new int[k];
           for (int i = 0; i < result.length; i++)
           { 
              // make a random index between 0 and n - 1
              int r = (int)(Math.random() * n);

              // pick the element at the random location
              result[i] = numbers[r];

              // move the last element into the random location
              numbers[r] = numbers[n - 1];
              n--;
           }

           // print the sorted array

           Arrays.sort(result);
           System.out.println
              ("Bet the following combination. It'll make you rich!");
           for (int i = 0; i < result.length; i++)
              System.out.println(result[i]);

           System.exit(0);

     }
    }

    posted @ 2005-09-05 10:51 my java 閱讀(214) | 評論 (0)編輯 收藏
    Weblogic8.X安裝及連接池配置指南

    http://dev.csdn.net/develop/article/51/51809.shtm


    1.安裝jre
    Eclipse雖然由java開發,但本身并不自帶jre。所以你必須先自己安裝,去http://java.sun.com/downloads下載最新J2SE1.4.2_03的jre安裝文件j2re-1_4_2_03-windows-i586-p.exe。安裝成功后,重啟機器,并將jre的bin文件夾路徑添加到系統環境變量PATH中,如:C:\Program Files\Java\j2re1.4.2_03\bin。
    2.安裝Eclipse2.1.2
    Eclipse目前最新的stable已經Build到了3.0M5,但是這個版本的LanguagePackFeature還沒有推出,直接用LanguagePackFeature2.1.2有問題。故建議用Eclipse穩定版本2.1.2,配上LanguagePackFeature2.1.2后可實現全中文界面。Eclipse SDK 2.1.2和其LanguagePackFeature下載地址為http://download2.eclipse.org/downloads。
    Eclipse的安裝非常簡單,只需解壓縮eclipse-SDK-2.1.2-win32.zip,將文件夾eclipse拷貝到你想要的地方。然后雙擊eclipse.exe,即開始編譯并初始化Eclipse,完畢自動進入Eclipse。
    下面開始安裝LanguagePackFeature。
    (1)解壓縮eclipse2.1.2.1-SDK-win32-LanguagePackFeature.zip。
    (2)啟動Eclipse,選擇“Help\Software Updates\Update Manager”菜單,使主界面切換到安裝更新透視圖畫面。
    (3)在窗體左下方的Feature Updates視圖中單擊鼠標右鍵,選擇“New\Site Bookmark”菜單,彈出New Site Bookmark對話框。在Name處隨便輸入什么名字,如:LanguagePack。URL處輸入前面(1)解壓縮后文件夾路徑,如:file: E:\開發工具\Eclipse\eclipse2.1.2.1-SDK-win32-LanguagePackFeature\eclipse。完畢按下Finish按鈕,關閉對話框。這時Feature Updates視圖中就會出現一項“LanguagePack”。展開該項,就可以看到很多語言包插件。
    (4)選擇一個語言包,如:Eclipse Java Development 工具語言包 1.2.1.2,單擊右邊視圖中的Install Now按鈕,即開始安裝。安裝成功后,Eclipse會重新啟動。依次類推,逐個安裝所有的語言包插件。在整個安裝過程中你會發現所有界面都變成了簡體中文。
    3.安裝MyEclipse2.7RC2
    去http://www.myeclipseide.com下載最新的MyEclipse安裝文件myeclipse_Enterprise_Workbench_Installer_020700RC2.exe。在安裝過程中需要提供Eclipse所在文件夾的路徑,安裝成功后會自動進入Eclipse。這時你就會發現主菜單中多出一項“MyEclipse”,我們再選擇“窗口\首選項”菜單,打開首選項對話框。展開MyEclipse結點,單擊Subscription子項,可以看到這是個30天限制版。不過你可以到http://www.cracks4u.com上下載破解程序MyEclipse_Enterprise_Workbench_v3.6.4.zip。運行zip中的keygen.exe,隨便輸入一個用戶名,然后選擇2.6.4版本,單擊Generate按鈕生成Subscription Code。將用戶名和Subscription Code輸入到上述的Subscriber和Subscription Code文本框中,點擊“應用”按鈕即可看到信息Number of Licenses:unlimited,至此你的MyEclipse已被破解。
    4.安裝WebLogic8.1
    安裝WebLogic比較容易,在這里就不再累述了,大家可以參閱相關文檔。現在著重講一下WebLogic的配置,因為后面在配置MyEclipse時將用到這里的有關信息。
    (1)運行開始\程序\BEA WebLogic PlatFORM 8.1\Configuration Wizard。
    (2)選擇Create a new WebLogic configuration,下一步。
    (3)選擇Basic WebLogic Server Domain,下一步。
    (4)選擇Custom,下一步。
    (5)在Name處輸入admin,Listen Address處選擇localhost,以下兩個Port均采用默認值,下一步。
    (6)選擇Skip跳過Multiple Servers,Clusters,and Machines Options,下一步。
    (7)選擇Skip跳過JDBC連接池的配置(注:JDBC連接池的配置可以在啟動WebLogic后到控制臺上進行,大家可以參閱相關文檔),下一步。
    (選擇Skip跳過JMS的配置(同樣留到控制臺上做),下一步。
    (9)繼續跳過,下一步。
    (10)選擇Yes,下一步。
    (11)在User頁點擊Add,隨意添加一個用戶user,密碼12345678,下一步。
    (12)將用戶user分配到Administrators組(還可以同時分配到其它組,方法是選中待加入的組,然后勾中user前的復選框即可),下一步。
    (13)直接點擊下一步跳過。
    (14)設置用戶user的權限,選中Admin,勾中user前的復選框(要指定其它權限依次類推),下一步。
    (15)采用默認設置,直接點擊下一步跳過。
    (16)同樣采用默認設置,直接點擊下一步跳過。
    (17)配置JDK,采用WebLogic的默認值,直接點擊下一步跳過。
    (1最后在Configuration Name處輸入dev,然后點擊Create生成配置,完畢點擊Done關閉Configuration Wizard對話框。
    5.配置MyEclipse的WebLogic服務器
    MyEclipse默認的應用服務器為JBoss3,這里我們使用WebLogic8.1。啟動Eclipse,選擇“窗口\首選項”菜單,打開首選項對話框。展開MyEclipse下的Application Servers結點,點擊JBoss 3,選中右面的Disable單選按鈕,停用JBoss 3。然后點擊WebLogic 8,選中右邊的Enable單選按鈕,啟用WebLogic服務器。同時下面的配置如下:
    (1)BEA home directory:D:\BEA。假定WebLogic安裝在D:\BEA文件夾中。
    (2)WebLogic installation directory:D:\BEA\weblogic81。
    (3)Admin username:user。
    (4)Admin password:12345678。
    (5)Execution domain root:D:\BEA\user_projects\dev。
    (6)Execution domain name:dev。
    (7)Execution server name:admin。
    (8)Hostname:PortNumber:localhost:7001。
    (9)Security policy file:D:\BEA\weblogic81\server\lib\weblogic.policy。
    (10)JAAS login configuration file:省略。
    接著展開WebLogic 8結點,點擊JDK,在右邊的WLS JDK name處選擇WebLogic 8的默認JDK。這里組合框中缺省為j2re1.4.2_03,即之前單獨安裝的jre。單擊Add按鈕,彈出WebLogic > Add JVM對話框,在JRE名稱處隨便輸入一個名字,如jre1.4.1_02。然后在JRE主目錄處選擇WebLogic安裝文件夾中的JDK文件夾,如D:\BEA\jdk141_02,程序會自動填充Javadoc URL文本框和JRE系統庫列表框。單擊確定按鈕關閉對話框。這時候就可以在WLS JDK name組合框中選擇jre1.4.1_02了。之后還要在下面的Optional Java VM arguments,如-ms64m -mx64m -Djava.library.path="D:/BEA/weblogic81/server/bin" -Dweblogic.management.discover=false -Dweblogic.ProductionModeEnabled=false
    最后點擊Paths,在右邊的Prepend to classpath列表框中,通過Add JAR/ZIP按鈕,加入D:\BEA\weblogic81\server\lib\weblogic.jar、D:\BEA\weblogic81\server\lib\webservices.jar。如果用到數據庫,還需把數據庫的驅動類庫加進來,這里我們用WebLogic自帶的SQL Server數據庫驅動庫D:\BEA\weblogic81\server\lib\mssqlserver4v65.jar。
    至此,MyEclipse中WebLogic8的配置工作就算完成了。下面可以看看在Eclipse中能否啟動WebLogic了?自從安裝了MyEclipse之后,Eclipse工具欄中就會有一個Run/Stop Servers下拉按鈕。點擊該按鈕的下拉部分,選擇“WebLogic 8\Start”菜單,即開始啟動WebLogic了。通過查看下面的控制臺消息,就可以知道啟動是否成功,或有什么異常發生。停止WebLogic可選擇“WebLogic\Stop”菜單。
    6.創建第一個Web程序——HelloWorld
    啟動Eclipse:
    (1)選擇“文件\新建\項目”菜單,打開新建項目向導。首先選擇左邊的J2EE,然后選擇右邊的Web Module Project,下一步在Project Name處理輸入HelloWorld,點擊完成按鈕,生成項目文件。包視圖結構如下:
    HelloWorld
    ├─src
    ├─JRE系統庫[j2re1.4.2_03]
    ├─J2EE 1.3 Library Container
    └─WebRoot
    (2)點擊src,單擊鼠標右鍵,選擇“新建\Servlet”菜單,創建HelloWorld Servlet。在包名稱處輸入servlet,在Servlet名稱處輸入HelloWorld,去掉Create doGet復選框中的勾,下一步,采用默認設置,點擊完成按鈕。修改doPost方法代碼如下:
    response.setContentType("text/xml");
    PrintWriter out = response.getWriter();
    out.println("Hello World");
    out.flush();
    out.close();
    (3)點擊WebRoot,單擊鼠標右鍵,選擇“新建\HTML”菜單,創建一個HTML頁面。將File Name改為index.html,點擊完成按鈕。將下列代碼替換<body>、</body>之間的代碼:
    <script language="vbscript">
    function bytes2bstr(vin)
    strreturn = ""
    for k = 1 to lenb(vin)
    thischarcode = ascb(midb(vin,k,1))
    if thischarcode < &h80 then
    strreturn = strreturn & chr(thischarcode)
    else
    nextcharcode = ascb(midb(vin,k+1,1))
    strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))
    k = k + 1
    end if
    next
    bytes2bstr = strreturn
    end function
    </script>

    <script language="javascript">
    var xml=null;
    var XMLSender=new ActiveXObject("Microsoft.XMLHTTP");
    var url="http://localhost:7001/HelloWorld/servlet/HelloWorld?";
    XMLSender.Open("POST",url,false);
    XMLSender.setRequestHeader("Content-Type","text/xml; charset=UTF-8");
    XMLSender.send(xml);
    var msg=bytes2bstr(XMLSender.responsebody);
    document.writeln(msg);
    </script>
    (4)展開WEB-INF結點,雙擊打開web.xml,在</servlet-mapping>下面加入下列語句:
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    (5)點擊HelloWorld,單擊鼠標右鍵,選擇“MyEclipse\Add and Remove Project Deployments…”菜單,彈出Project Deployments對話框,在Project組合框中選擇HelloWorld,單擊Add,在Server組合框中選擇WebLogic 8,點擊完成按鈕回到Project Deployments對話框,這時服務器信息就會顯示在Deployments列表中,點擊確定按鈕關閉對話框。
    (6)點擊工具欄上的Run/Stop Servers下拉按鈕,選擇“WebLogic 8\Start”菜單,啟動服務器。
    (7)運行IE,在地址欄輸入http://localhost:7001/HelloWorld/index.html,即可在頁面中看到“Hello World”字樣。
    posted @ 2005-08-25 15:43 my java 閱讀(1065) | 評論 (0)編輯 收藏
    http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/JAASRefGuide.html

    http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/JAASLMDevGuide.html


    http://java.sun.com/j2se/1.4.2/docs/guide/security/jaas/JAASRefGuide.html

    http://java.sun.com/j2se/1.4.1/docs/api/javax/security/auth/login/Configuration.html
    posted @ 2005-08-25 14:29 my java 閱讀(261) | 評論 (0)編輯 收藏

    The include Directive


    The following is the syntax for the include directive:

    <%@ include file="relativeURL" %>

    As you can see the directive accepts a single file attribute that is used to indicate the resource whose content is to be included in the declaring JSP. The file attribute is interpreted as a relative URL; if it starts with a slash it's interpreted as relative to the context of the web application (namely a context-relative path), otherwise it's interpreted as relative to the path of the JSP that contains the include directive (namely a page relative path). The included file may contain either static content, such as HTML or XML, or another JSP page.

    For example:
    <%@ include file="/copyright.html"%>


    Let's consider a real-world example of such a templating mechanism that utilizes the include directive to provide a consistent page layout for a web application.

    Consider the following two JSP pages:

    Header.jsp
        <html>
          <head><title>A Very Simple Example</title></head>
          <body style="font-family:verdana,arial;font-size:10pt;">
            <table width="100%" height="100%">
              <tr bgcolor="#99CCCC">
                <td align="right" height="15%">Welcome to this example...</td>
              </tr>
              <tr>
                <td height="75%">

    Footer.jsp
               </td>
             </tr>
             <tr bgcolor=" #99CC99">
               <td align="center" height="10%">Copyright ACompany.com 2003</td>
             </tr>
           </table>
         </body>
       </html>

    As you can see, Header.jsp declares the starting elements of an HTML table that is to be 100 percent of the size of the page and has two rows, whereas Footer.jsp simply declares the closing elements for the table. Used separately, either JSP will result in partial HTML code that will look very strange to a user but when they're combined using the include directive it's easy to create consistent pages as part of a web application.

    Let's see just how simple this basic template mechanism is to use:

    Content.jsp
        <%@ include file='./Header.jsp'%>
        <p align="center">The Content Goes Here...!!!</p>
        <%@ include file='./Footer.jsp'%>

    2、
    date.jsp
    <html>
      <body>
        <h2>Greetings!</h2>
     <P>The current time is <%=new java.util.Date()%> precisely
      </body>
    </html>

    3、
    dateBean.jsp
    <html>
        <head><title>Professional JSP, 3rd Edition</title></head>
        <body style="font-family:verdana;font-size:10pt;">
            <jsp:useBean id="date" class="com.apress.projsp20.ch01.DateFormatBean"/>
            <h2>Today's date is <%= date.getDate() %></h2>
        </body>
    </html>

    或:
    dateBean_getProperty.jsp
    <html>
        <head><title>Professional JSP, 3rd Edition</title></head>
        <body style="font-family:verdana;font-size:10pt;">
            <jsp:useBean id="date" class="com.apress.projsp20.ch01.DateFormatBean"/>
            <h2>Today's date is <jsp:getProperty name="date" property="date"/></h2>
        </body>
    </html>

    dateBean_setProperty.jsp
    <html>
        <head><title>Professional JSP, 3rd Edition</title></head>
        <body style="font-family:verdana;font-size:10pt;">
            <jsp:useBean id="date" class="com.apress.projsp20.ch01.DateFormatBean"/>
            <jsp:setProperty name="date" property="format"
                             value="EEE, d MMM yyyy HH:mm:ss z"/>
            <h2>Today's date is <jsp:getProperty name="date" property="date"/></h2>
        </body>
    </html>

    其中DateFormatBean.java:
       package com.apress.projsp20.ch01;

        import java.util.Date;
        import java.text.*;

        public class DateFormatBean {
          private DateFormat dateFormat;
          private Date date;

          public DateFormatBean() {
            dateFormat = DateFormat.getInstance();
            date = new Date();
          }

          public String getDate() {
            return dateFormat.format(date);
          }

          public void setDate(Date date) {
            this.date = date;
          }

          public void setFormat(String format) {
            this.dateFormat = new SimpleDateFormat(format);
          }
        }
    例:SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    posted @ 2005-08-24 17:20 my java 閱讀(301) | 評論 (0)編輯 收藏


    DBPhoneLookupReuse.java
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;

    public class DBPhoneLookupReuse extends HttpServlet {

      private Connection con = null;

      public void init() throws ServletException {
        try {
          // Load (and therefore register) the Sybase driver
          Class.forName("com.jnetdirect.jsql.JSQLDriver");
          con = DriverManager.getConnection(
            "jdbc:JSQLConnect://127.0.0.1/database=JAAS", "sa", "db_password");
        }
        catch (ClassNotFoundException e) {
          throw new UnavailableException("Couldn't load database driver");
        }
        catch (SQLException e) {
          throw new UnavailableException("Couldn't get db connection");
        }
      }

      public void doGet(HttpServletRequest req, HttpServletResponse res)
                                   throws ServletException, IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();

        out.println("<HTML><HEAD><TITLE>Phonebook</TITLE></HEAD>");
        out.println("<BODY>");

        HtmlSQLResult result =
          new HtmlSQLResult("SELECT UserName,Password FROM Users", con);

        // Display the resulting output
        out.println("<H2>Users:</H2>");
        out.println(result);
        out.println("</BODY></HTML>");
      }

      public void destroy() {
        // Clean up.
        try {
          if (con != null) con.close();
        }
        catch (SQLException ignored) { }
      }
    }

    HtmlSQLResult.java
    import java.sql.*;

    public class HtmlSQLResult {
      private String sql;
      private Connection con;

      public HtmlSQLResult(String sql, Connection con) {
        this.sql = sql;
        this.con = con;
      }

      public String toString() {  // can be called at most once
        StringBuffer out = new StringBuffer();

        // Uncomment the following line to display the SQL command at start of table
        // out.append("Results of SQL Statement: " + sql + "<P>\n");

        try {
          Statement stmt = con.createStatement();

          if (stmt.execute(sql)) {
            // There's a ResultSet to be had
            ResultSet rs = stmt.getResultSet();
            out.append("<TABLE>\n");

            ResultSetMetaData rsmd = rs.getMetaData();

            int numcols = rsmd.getColumnCount();
      
            // Title the table with the result set's column labels
            out.append("<TR>");
            for (int i = 1; i <= numcols; i++)
              out.append("<TH>" + rsmd.getColumnLabel(i));
            out.append("</TR>\n");

            while(rs.next()) {
              out.append("<TR>");  // start a new row
              for(int i = 1; i <= numcols; i++) {
                out.append("<TD>");  // start a new data element
                Object obj = rs.getObject(i);
                if (obj != null)
                  out.append(obj.toString());
                else
                  out.append("&nbsp;");
                }
              out.append("</TR>\n");
            }

            // End the table
            out.append("</TABLE>\n");
          }
          else {
            // There's a count to be had
            out.append("<B>Records Affected:</B> " + stmt.getUpdateCount());
          }
        }
        catch (SQLException e) {
          out.append("</TABLE><H1>ERROR:</H1> " + e.getMessage());
        }
      
        return out.toString();
      }
    }

    posted @ 2005-08-24 14:49 my java 閱讀(463) | 評論 (0)編輯 收藏

    1、NTLM can be done with JCIFS and without HTTP. Only a few lines of code are required in the code of your servlet:

    InetAddress ip = InetAddress.getByName(”192.168.0.1.”); // ip address of your windows controller
    UniAddress myDomain = new UniAddress(ip);
    NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(”MYDOMAIN”, “mylogin”, “mypasword”);
    SmbSession.logon(myDomain, auth);

    If an exception is triggered, the controller didn’t like the login and the password

    2、Http方式下web.xml中filter的配置:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "<web-app>
     <display-name>WEB APP</display-name>
     <description>WEB APP description</description>
     <servlet>
      <servlet-name>ShowRequestHeaders</servlet-name>
      <servlet-class>coreservlets.ShowRequestHeaders</servlet-class>
     </servlet>
     <servlet-mapping>
      <servlet-name>ShowRequestHeaders</servlet-name>
      <url-pattern>/ShowRequestHeaders</url-pattern>
     </servlet-mapping>
      <filter>
        <filter-name>NtlmHttpFilter</filter-name>
        <filter-class>jcifs.http.NtlmHttpFilter</filter-class>

        <init-param>
            <param-name>jcifs.http.domainController</param-name>
            <param-value>192.168.10.1</param-value>
        </init-param>
      </filter>

      <filter-mapping>
        <filter-name>NtlmHttpFilter</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
     
    </web-app>

    //import java.text.*;
    //import java.util.*;

    public static String addDate(String day,int x)
      {
        SimpleDateFormat format=new SimpleDateFormat("yyyy/MM/dd");
        Date date = null;
        try
        {
          date = format.parse(day);
        }
        catch (ParseException ex)
        {
          ex.printStackTrace();
        }
        if (date==null) return "";
        Calendar cal=Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DAY_OF_MONTH,x);
        date=cal.getTime();
        System.out.println("3 days after(or before) is "+format.format(date));
        cal=null;
        return format.format(date);
      }

    posted @ 2005-08-18 13:26 my java 閱讀(5553) | 評論 (0)編輯 收藏
    僅列出標題
    共3頁: 上一頁 1 2 3 下一頁 
    主站蜘蛛池模板: 成人久久免费网站| 免费一级毛suv好看的国产网站| 一级特黄录像免费播放肥| 免费看小12萝裸体视频国产| 亚洲精品理论电影在线观看| 成年女人午夜毛片免费视频| 亚洲国产精品免费在线观看| 在线观看AV片永久免费| 亚洲国产韩国一区二区| 色婷婷7777免费视频在线观看| 成年免费a级毛片| 免费真实播放国产乱子伦| yellow视频免费看| 国产亚洲成av人片在线观看| 久久久精品免费国产四虎| 亚洲av成人无码久久精品| 51精品视频免费国产专区| 国产精品亚洲四区在线观看 | 久久免费视频一区| 狠狠色伊人亚洲综合成人| 污污网站免费观看| 77777午夜亚洲| 日本免费中文字幕在线看| 免费人成视频在线播放| 亚洲一区二区三区偷拍女厕| 一级毛片免费观看不卡视频| 亚洲免费中文字幕| 亚洲成AV人在线观看网址| 在线观看特色大片免费网站| 亚洲av一本岛在线播放| 免费在线观看黄网站| 久久精品免费视频观看| 亚洲性无码AV中文字幕| 亚洲片一区二区三区| 一级毛片免费播放| 国产精品亚洲AV三区| 亚洲精品国产字幕久久不卡| 波多野结衣在线免费视频| 日本黄页网址在线看免费不卡| 久久精品国产精品亚洲精品| 日韩精品无码区免费专区|