SmileFace
与java一起走过的日子
posts - 41,  comments - 8,  trackbacks - 0
I am trying to run wireshark in linux using sudo, but was told: i am not in the sudoer files. So I must edit this file to add my own user into this file. Steps as follows:

1. su to root:  su-
 2. open sudoers:  visudo /etc/sudoers
3. add my user name:  testuser ALL=(ALL) NOPASSWD:ALL
    This lines means that the user "testuser" can execute from ALL terminals, acting as ALL (any) users, and run ALL (any) command.

The detail is in paper:  http://www.go2linux.org/sudoers-how-to






posted @ 2009-08-28 04:28 SmileFace 阅读(226) | 评论 (0)编辑 收藏
In order to supports internationalization (I18N), on Tomcat some additional configuration is necessary. You must
ensure that Tomcat's URI encoding is set to UTF-8. You can do this by editing the Tomcat configuration file
conf/server.xml and adding URIEncoding=”UTF-8” to each connector element, as shown below:

<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" debug="0"
acceptCount="100" connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="UTF-8" />

And make sure you do this for every connectort.
posted @ 2009-08-20 13:45 SmileFace 阅读(274) | 评论 (0)编辑 收藏
I planned to install Roller in my centOS which need tomcat6. But centos5.3 has tomcat5 in it's yum. So I have to install tomcat6 using other way. I searched and found this good install guide in:
     http://cloudservers.mosso.com/index.php/CentOS_-_Tomcat_6 ( or http://de0ris.blogspot.com/2008/08/installing-tomcat-6x-on-centos-5.html )
which give detail instructions. I choose some important part and paste here in case for late use.

1.  install appache ant:  (note: download and put the tar file in /usr/share first )
   tar -xzf apache-ant-1.7.1-bin.tar.gz



2. install tomcat:(note: download and put the tar file in /usr/share first )



tar -xzf apache-tomcat-6.0.18.tar.gz

3.  create a symbolic link for Ant so other applications can easily find it. Be sure to select the correct version when you create your link.
ln -s /usr/share/apache-ant-1.7.1/bin/ant /usr/bin

4. set JAVA_HOME:
cd /usr/share/apache-tomcat-6.0.18/bin

vi catalina.sh

enter insert mode. Enter the following:

JAVA_HOME=/usr/java/jdk1.6.0_14

Test:
cd /usr/share/apache-tomcat-6.0.18/bin

./startup.sh

5.Automating atartup:   Right now Tomcat will not start up on it's own so we need to create a startup script for this. To do this:
cd /etc/init.d

vi tomcat

Press i to enter insert mode and paste in the following:

#!/bin/bash

# chkconfig: 234 20 80

# description: Tomcat Server basic start/shutdown script

# processname: tomcat

JAVA_HOME=/usr/java/jdk1.6.0_14

export JAVA_HOME

TOMCAT_HOME=/usr/share/apache-tomcat-6.0.18/bin

START_TOMCAT=/usr/share/apache-tomcat-6.0.18/bin/startup.sh

STOP_TOMCAT=/usr/share/apache-tomcat-6.0.18/bin/shutdown.sh

start() {

echo -n "Starting tomcat: "

cd $TOMCAT_HOME

${START_TOMCAT}

echo "done."

}

stop() {

echo -n "Shutting down tomcat: "

cd $TOMCAT_HOME

${STOP_TOMCAT}

echo "done."

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart)

stop

sleep 10

start

;;

*)

echo "Usage: $0 {start|stop|restart}"

esac

exit 0

Be sure to change the following items in the above file:

* JAVA_HOME path

* TOMCAT_HOME path

* START_TOMCAT path

* STOP_TOMCAT path

Once you have those changes made, save the file and quit.

Now we need to change the permissions on the file.

chmod 755 tomcat

We need to set the script to start with other system services and set the runlevels.

chkconfig --add tomcat

chkconfig --level 234 tomcat on

You can verify that it is listed by typing chkconfig --list tomcat.

tomcat         	0:off	1:off	2:on	3:on	4:on	5:off	6:off

Test your shutdown and startup script.

sudo /sbin/service tomcat stop

sudo /sbin/service tomcat start

Tomcat 6 should now be installed under CentOS.

    



posted @ 2009-08-20 13:12 SmileFace 阅读(696) | 评论 (0)编辑 收藏
1.Agile model driven development(AMDD): focus on model

2.Extreme programmning: focus on full development life cycle.

3.Jconsole: c:\program files\java\jdk1.6.0_14\bin\jconsole, which could dectect the memory issue, class loading, garbage collection...
posted @ 2009-08-20 01:43 SmileFace 阅读(120) | 评论 (0)编辑 收藏
一看书名就知道又是一本通俗易懂的书。果不其然,而且比想象的更有意思(我想是简单的缘故吧)。

书里只是很简单的提及了一些网络的基本概念和运作原理,似乎各个方面都有覆盖,但是因为描述的很浅显,所以建议给:
1 想大致了解DNS,ARP,router等网络知识的人;
2 有闲但是对于网络感兴趣的人;

其实不错,无聊的时候翻翻,解闷!

posted @ 2009-08-19 14:08 SmileFace 阅读(147) | 评论 (0)编辑 收藏
centos

0. /sbin/ifconfig

1. mysql :

   *remove: yum -y remove mysql mysql-server
   *insatll: yum -y install mysql mysql-server
 
   *check: chkconfig --list | grep mysql
  
   *Set to Start on Boot:
       chkconfig mysqld on

   *start service:
       service --status-all
       service mysqld start
       check:  mysqladmin version    
 
   *setup root password:
    mysqladmin -u root password ***(this is new password)

    *run:
    mysql -u root -p

    *exit:
    \q

    *commands:ep t
    show databases;

    drop database ***;

