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 阅读(1506) | 评论 (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 阅读(331) | 评论 (0)编辑 收藏

    dateadd()函数

    dateadd(datepart,number,date)

    例:
    dateadd(month,1,getdate())
    posted @ 2005-09-05 13:50 my java 阅读(271) | 评论 (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 阅读(211) | 评论 (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 阅读(1061) | 评论 (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 阅读(255) | 评论 (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 阅读(294) | 评论 (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 阅读(457) | 评论 (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" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <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>

    posted @ 2005-08-19 11:06 my java 阅读(1126) | 评论 (0)编辑 收藏

    //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 阅读(5538) | 评论 (0)编辑 收藏
    仅列出标题
    共3页: 上一页 1 2 3 下一页