2. Tomcat:

    *install:
        yum -y install tomcat5 tomcat5-webapps tomcat5-admin-webapps

    *You can find these packages using
        yum list available tomcat5*
        or
        yum search tomcat5

    *Start:
        service tomcat5 start
       
    view:   http://localhost:8080/.

    *location:r
         /usr/share/tomcat5 .
        *setting:
            "$CATALINA_HOME".

3. JDK:

     * Originally, centOS only install jre. so we need install jdk by ourselves.
     *To install from the command line:
$yum install java-1.6.0-openjdk-devel

You can also install all the OpenJDK 6 packages, including the API documentation, by using the wildcard java-1.6.0-openjdk*.

      *location:         /usr/lib/jvm...
      *check:  java -version
        






posted @ 2009-08-13 07:31 SmileFace 阅读(162) | 评论 (0)编辑 收藏

最近赋闲,借来这本书看。本来希望很大,期冀可以学到些东西。结果,事与愿违。

总的感觉:这书一般,不推荐给大家,尤其是对于有项目开发经验的人。在这个200多页的书里,作者罗列了项目开发方法,开发工具,开发环境等等。因为涉及内容太多,所以每个知识点都是一带而过,不过讲讲优点,缺点。所以感觉四不像。

如果你是个没有项目开发经验的人,想全面地了解目前web开发的基本过程,项目可能涉及的技术方面,可以看看。


下面是自己的一些读书笔记,你们可以掠过:

1.Agile model driven development(AMDD): focus on model

2.Extreme programmning: focus on full development life cycle.

3.Jconsole: c:\program files\java\jdk1.6.0_14\bin\jconsole, which could dectect the memory issue, class loading,

garbage collection...
 

Java profilers: analyze the heap for memory usage and leaks, CPU utilization, trace object and methods,determine performance bottlenecks...

4.Ant new feature:

      <exec command="date"/>

   Get:  fetch a file using HTTP GET.

      <get src="http://visualpatterns.com/comics/funny.gif" dest="funny.gif"  verbose="true"/>

   Sleep: pause processing.
 
 <sleep seconds="2"/>
 
   FTP: use FTP directly. The example transfe the files to ftp server automatically using windows scheduled tasks
 <ftp server="mirror.kernel.org"
      action="get"
      remotedir=...> </ftp>

   MAIL: ...

5. JMX: my thought: I can use it to track how many user signed into, and so on.

6.unchecked exception: do not need to be caught by the code. Checked exception require the code to either cathch the exception or throw it up the call chain using throws. "If  a client can reasonble to recover from an exception, make it a checked exception. If client cannot do anything to recover from the excepetion, make it unchecked"

posted @ 2009-07-25 07:38 SmileFace 阅读(198) | 评论 (0)编辑 收藏

在windows和fedora 4下都安装了postgresql,有2点体会:

1。windows下安装postgresql,最好在安装前先建立“limit”权限的用户postgres;当然,看见报错的时候再加也来的及呀;

2。在fedora 4 下安装,要么用rpm安装低版本的postgresql,要么用source逐步安装最新版本的。用rpm比较简单,不说了;
    如果安装source,不要到网上到处找帮助,直接在postgresql的网站上找到权威文档就行:http://www.postgresql.org/docs/8.2/static/installation.html。 我觉得很实用。按照它的步骤做下来,ok。 尤其是,注意看里面14.2中关于requirments的说明,在configure时记得使用--without-readline option,否则会出错的。

posted @ 2007-05-25 22:42 SmileFace 阅读(349) | 评论 (0)编辑 收藏
前天开始在fedora 4 下安装java的这一套开发环境,满以为很简单,后来发现里面还是有点小trick的,而且在网上并没有找到类似的完整讲解的文章,所以写出来共享。希望对大家有所帮助。

安装的版本: jdk1.5.0_11+Tomcat5.0.28+Eclipse3.2.2+Sysdeo3.2.1

说明:

1、fc4第一次有了自带的全套java开发环境,也就是说,如果你完全安装,那么jdk,tomcat和eclipse都是直接装好的。据说这是因为版权的原因不再使用sun的jdk,所以才会这样。但是却害苦了我。我遇到了一个接一个的问题。后来再网上搜了一遍,看了写文章,结论是:fc4自带的这套环境不能用,最好自己装。于是就有了我的子装过程和这片文章。注意:我遇到的问题主要来自sysdeo,如果你不使用这个插件,也许fc4的环境可以将就用。

2、安装jdk和tomcat需要是root用户,安装eclipse和sysdeo最好使用开发者自己的用户。

安装过程:

1 安装jdk:   参考文档:http://www.sitepoint.com/article/jakarta-tapestry

   su 到root用户:

    1.1 下载jdk-1_5_0_11-linux-i586-rpm.bin;
   1.2 要执行文件,须先change文件的perrmissions: chmod +x jdk-1_5_0_11-linux-i586-rpm.bin
  
    1.3 执行文件:./jdk-1_5_0_11-linux-i586-rpm.bin
    1.4 在etc/profile.d新建java.sh,如下:
  
     if ! echo ${PATH} | grep -q /usr/java/jdk1.5.0_11/bin ; then
      export PATH=/usr/java/jdk1.5.0_11/bin:${PATH}
    fi
    if ! echo ${PATH} | grep -q /usr/java/jdk1.5.0_11/jre/bin ; then
      export PATH=/usr/java/jdk1.5.0_11/jre/bin:${PATH}
    fi
    export JAVA_HOME=/usr/java/jdk1.5.0_11
    export CLASSPATH=.:/usr/java/jdk1.5.0_11/lib/tools.jar:/usr/java/jdk1.5.0_11/jre/lib/rt.jar
    
2.安装tomcat:我完全参考文档:http://linux-sxs.org/internet_serving/c140.html#INSTALL。这个文章很好,强烈推荐。

3、安装eclipse: 没有trick。
      3.1 su到普通的开发用户;
       3.2 unzip即可。
       3.3 ./eclipse即可启动。
4、安装sysdeo:
       因为在windows下这个插件用的很顺手,所以在linux下我也希望能接着用它。
       以普通用户身份下载,unzip,然后mv到eclips的plugins下,即可。
 
        重新启动eclipse,小猫的图标在。再在window/perferences下配置一下。运行,就出问题了。原因是:tomcat的启动只有root有权限,现在是普通用户的模式下,权限受限。solution:  让普通用户接管tomcat的权限。

       做法是:chown -R test:test  /opt/tomcat
   这里的 test:test是我自己的用户名和用户组,opt/tomcat是catalina_home。
   注意:如果这里的/opt/tomcat是sambolic link的话,真正的目录也需要chown。即,如果是opt/jarcartar_tomcat_1.5.0指向opt/tomcat,那么opt/jarcartar_tomcat_1.5.0也要chown。



这下应该就ok了。
posted @ 2007-05-25 11:32 SmileFace 阅读(408) | 评论 (0)编辑 收藏

出处:hihi的网站

http://home.fego.cn/loading.html?aspxerrorpath=/members/hihi/m_Article/Detail.aspx


Java数据库接口JDBC入门基础讲座-第六讲 PreparedStatement接口

 

 
  概述

  该 PreparedStatement 接口继承 Statement,并与之在两方面有所不同:

  PreparedStatement 实例包含已编译的 SQL 语句。这就是使语句“准备好”。包含于 PreparedStatement 对象中的 SQL 语句可具有一个或多个 IN 参数。IN参数的值在 SQL 语句创建时未被指定。相反的,该语句为每个 IN 参数保留一个问号(“?”)作为占位符。每个问号的值必须在该语句执行之前,通过适当的setXXX 方法来提供。


  由于 PreparedStatement 对象已预编译过,所以其执行速度要快于 Statement 对象。因此,多次执行的 SQL 语句经常创建为 PreparedStatement 对象,以提高效率。

  作为 Statement 的子类,PreparedStatement 继承了 Statement 的所有功能。另外它还添加了一整套方法,用于设置发送给数据库以取代 IN 参数占位符的值。同时,三种方法 execute、 executeQuery 和 executeUpdate 已被更改以使之不再需要参数。这些方法的 Statement 形式(接受 SQL 语句参数的形式)不应该用于 PreparedStatement 对象。

  1、创建 PreparedStatement 对象

  以下的代码段(其中 con 是 Connection 对象)创建包含带两个 IN 参数占位符的 SQL 语句的 PreparedStatement 对象:

PreparedStatement pstmt = con.prepareStatement("UPDATE table4 SET m = ? WHERE x = ?");

  pstmt 对象包含语句 "UPDATE table4 SET m = ? WHERE x = ?",它已发送给DBMS,并为执行作好了准备。

  2、传递 IN 参数

  在执行 PreparedStatement 对象之前,必须设置每个 ? 参数的值。这可通过调用 setXXX 方法来完成,其中 XXX 是与该参数相应的类型。例如,如果参数具有Java 类型 long,则使用的方法就是 setLong。setXXX 方法的第一个参数是要设置的参数的序数位置,第二个参数是设置给该参数的值。例如,以下代码将第一个参数设为 123456789,第二个参数设为 100000000:

pstmt.setLong(1, 123456789);
pstmt.setLong(2, 100000000);

  一旦设置了给定语句的参数值,就可用它多次执行该语句,直到调用clearParameters 方法清除它为止。在连接的缺省模式下(启用自动提交),当语句完成时将自动提交或还原该语句。

  如果基本数据库和驱动程序在语句提交之后仍保持这些语句的打开状态,则同一个 PreparedStatement 可执行多次。如果这一点不成立,那么试图通过使用PreparedStatement 对象代替 Statement 对象来提高性能是没有意义的。

  利用 pstmt(前面创建的 PreparedStatement 对象),以下代码例示了如何设置两个参数占位符的值并执行 pstmt 10 次。如上所述,为做到这一点,数据库不能关闭 pstmt。在该示例中,第一个参数被设置为 "Hi"并保持为常数。在 for 循环中,每次都将第二个参数设置为不同的值:从 0 开始,到 9 结束。

pstmt.setString(1, "Hi");
for (int i = 0; i < 10; i++) {
 pstmt.setInt(2, i);
 int rowCount = pstmt.executeUpdate();
}

  3、IN 参数中数据类型的一致性

  setXXX 方法中的 XXX 是 Java 类型。它是一种隐含的 JDBC 类型(一般 SQL 类型),因为驱动程序将把 Java 类型映射为相应的 JDBC 类型(遵循该 JDBCGuide中§8.6.2 “映射 Java 和 JDBC 类型”表中所指定的映射),并将该 JDBC 类型发送给数据库。例如,以下代码段将 PreparedStatement 对象 pstmt 的第二个参数设置为 44,Java 类型为 short:

pstmt.setShort(2, 44);

  驱动程序将 44 作为 JDBC SMALLINT 发送给数据库,它是 Java short 类型的标准映射。

  程序员的责任是确保将每个 IN 参数的 Java 类型映射为与数据库所需的 JDBC 数据类型兼容的 JDBC 类型。不妨考虑数据库需要 JDBC SMALLINT 的情况。如果使用方法 setByte ,则驱动程序将 JDBC TINYINT 发送给数据库。这是可行的,因为许多数据库可从一种相关的类型转换为另一种类型,并且通常 TINYINT 可用于SMALLINT 适用的任何地方
posted @ 2006-12-23 01:47 SmileFace 阅读(283) | 评论 (0)编辑 收藏
使用J2SEAPI读取Properties文件的六种方法:

  1。使用java.util.Properties类的load()方法示例:
                InputStream in=new BufferedInputStream(newFileInputStream(name));
                Properties p=new Properties();
                p.load(in);

  2。使用java.util.ResourceBundle类的getBundle()方法示例:
                  ResourceBundle rb=ResourceBundle.getBundle(name,Locale.getDefault());

  3。使用java.util.PropertyResourceBundle类的构造函数示例:
                   InputStream in=newBufferedInputStream(newFileInputStream(name));
                  ResourceBundle rb=newPropertyResourceBundle(in);

  4。使用class变量的getResourceAsStream()方法示例:
                   InputStream in=JProperties.class.getResourceAsStream(name);
                   Properties p=newProperties();
                   p.load(in);

  5。使用class.getClassLoader()所得到的java.lang.ClassLoader的getResourceAsStream()方法示例:          

                   InputStream in=JProperties.class.getClassLoader().getResourceAsStream(name);
                   Properties p=new Properties();
                    p.load(in);

  6。使用java.lang.ClassLoader类的getSystemResourceAsStream()静态方法示例:InputStreamin=ClassLoader.getSystemResourceAsStream(name);Propertiesp=newProperties();p.load(in);

  补充

  Servlet中可以使用javax.servlet.ServletContext的getResourceAsStream()方法示例:

                 InputStream in=context.getResourceAsStream(path);
                 Properties p=newProperties();
                 p.load(in);
posted @ 2006-12-22 05:11 SmileFace 阅读(296) | 评论 (0)编辑 收藏

首先:java没有叫 全局变量 的东西(有全局变量还叫OO吗?);原因:Java将所有设计都基于对象的基础上。Java的全局变量只能对一个类内部而言。能够在类内的任何地方使用的变量就是全局变量,而只在某个特定的函数或者局部的程序块内使用的变量则是局部变量。

所以:声明为static的变量实质上就是全局变量。当声明一个对象时,并不产生static变量的拷贝,而是该类所有的实例变量共用同一个static变量。

使用:java中只有static和非static变量,这个属于每个类的,如果需要全局变量比如PI(3.14...),可以写一个类Math,定义static变量PI,调用Math.PI就可以使用了,这样就达到我们使用全局变量的目的了。

1、将一个 package 中需要的常量集中到一个 XyzConstants 之类的 interface 里声明,
就像普通的 field 那样声明就行了。
public interface SomeConstants {
   public intPORT = 80;
   public String IP = "166.111.16.1";
   public boolean test = true;
}
就可以。
用到常量的类 implements 这个接口 .. 简单情况这样就行乐。

2、更 formal 的做法是写一个类维护所有的常量,负责从配置文件(例如properties文件或xml文件)读取所有的常量的值。
可以在一个 static {} 块里从配置文件中初始化所有 static 的变量。 这样有利于提高软件的可配置性。改些东东不用动代码,比较好。
最好要有 config Tool 负责写配置文件。

3.其他说明:

定义一个公开类,在里面加static 变量。
public class infos{
  private infos(){
  }
   public static int PORT = 80;
   public static String IP = "166.111.166.111";
   public static boolean test = true;
   public static finale String MYNAME="zzz"; //定义中用了finale,就是不能改变指的。
}
在别的class中调用这些变量就是: infos.PORT,infos.IP,infos.test,infos.MYNAME
多个class交互时可以通过改变这些变量的值来传递信息。比如 infos.test被别的class改成了false,可能表示某一件事已经失败或已经做过,其它class就可以提前知道这些信息。
posted @ 2006-12-21 04:06 SmileFace 阅读(10279) | 评论 (1)编辑 收藏
出处:http://www.360doc.com/showWeb/0/0/162473.aspx

一、前言
    JDOM是Breet Mclaughlin和Jason Hunter两大Java高手的创作成果,2000年初,JDOM作为一个开放源代码项目正式开始研发。JDOM是一种解析XML的Java工具包。

    DOM适合于当今流行的各种语言,包括Java,JavaScripte,VB,VBScript,Perl,C,C++等。它了为HTML和XML文档提供了一个可应用于不同平台的编程接口。W3C DOM的最新信息可从http://www.w3.org/TR2001/WD-DOM-Lever-3-Core-20010913查阅。微软在http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmconxmldomuserguide.asp上也有DOM的详细技术信息。

   DOM的设计为了适用于不同的语言,它保留了不同语言中非常相似的API。但是它并不适合于Java编程者的习惯。而JDOM作为一种轻量级API被制定,它最核心的要求是以Java为中心,只适合于Java语言,它遵循DOM的接口主要规则,除去了DOM中为了兼容各语言而与Java习惯的不同。

二、使用JDOM的前提条件
   须要有SAX、DOM解析器的类文件,JDOM只是一种适合Java程序员来使用的Java XML解析器,目前流行的Java XML解析器还有:Apache Xerces Java、JAXP。
Xerces Java解析器是完全用Java编写的XML解析器,最新版本是2.5,它支持以下标准和API:
(1) XML1.0规范(第二版本)
(2) XML命名空间规范
(3) DOM2核心标准规范
(4) SAX2核心扩展
(5) JAXP1.2 :是Sun提供的使用Java处理XML的接口API。
(6) XML Schema结构和数据类型标准

      还有最好的是它开放源代码,我们可以在http://xml.apache.org/dist/xerces-j/ 处去下载。下载文件Xerces-J-bin.2.5.0.zip。
解压下载文件,得到四个压缩包加到项目的路径中(其实不要全加,但不熟的情况下考虑这么做)。
JDOM的二进制版本下载:http://www.jdom.org/downloads/index.html
把解压后的jdom.jar文件加到项目的类路径中,另外便于调试,还要下载它的源代码。

三、使用JDOM解析XML
     好了,现在该是正题了。下面通过一个简单的例子说明一下怎么用JDOM这一适合Java程序员习惯的工具包来解析XML文档。
为了简单,我用了如下XML作为要解析的XML文件:
<?xml version="1.0" encoding="gb2312"?>
<books>
   <book email="zhoujunhui">
     <name>rjzjh</name>
     <price>60.0</price>
  </book>
</books>
够简单的吧,但它对于我们关心的东西都有了,子节点,属性。
下面是用于解析这个XML文件的Java文件:

1 public class JDomParse {
2	public JDomParse(){
3		String xmlpath="library.xml";
4		SAXBuilder builder=new SAXBuilder(false);
5		try {
6			Document doc=builder.build(xmlpath);
7			Element books=doc.getRootElement();
8			List booklist=books.getChildren("book");
9			for (Iterator iter = booklist.iterator(); iter.hasNext();) {
10				Element book = (Element) iter.next();
11				String email=book.getAttributeValue("email");
12				System.out.println(email);
13				String name=book.getChildTextTrim("name");
14				System.out.println(name);
15				book.getChild("name").setText("alterrjzjh");
16
17			}
18
19			XMLOutputter outputter=new XMLOutputter();
20			outputter.output(doc,new FileOutputStream(xmlpath));
21
22		} catch (JDOMException e) {
23			e.printStackTrace();
24		} catch (IOException e) {
25			e.printStackTrace();
26		}
27	}
28	public static void main(String[] args) {
29		new JDomParse();
30	}
31}
不到30行代码,现在我对代码解释一下:
四、解释代码
引用的类:
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
//下面是引用到JDOM中的类
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
(1)使用JDOM首先要指定使用什么解析器。如:
        SAXBuilder builder=new SAXBuilder(false); 这表示使用的是默认的解析器
(2)得到Document,我们以后要进行的所有操作都是对这个Document操作的:
        Document doc=builder.build(xmlpath);
(3)得到根元素:
        Element books=doc.getRootElement();
在JDOM中所有的节点(DOM中的概念)都是一个org.jdom.Element类,当然他的子节点也是一个org.jdom.Element类。
(4)得到元素(节点)的集合:
      List booklist=books.getChildren("book");
这表示得到“books”元素的所在名称为“book”的元素,并把这些元素都放到一个List集合中
(5)轮循List集合
     for (Iterator iter = booklist.iterator(); iter.hasNext();) {
       Element book = (Element) iter.next();
    }
还有一种轮循方法是:
    for(int i=0;I<booklist.size();I++){
      Element book=(Element)booklist.get(i);
    }
(6)取得元素的属性:
    String email=book.getAttributeValue("email");
   取得元素book的属性名为“email”的属性值。
(7)取得元素的子元素(为最低层元素)的值:
    String name=book.getChildTextTrim("name");
    注意的是,必须确定book元素的名为“name”的子元素只有一个。
(8)改变元素(为最低层元素)的值:
    book.getChild("name").setText("alterrjzjh");
    这只是对Document的修改,并没有在实际的XML文档中进行修改
(9)保存Document的修改到XML文件中:
   XMLOutputter outputter=new XMLOutputter();
    outputter.output(doc,new FileOutputStream(xmlpath));

我们先要有一个XMLOutputter类,再把已经修改了的Document保存进XML文档中。
到此。用JDOM解析和处理XML文档讲解完了,麻雀虽小,五脏俱全。现在已对JDOM有个整体上的概念了吧。

进一步可以参考的文章:http://www.1-100.org/JSP/13190.htm
posted @ 2006-12-21 02:40 SmileFace 阅读(313) | 评论 (0)编辑 收藏
建设一个完整的J2EE应用总会有很多系统参数,例如Datasource、INITIAL_CONTEXT_FACTORY、PROVIDER_URL等等,怎么才能最方便的存取,并且便于系统部署,移植呢?

就是--.properties属性文件。

掌握他的使用方法后,您可以象使用一个Class一样使用您的.properties属性文件。

Java中提供了一个java.util.Properties工具类,使用Properties类您可以方便的从一个.properties属性文件中读取设置参数,示例代码如下:

    Properties props = new Properties();
    props.load(new FileInputStream("filename.properties"));
    String value = props.getProperty("propertyname");

如果您的.properties文件打包入一个Jar或War文件,您可以使用ClassLoader的getResourceAsStream()方法得到一个InputStream对象,示例代码如下:

        Properties props = new Properties();
        props.load(getClass().getResourceAsStream("com/company/application/application.properties"));
        String value = props.getProperty("propertyname");

不过这种方式应该适用于较少量的访问吧,比如应用系统的初始化等等。
如果需要频繁得到信息,就不太适合了。


另解: 他就象是数据可以存放在*.txt中,但是当数据变得很复杂,就要用专门的东西来存放---数据库,用java.util.Properties类来存储配置参数提供一种以Java为中心的数据存储配置方案,对Java有一定的依赖性,另外功能上也很匮乏,相当于*.txt,目前对于稍微复杂一些的系统存储配置都采用通用的xml方案,可以充分利用xml的强大功能,相当于数据库。

Properties文件就象一个文本文件,文件中使用属性和值来保存数据,如:abc.name=Colin。使用Porperites文件来保存实际上就是创建一个Properites文件,在程序关闭的时候,将数据写入文件,再等程序启动的时候,从这个Properties文件中读出数据。

出处:http://www.cjsdn.net/post/view?bid=2&id=109&sty=3&age=0&tpg=1&ppg=1#109
posted @ 2006-12-19 13:36 SmileFace 阅读(340) | 评论 (0)编辑 收藏

首先要了解java默认的序列化行为,java将一切关于对象的信息都保存了下了,也就是说,有些时候那些不需要保存的也被保存了下来。一般情况下,我们仅仅需要保存逻辑数据就可以了。不需要保存的数据我们可以用关键字transient标出。

例如:

import java.io.*;

public class Serial implements Serializable {

 int company_id;

 String company_addr;

 transient boolean company_flag;

}


其中的company_flag字段将不会参与序列化与反序列化,但同时也增加了为它初始值的责任。这也是序列化常常导致的问题之一。因为序列化相当于一个只接受数据流的public构造函数,这种对象构造方法是语言之外的。但他仍然是一种形式上的构造函数。如若你的类不能够通过其他方面来保证初始化,则你需要额外的提供readObject方法,首先正常的反序列化,然后对transient标示的字段进行初始化。

在不适合的时候,使用java默认的序列化行为可能会带来速度上的影响,最糟糕的情况是,可能导致溢出。在某些数据结构的实现中,经常会充斥着各种的循环引用,而java的默认序列化行为,并不了解你的对象结构,其结果就是java试图通过一种昂贵的“图遍历”来保存对象状态。可想而知,不但慢而且可能溢出。这时候你就要提供自己的readObject,来代替默认的行为。

note: http://developer.51cto.com/art/200601/20017.htm

posted @ 2006-12-16 04:11 SmileFace 阅读(263) | 评论 (0)编辑 收藏
5月份的时候,我的一篇blog里提到这个内容,那时候没有深入写,现在还是补补吧:

在配置之前需要把数据库启动程序copy到tomcat的common/lib下。

1、在Tomcat 的“管理”工具中,添加“数据源”。键入以下值:
  • JNDI 名称:jdbc/blue
  • 数据源 URL:jdbc:mysql://localhost/home
  • JDBC 驱动程序类:org.gjt.mm.mysql.Driver
  • 用户名:root
  • 口令: ×××

2、在conf/catalina/localhost下找到与“项目名.xml”文件,程序名是webapps目录下的项目文件夹名称。在此文件中的 <context> 标记之间添加以下资源链接:

   <ResourceLink name="jdbc/blue" type="javax.sql.DataSource" global="jdbc/blue"/>

注意:一定要加在这个文件中,而不是在项目文件夹里的web.xml中。至少我这样做时结果不对。

3、 接下来就是测试了。测试程序很重要,尽量用简单的了。以下是我的测试程序:





<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="java.sql.*,javax.sql.DataSource,javax.naming.*"%>
<html>
<head><title>test.jsp</title></head>
<body bgcolor="#ffffff">
<% 
Context initCtx=new InitialContext();
DataSource ds = (DataSource)initCtx.lookup("java:comp/env/jdbc/blue");
try
{
out.println("test! <br>");
Connection conn=ds.getConnection();
out.println("data from database:<br>");
Statement stmt=conn.createStatement();
ResultSet rs =stmt.executeQuery("select * from dept");
while(rs.next())
{
out.println(rs.getString(1));
out.println(rs.getString(2));
}
rs.close();
stmt.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</body>
</html>





























































Good Luck!
posted @ 2006-12-01 05:03 SmileFace 阅读(300) | 评论 (0)编辑 收藏

There are two conditons before you want to run *.jsp file in your web.

1. You have to put the *.jsp into a project which have already registered in the server.xml of conf folder in Tomcat,or the project which under the webapps folder directly
2. In the project, you must have WEB-INF folder which have classes and lib subdirectory.

posted @ 2006-10-13 04:22 SmileFace 阅读(290) | 评论 (0)编辑 收藏
今天才知道,有2种方法:

1、适用于所有的servlet:只需修改conf目录下的server.xml即可自动匿名访问所有的servlet。

To let Tomcat run anonymous servlet classes that have not been defined in a web.xml file, you can enable the Tomcat "invoker" servlet by removing the comments around the servlet-mapping element in the web.xml file in the Tomcat conf directory:
  <!-- The mapping for the invoker servlet -->

<!--

  <servlet-mapping>

    <servlet-name>invoker</servlet-name>

    <url-pattern>/servlet/*</url-pattern>

  </servlet-mapping>

-->

When you edit web.xml in the Tomcat conf directory, the servlet is ready to go。

例如,after saving Ch09_06.java and building the project, start Tomcat with the Tomcat plug-in's buttons and navigate to http://localhost:8080/Ch09_06/servlet/org.eclipsebook.ch09.Ch09_06.

2、就是编辑每个项目中的web.xml文件:

lternatively, if you don't want to edit web.xml in the Tomcat conf directory to enable anonymous servlets, you can create a local web.xml for each project you create with the Tomcat plug-in.

posted @ 2006-10-11 03:01 SmileFace 阅读(279) | 评论 (0)编辑 收藏

今天下载了一个Toad for mysql, 是freeware。 可是安装它之前还要装.Net的framework2让我很不舒服。Anyway,  I still need to use it, right? So, I decide not to think about it. Ok, just install everything it asked. The result is important to me. I have not too much time. Go ahead, my great plan !!!

posted @ 2006-09-29 02:11 SmileFace 阅读(193) | 评论 (0)编辑 收藏

1 安装JDK:
       下载,解压到想要的目录;
        修改、/etc/profile 文件,增加4行:
           export JAVA_HOME=/usr/hong/tools/jdk1.5.0_08
          export PATH=$JAVA_HOME/bin:$PATH              
          CLASSPATH=.:/usr/hong/tools/jdk1.5.0_08/lib/tools.jar:$CALSSPATH
          export CLASSPATH

           验证: 输入java -version 。如果版本信息正确,ok

2 eclipse: 下载,解压即可
3 安装tomcat:
        下载,解压到想要的目录;
         修改、/etc/profile 文件,增加4行:      

          CATALINA_BASE="/usr/hong/tools/jakarta-tomcat-5.0.28"
          CATALINA_HOME="/usr/hong/tools/jakarta-tomcat-5.0.28"
          PATH=$PATH:$CATALINA_HOME/bin 
          export CATALINA_BASE CATALINA_HOME PATH 

          启动:Tomcat/bin/startup.sh
           验证:配置好环境变量以后你试试在浏览器中敲入: http://localhost:8080

 为Tomcat新建一个管理用户,为此需要编辑jakarta/conf/tomcat-users.xml,在里面添加类似的一行:
  <user user-name="admin" password="20006600" roles="????" />
  这样在Tomcat主页面中点击左面的"Tomcat Administration"的链接,就可以对服务器进一步配置.

注册自己的项目:假设你有一个自己的JSP项目,他应该安装在下面的目录下:/tomcat/webapps/myproject。你必须在tomcat/conf/server.xml中加入一行

    <Context path="/myproject" docBase="myproject" debug="0"/>

在浏览器中对应的地址为:http://localhost/myproject


Note:  
            when I install tomcat again, I found a wonderful document regarding how to installtomcat in linux, I am highly recommanding it for you. pls check with the  url:  http://linux-sxs.org/internet_serving/book1.html



    

posted @ 2006-09-20 03:34 SmileFace 阅读(519) | 评论 (0)编辑 收藏
一、rpm包安装方式步骤:
1、找到相应的软件包,比如soft.version.rpm,下载到本机某个目录;
2、打开一个终端,su -成root用户;
3、cd soft.version.rpm所在的目录;
4、输入rpm -ivh soft.version.rpm

二、deb包安装方式步骤:
1、找到相应的软件包,比如soft.version.deb,下载到本机某个目录;
2、打开一个终端,su -成root用户;
3、cd soft.version.deb所在的目录;
4、输入dpkg -i soft.version.deb

三、tar.gz源代码包安装方式:
1、找到相应的软件包,比如soft.tar.gz,下载到本机某个目录;
2、打开一个终端,su -成root用户;
3、cd soft.tar.gz所在的目录;
4、tar -xzvf soft.tar.gz //一般会生成一个soft目录
5、cd soft
6、./configure
7、make
8、make install

四、tar.bz2源代码包安装方式:
1、找到相应的软件包,比如soft.tar.bz2,下载到本机某个目录;
2、打开一个终端,su -成root用户;
3、cd soft.tar.bz2所在的目录;
4、tar -xjvf soft.tar.bz2 //一般会生成一个soft目录
5、cd soft
6、./configure
7、make
8、make install

五、apt方式安装:
1、打开一个终端,su -成root用户;
2、apt-cache search soft 注:soft是你要找的软件的名称或相关信息
3、如果2中找到了软件soft.version,则用apt-get install soft.version命令安
装软件 注:只要你可以上网,只需要用apt-cache search查找软件,用apt-get
install软件

六、bin文件安装:
如果你下载到的软件名是soft.bin,一般情况下是个可执行文件,安装方法如下:
1、打开一个终端,su -成root用户;
2、chmod +x soft.bin
3、./soft.bin //运行这个命令就可以安装软件了

七、不需要安装的软件:
有了些软件,比如lumaqq,是不需要安装的,自带jre解压缩后可直接运行。假设
下载的是lumaqq.tar.gz,使用方法如下:
1、打开一个终端,su -成root用户;
2、tar -xzvf lumaqq.tar.gz //这一步会生成一个叫LumaQQ的目录
3、cd LumaQQ
4、chmod +x lumaqq //设置lumaqq这个程序文件为可运行
5、此时就可以运行lumaqq了,用命令./lumaqq即可,但每次运行要输入全路径或
切换到刚才生成的LumaQQ目录里
6、为了保证不设置路径就可以用,你可以在/bin目录下建立一个lumaqq的链接,
用命令ln -s lumaqq /bin/ 即可,以后任何时候打开一个终端输入lumaqq就可以
启动QQ聊天软件了
7、 如果你要想lumaqq有个菜单项,使用菜单编辑工具,比如Alacarte Menu
Editor,找到上面生成的LumaQQ目录里的lumaqq设置一个菜单项就可以了,当然你
也可以直接到 /usr/share/applications目录,按照里面其它*.desktop文件的格
式生成一个自己的desktop文件即可。
posted @ 2006-09-11 23:32 SmileFace 阅读(118) | 评论 (0)编辑 收藏

前一阵突然发现图书馆可以借到很多我想要的书(UML,XML,J2EE,EJB),于是一口气预定了几十本,结果拿回来本本都想看(^_^,稍微夸张了点,但是百分之六十是不错的,一点要看呀)。这下忙死我了,真不知道怎么分身才好。没啥好说的,看呀。所以,再也没有时间看电视,娱乐,没时间仔细耕耘我的blog了。就这样吧,等我的技术见长,我再好好总结吧。

只是有一点很深的体会: 学一个技术,一定要系统的看书,一本足矣。

posted @ 2006-08-09 22:58 SmileFace 阅读(152) | 评论 (0)编辑 收藏
前几天出去大瀑布玩了一下,似乎放松了些。现在要收心了。本来计划周五就考scjp的,结果没有位置,再者我还没有看模拟题,心理不是态有底,于是决定再等2天看看。

今天看了j2ee书的第2章application assembly and deployment,接下来的第3、4、5章都是servlet和jsp的,于是我决定暂时就看到这里,从现在开始准备scjp,等下周考完后,开始准备scwcd时再看。

老师给的文章还没看,唉,也要留点时间呢。
posted @ 2006-07-05 03:33 SmileFace 阅读(152) | 评论 (0)编辑 收藏
 (From: www.MindView.net)

Your Java Programming Questions

There are several people who have kindly offered to answer Java questions. So please send all questions to:

  1. Sun has a "New To Java" Programming Information Center to help get you started.

  2. Bill Venners, who teaches with me, has created the Java Answers Forum. He said: "I wanted to create a place where programmers could ask and answer each other questions, where the questions and answers would remain indefinitely and be searchable."

  3. The forums at TechInterviews have many people asking and answering Java questions.

  4. IBM DeveloperWorks contains some nice introductory material.

  5. Kathy Kozel has created http://www.javaranch.com/ for the same reason. You can send programming questions to kathykozel@javaranch.com

  6. Marcus Green maintains the Java Certification Exam Discussion Forum

  7. Another page about certification www.levteck.com.

  8. Raymond Blum is available to answer Java questions. He has several years experience in Java and other O-O languages and is currently consulting as an OO mentor and Java instructor. You can send him questions at raytrace@thebyteboard.com

  9. David Reilly has a web site devoted to answering Java questions, which seems well-targeted to beginners. You can go directly to his FAQ.

  10. JFind keeps a list of answers and snippets.

  11. The JavaFAQ specializes in Java questions and answers, including Java Daily Tips, many online Java books, a weekly newsletter, and they provide a free "Java Tips" e-book.

  12. Charles Bell says he will be happy to try to answer questions; he also has a web site at http://www.quantumhyperspace.com.

  13. jGuru.com http://www.jguru.com maintains a set of community-driven, topical FAQs where developers can pose questions or answer those already posed.

  14. Kevin Brown has created an egroup "For those who are working through and would like to discuss the book."

  15. Here's another study group for TIJ: http://groups.yahoo.com/group/JavaThink/.

  16. For JSP (Java Server Pages) questions, JSPInsider claims to have "a refreshing take on JSP." JSPInsider is based upon a group of developers sharing information to help the JSP community make the most out of JSP. They also have a newsletter.

  17. From a bulletin from Sun: "HotDispatch, Inc. and Sun Microsystems, Inc. are helping to bring people together in a real-time marketplace for Java technology support ... [if] you like the idea of getting technical help at competitive prices, visit: http://developer.java.sun.com/developer/support/Hotdispatch/"

  18. Dr. Heinz Max Kabutz publishes an Advanced Java newsletter. Not for the uninitiated, but I find something fascinating in every issue. To subscribe, either send an email here or do it via the web here. He has back issues here.

  19. Programmer's Heaven provides a Java Message Board for Q & A.

posted @ 2006-06-23 22:13 SmileFace 阅读(238) | 评论 (0)编辑 收藏
今天看到chapter 7中讲到sereliaztion,很是糊涂,于是search了一下,嗯,果然有大侠解释的比较清楚,z摘录如下:

Object serialization的定义:
Object serialization 允许你将实现了Serializable接口的对象转换为字节序列,这些字节序列可以被完全存储以备以后重新生成原来的对象。 

serialization不但可以在本机做,而且可以经由网络操作(就是猫小说的RMI)。这个好处是很大的----因为它自动屏蔽了操作系统的差异,字节顺序(用Unix下的c开发过网络编程的人应该知道这个概念,我就容易在这上面犯错)等。比如,在Window平台生成一个对象并序列化之,然后通过网络传到一台Unix机器上,然后可以在这台Unix机器上正确地重构这个对象。


Object serialization主要用来支持2种主要的特性:
1。Java的RMI(remote method invocation).RMI允许象在本机上一样操作远程机器上的对象。当发送消息给远程对象时,就需要用到serializaiton机制来发送参数和接收返回直。

2。Java的JavaBeans.   Bean的状态信息通常是在设计时配置的。Bean的状态信息必须被存起来,以便当程序运行时能恢复这些状态信息。这也需要serializaiton机制。
posted @ 2006-06-20 03:02 SmileFace 阅读(207) | 评论 (0)编辑 收藏
一周没写blog了,因为一直沉浸在scjp的知识里,^_^。

从图书馆借来了sun的SCJP和SCWCD的考试指导书(这点我要盛赞一下这里的图书馆了,真是好呀。真的是给每一个人服务的。人手一个借书卡(限借30本吧,好像),然后所有的图书馆都是联网的,可以预定,只要你耐心,你想看的书,DVD一定是可以看到的。唉,我老人家刚来这里的时候,就梦想着等若干年后我有那个money了,也在我们那个小城市办个图书馆之类的,而且先从儿童图书开始呀。唉,这里的小孩实在太幸福了,我嫉妒很呀。唉,扯的太远了)。先看SCJP的,觉得很好。真的很实用。唉,惭愧,虽然我老人家也编程几载了,可是如今看着SCJP 里的基本知识点,居然很多不是很清楚呢。老公总是问我,SCJP 有用吗?我一直也不知道怎么回答。现在我知道了,就是不为SCJP,为了把基础垫扎实,让自己心安,这个SCJP 我也是要考的,哈哈。

继续努力吧,我自己,哈哈
posted @ 2006-06-13 10:15 SmileFace 阅读(213) | 评论 (0)编辑 收藏

看到一篇比较好的区别几个测试概念的文章,链接如下:

http://agiletesting.blogspot.com/2005/02/performance-vs-load-vs-stress-testing.html

http://agiletesting.blogspot.com/2005/04/more-on-performance-vs-load-testing.html

这里我想补充一下我的理解(基本思想来自我爱人,哈哈):

Performance Testing: 增加一个新的feature后,使用同样的测试环境,测试样本去测试,与baseline对比看performance的变化;

Stress Testing: 使用尽可能多的样本,不同的样本,去测试系统,以求在最短的时间内发现系统的bug和memory leak 或者其他的问题。这里是不care样本的一致性的。

posted @ 2006-06-03 01:33 SmileFace 阅读(152) | 评论 (0)编辑 收藏
UML一直是我想认真学习的领域,以后就专门开辟一个板块给它吧。希望最终可以有所得。
今天就看到一篇入门的文章,贴在这里吧:

http://frogone.cnblogs.com/archive/2004/02/11/1169.aspx
posted @ 2006-06-01 04:42 SmileFace 阅读(157) | 评论 (0)编辑 收藏

今天发现了几篇使用LoadRunner的好文章,链接在这里,以备后用,哈哈

一个英文站点,资源丰富,强烈推荐:http://www.wilsonmar.com/1loadrun.htm 

使用LoadRunner来测试BEA TUXEDO (LoadRunner 7.6)。 基本的使用点,简单明了,也推荐一下:http://dev2dev.bea.com.cn/techdoc/200312107.html


Note:

1.Virtual User Generator录制出的脚本分3部分,vuser_init、Action1、vuser_end,其中重复执行的是Action1部分,其它2部分都只执行1次

2、在Controller中,Ramp Up栏控制vuser_init的运行,Duration栏控制Action1的运行,Ramp Down栏控制vuser_end的运行

posted @ 2006-05-30 04:51 SmileFace 阅读(199) | 评论 (0)编辑 收藏

<2006年5月>
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

常用链接

留言簿(2)

随笔分类

随笔档案

文章档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