<?xml version="1.0" encoding="gb2312"?>

<!-- RSS generated by oioj.net on 4/16/2004 ; 感谢LeXRus提供 RSS 2.0 文档; 此文件可自由使用，但请保留此行信息 --> 
<!-- Source download URL: http://blogger.org.cn/blog/rss2.asp       -->
<rss version="2.0">

<channel>
<title>guan1200的博客</title>
<link>http://blogger.org.cn/blog/blog.asp?name=guan1200</link>
<description>guan1200的博客</description>
<copyright>blogger.org.cn</copyright>
<generator>W3CHINA Blog</generator>
<webMaster>webmaster@blogger.org.cn</webMaster>
<item>
<title><![CDATA[log4j properties配置]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=guan1200&amp;id=31096</link>
<author>guan1200</author>
<pubDate>2008/1/7 13:57:58</pubDate>
<description><![CDATA[og4j.properties 使用<br>
一.参数意义说明<br>
输出级别的种类<br>
ERROR、WARN、INFO、DEBUG<br>
ERROR 为严重错误 主要是程序的错误<br>
WARN 为一般警告，比如session丢失<br>
INFO 为一般要显示的信息，比如登录登出<br>
DEBUG 为程序的调试信息<br>
配置日志信息输出目的地<br>
log4j.appender.appenderName = fully.qualified.name.of.appender.class<br>
1.org.apache.log4j.ConsoleAppender（控制台）<br>
2.org.apache.log4j.FileAppender（文件）<br>
3.org.apache.log4j.DailyRollingFileAppender（每天产生一个日志文件）<br>
4.org.apache.log4j.RollingFileAppender（文件大小到达指定尺寸的时候产生一个新的文件）<br>
5.org.apache.log4j.WriterAppender（将日志信息以流格式发送到任意指定的地方）<br>
配置日志信息的格式<br>
log4j.appender.appenderName.layout = fully.qualified.name.of.layout.class<br>
1.org.apache.log4j.HTMLLayout（以HTML表格形式布局），<br>
2.org.apache.log4j.PatternLayout（可以灵活地指定布局模式），<br>
3.org.apache.log4j.SimpleLayout（包含日志信息的级别和信息字符串），<br>
4.org.apache.log4j.TTCCLayout（包含日志产生的时间、线程、类别等等信息）<br>
控制台选项<br>
Threshold=DEBUG:指定日志消息的输出最低层次。<br>
ImmediateFlush=true:默认值是true,意谓着所有的消息都会被立即输出。<br>
Target=System.err：默认情况下是：System.out,指定输出控制台<br>
FileAppender 选项<br>
Threshold=DEBUF:指定日志消息的输出最低层次。<br>
ImmediateFlush=true:默认值是true,意谓着所有的消息都会被立即输出。<br>
File=mylog.txt:指定消息输出到mylog.txt文件。<br>
Append=false:默认值是true,即将消息增加到指定文件中，false指将消息覆盖指定的文件内容。<br>
RollingFileAppender 选项<br>
Threshold=DEBUG:指定日志消息的输出最低层次。<br>
ImmediateFlush=true:默认值是true,意谓着所有的消息都会被立即输出。<br>
File=mylog.txt:指定消息输出到mylog.txt文件。<br>
Append=false:默认值是true,即将消息增加到指定文件中，false指将消息覆盖指定的文件内容。<br>
MaxFileSize=100KB: 后缀可以是KB, MB 或者是 GB. 在日志文件到达该大小时，将会自动滚动，即将原来的内容移到mylog.log.1文件。<br>
MaxBackupIndex=2:指定可以产生的滚动文件的最大数。<br>
log4j.appender.A1.layout.ConversionPattern=%-4r %-5p %d{yyyy-MM-dd HH:mm:ssS} %c %m%n<br>
日志信息格式中几个符号所代表的含义：<br>
&nbsp;-X号: X信息输出时左对齐；<br>
&nbsp;%p: 输出日志信息优先级，即DEBUG，INFO，WARN，ERROR，FATAL,<br>
&nbsp;%d: 输出日志时间点的日期或时间，默认格式为ISO8601，也可以在其后指定格式，比如：%d{yyy MMM dd HH:mm:ss,SSS}，输出类似：2002年10月18日 22：10：28，921<br>
&nbsp;%r: 输出自应用启动到输出该log信息耗费的毫秒数<br>
&nbsp;%c: 输出日志信息所属的类目，通常就是所在类的全名<br>
&nbsp;%t: 输出产生该日志事件的线程名<br>
&nbsp;%l: 输出日志事件的发生位置，相当于%C.%M(%F:%L)的组合,包括类目名、发生的线程，以及在代码中的行数。举例：Testlog4.main (TestLog4.java:10)<br>
&nbsp;%x: 输出和当前线程相关联的NDC(嵌套诊断环境),尤其用到像java servlets这样的多客户多线程的应用中。<br>
&nbsp;%%: 输出一个"%"字符<br>
&nbsp;%F: 输出日志消息产生时所在的文件名称<br>
&nbsp;%L: 输出代码中的行号<br>
&nbsp;%m: 输出代码中指定的消息,产生的日志具体信息<br>
&nbsp;%n: 输出一个回车换行符，Windows平台为"\r\n"，Unix平台为"\n"输出日志信息换行<br>
&nbsp;可以在%与模式字符之间加上修饰符来控制其最小宽度、最大宽度、和文本的对齐方式。如：<br>
&nbsp;1)%20c：指定输出category的名称，最小的宽度是20，如果category的名称小于20的话，默认的情况下右对齐。<br>
&nbsp;2)%-20c:指定输出category的名称，最小的宽度是20，如果category的名称小于20的话，"-"号指定左对齐。<br>
&nbsp;3)%.30c:指定输出category的名称，最大的宽度是30，如果category的名称大于30的话，就会将左边多出的字符截掉，但小于30的话也不会有空格。<br>
&nbsp;4)%20.30c:如果category的名称小于20就补空格，并且右对齐，如果其名称长于30字符，就从左边较远输出的字符截掉。<br>
二.文件配置Sample1<br>
log4j.rootLogger=DEBUG,A1,R<br>
#log4j.rootLogger=INFO,A1,R<br>
# ConsoleAppender 输出<br>
log4j.appender.A1=org.apache.log4j.ConsoleAppender<br>
log4j.appender.A1.layout=org.apache.log4j.PatternLayout<br>
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%c]-[%p] %m%n<br>
# File 输出 一天一个文件,输出路径可以定制,一般在根路径下<br>
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender<br>
log4j.appender.R.File=blog_log.txt<br>
log4j.appender.R.MaxFileSize=500KB<br>
log4j.appender.R.MaxBackupIndex=10<br>
log4j.appender.R.layout=org.apache.log4j.PatternLayout<br>
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c] [%p] - %m%n<br>
文件配置Sample2<br>
下面给出的Log4J配置文件实现了输出到控制台，文件，回滚文件，发送日志邮件，输出到数据库日志表，自定义标签等全套功能。<br>
log4j.rootLogger=DEBUG,CONSOLE,A1,im <br>
#DEBUG,CONSOLE,FILE,ROLLING_FILE,MAIL,DATABASE<br>
log4j.addivity.org.apache=true<br>
################### <br>
# Console Appender <br>
################### <br>
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender <br>
log4j.appender.Threshold=DEBUG <br>
log4j.appender.CONSOLE.Target=System.out <br>
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout <br>
log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n <br>
#log4j.appender.CONSOLE.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD]
n%c[CATEGORY]%n%m[MESSAGE]%n%n<br>
##################### <br>
# File Appender <br>
##################### <br>
log4j.appender.FILE=org.apache.log4j.FileAppender <br>
log4j.appender.FILE.File=file.log <br>
log4j.appender.FILE.Append=false <br>
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout <br>
log4j.appender.FILE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n <br>
# Use this layout for LogFactor 5 analysis<br>
######################## <br>
# Rolling File <br>
######################## <br>
log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender <br>
log4j.appender.ROLLING_FILE.Threshold=ERROR <br>
log4j.appender.ROLLING_FILE.File=rolling.log <br>
log4j.appender.ROLLING_FILE.Append=true <br>
log4j.appender.ROLLING_FILE.MaxFileSize=10KB <br>
log4j.appender.ROLLING_FILE.MaxBackupIndex=1 <br>
log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout <br>
log4j.appender.ROLLING_FILE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n<br>
#################### <br>
# Socket Appender <br>
#################### <br>
log4j.appender.SOCKET=org.apache.log4j.RollingFileAppender <br>
log4j.appender.SOCKET.RemoteHost=localhost <br>
log4j.appender.SOCKET.Port=5001 <br>
log4j.appender.SOCKET.LocationInfo=true <br>
# Set up for Log Facter 5 <br>
log4j.appender.SOCKET.layout=org.apache.log4j.PatternLayout <br>
log4j.appender.SOCET.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD]%n%c[CATEGORY]%n%m[MESSAGE]%n%n<br>
######################## <br>
# Log Factor 5 Appender <br>
######################## <br>
log4j.appender.LF5_APPENDER=org.apache.log4j.lf5.LF5Appender <br>
log4j.appender.LF5_APPENDER.MaxNumberOfRecords=2000<br>
######################## <br>
# SMTP Appender <br>
####################### <br>
log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender <br>
log4j.appender.MAIL.Threshold=FATAL <br>
log4j.appender.MAIL.BufferSize=10 <br>
<a href="mailto:log4j.appender.MAIL.From=chenyl@yeqiangwei.com">log4j.appender.MAIL.From=chenyl@yeqiangwei.com</a> <br>
log4j.appender.MAIL.SMTPHost=mail.hollycrm.com <br>
log4j.appender.MAIL.Subject=Log4J Message <br>
<a href="mailto:log4j.appender.MAIL.To=chenyl@yeqiangwei.com">log4j.appender.MAIL.To=chenyl@yeqiangwei.com</a> <br>
log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout <br>
log4j.appender.MAIL.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n<br>
######################## <br>
# JDBC Appender <br>
####################### <br>
log4j.appender.DATABASE=org.apache.log4j.jdbc.JDBCAppender <br>
log4j.appender.DATABASE.URL=jdbc:mysql://localhost:3306/test <br>
log4j.appender.DATABASE.driver=com.mysql.jdbc.Driver <br>
log4j.appender.DATABASE.user=root <br>
log4j.appender.DATABASE.password= <br>
log4j.appender.DATABASE.sql=INSERT INTO LOG4J (Message) VALUES ('[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n') <br>
log4j.appender.DATABASE.layout=org.apache.log4j.PatternLayout <br>
log4j.appender.DATABASE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n<br>
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender <br>
log4j.appender.A1.File=SampleMessages.log4j <br>
log4j.appender.A1.DatePattern=yyyyMMdd-HH'.log4j' <br>
log4j.appender.A1.layout=org.apache.log4j.xml.XMLLayout<br>
################### <br>
#自定义Appender <br>
################### <br>
log4j.appender.im = net.cybercorlin.util.logger.appender.IMAppender<br>
log4j.appender.im.host = mail.cybercorlin.net <br>
log4j.appender.im.username = username <br>
log4j.appender.im.password = password <br>
log4j.appender.im.recipient = <a href="mailto:corlin@yeqiangwei.com">corlin@yeqiangwei.com</a> <br>
log4j.appender.im.layout=org.apache.log4j.PatternLayout <br>
log4j.appender.im.layout.ConversionPattern =[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n<br>
三.高级使用<br>
实验目的：<br>
&nbsp;1.把FATAL级错误写入2000NT日志<br>
&nbsp;2. WARN，ERROR，FATAL级错误发送email通知管理员<br>
&nbsp;3.其他级别的错误直接在后台输出<br>
实验步骤：<br>
&nbsp;输出到2000NT日志<br>
&nbsp;1.把Log4j压缩包里的NTEventLogAppender.dll拷到WINNT\SYSTEM32目录下<br>
&nbsp;2.写配置文件log4j.properties<br>
# 在2000系统日志输出<br>
&nbsp;log4j.logger.NTlog=FATAL, A8<br>
&nbsp;# APPENDER A8<br>
&nbsp;log4j.appender.A8=org.apache.log4j.nt.NTEventLogAppender<br>
&nbsp;log4j.appender.A8.Source=JavaTest<br>
&nbsp;log4j.appender.A8.layout=org.apache.log4j.PatternLayout<br>
&nbsp;log4j.appender.A8.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n<br>
3.调用代码：<br>
&nbsp;Logger logger2 = Logger.getLogger("NTlog"); //要和配置文件中设置的名字相同<br>
&nbsp;logger2.debug("debug!!!");<br>
&nbsp;logger2.info("info!!!");<br>
&nbsp;logger2.warn("warn!!!");<br>
&nbsp;logger2.error("error!!!");<br>
&nbsp;//只有这个错误才会写入2000日志<br>
&nbsp;logger2.fatal("fatal!!!");<br>
发送email通知管理员：<br>
&nbsp;1. 首先下载JavaMail和JAF, <br>
&nbsp; <a href="http://java.sun.com/j2ee/ja/javamail/index.html">http://java.sun.com/j2ee/ja/javamail/index.html</a> <br>
&nbsp; <a href="http://java.sun.com/beans/glasgow/jaf.html">http://java.sun.com/beans/glasgow/jaf.html</a> <br>
&nbsp;在项目中引用mail.jar和activation.jar。<br>
&nbsp;2. 写配置文件<br>
&nbsp;# 将日志发送到email<br>
&nbsp;log4j.logger.MailLog=WARN,A5<br>
&nbsp;#&nbsp; APPENDER A5<br>
&nbsp;log4j.appender.A5=org.apache.log4j.net.SMTPAppender<br>
&nbsp;log4j.appender.A5.BufferSize=5<br>
&nbsp;<a href="mailto:log4j.appender.A5.To=chunjie@yeqiangwei.com">log4j.appender.A5.To=chunjie@yeqiangwei.com</a> <br>
&nbsp;<a href="mailto:log4j.appender.A5.From=error@yeqiangwei.com">log4j.appender.A5.From=error@yeqiangwei.com</a> <br>
&nbsp;log4j.appender.A5.Subject=ErrorLog<br>
&nbsp;log4j.appender.A5.SMTPHost=smtp.263.net<br>
&nbsp;log4j.appender.A5.layout=org.apache.log4j.PatternLayout<br>
&nbsp;log4j.appender.A5.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n<br>
&nbsp;3.调用代码：<br>
&nbsp;//把日志发送到mail<br>
&nbsp;Logger logger3 = Logger.getLogger("MailLog");<br>
&nbsp;logger3.warn("warn!!!");<br>
&nbsp;logger3.error("error!!!");<br>
&nbsp;logger3.fatal("fatal!!!");<br>
在后台输出所有类别的错误：<br>
&nbsp;1. 写配置文件<br>
&nbsp;# 在后台输出<br>
&nbsp;log4j.logger.console=DEBUG, A1<br>
&nbsp;# APPENDER A1<br>
&nbsp;log4j.appender.A1=org.apache.log4j.ConsoleAppender<br>
&nbsp;log4j.appender.A1.layout=org.apache.log4j.PatternLayout<br>
&nbsp;log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n<br>
&nbsp;2．调用代码<br>
&nbsp;Logger logger1 = Logger.getLogger("console");<br>
&nbsp;logger1.debug("debug!!!");<br>
&nbsp;logger1.info("info!!!");<br>
&nbsp;logger1.warn("warn!!!");<br>
&nbsp;logger1.error("error!!!");<br>
&nbsp;logger1.fatal("fatal!!!");<br>
--------------------------------------------------------------------<br>
&nbsp;全部配置文件：log4j.properties<br>
&nbsp;# 在后台输出<br>
&nbsp;log4j.logger.console=DEBUG, A1<br>
&nbsp;# APPENDER A1<br>
&nbsp;log4j.appender.A1=org.apache.log4j.ConsoleAppender<br>
&nbsp;log4j.appender.A1.layout=org.apache.log4j.PatternLayout<br>
&nbsp;log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n<br>
# 在2000系统日志输出<br>
&nbsp;log4j.logger.NTlog=FATAL, A8<br>
&nbsp;# APPENDER A8<br>
&nbsp;log4j.appender.A8=org.apache.log4j.nt.NTEventLogAppender<br>
&nbsp;log4j.appender.A8.Source=JavaTest<br>
&nbsp;log4j.appender.A8.layout=org.apache.log4j.PatternLayout<br>
&nbsp;log4j.appender.A8.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n<br>
# 将日志发送到email<br>
&nbsp;log4j.logger.MailLog=WARN,A5<br>
&nbsp;#&nbsp; APPENDER A5<br>
&nbsp;log4j.appender.A5=org.apache.log4j.net.SMTPAppender<br>
&nbsp;log4j.appender.A5.BufferSize=5<br>
&nbsp;<a href="mailto:log4j.appender.A5.To=chunjie@yeqiangwei.com">log4j.appender.A5.To=chunjie@yeqiangwei.com</a> <br>
&nbsp;<a href="mailto:log4j.appender.A5.From=error@yeqiangwei.com">log4j.appender.A5.From=error@yeqiangwei.com</a> <br>
&nbsp;log4j.appender.A5.Subject=ErrorLog<br>
&nbsp;log4j.appender.A5.SMTPHost=smtp.263.net<br>
&nbsp;log4j.appender.A5.layout=org.apache.log4j.PatternLayout<br>
&nbsp;log4j.appender.A5.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n<br>
全部代码：Log4jTest.java<br>
&nbsp; <br>
/* <br>
&nbsp; * 创建日期 2003-11-13 <br>
&nbsp; */ <br>
&nbsp;package edu.bcu.Bean; <br>
&nbsp;import org.apache.log4j.*; <br>
&nbsp;//import org.apache.log4j.nt.*; <br>
&nbsp;//import org.apache.log4j.net.*; <br>
&nbsp;/** <br>
&nbsp; * @author yanxu <br>
&nbsp; */ <br>
&nbsp;public class Log4jTest <br>
&nbsp;{ <br>
&nbsp; public static void main(String args[]) <br>
&nbsp; { <br>
&nbsp;&nbsp; PropertyConfigurator.configure("log4j.properties"); <br>
&nbsp;&nbsp; //在后台输出 <br>
&nbsp;&nbsp; Logger logger1 = Logger.getLogger("console"); <br>
&nbsp;&nbsp; logger1.debug("debug!!!"); <br>
&nbsp;&nbsp; logger1.info("info!!!"); <br>
&nbsp;&nbsp; logger1.warn("warn!!!"); <br>
&nbsp;&nbsp; logger1.error("error!!!"); <br>
&nbsp;&nbsp; logger1.fatal("fatal!!!");<br>
//在NT系统日志输出 <br>
&nbsp;&nbsp; Logger logger2 = Logger.getLogger("NTlog"); <br>
&nbsp;&nbsp; //NTEventLogAppender nla = new NTEventLogAppender(); <br>
&nbsp;&nbsp; logger2.debug("debug!!!"); <br>
&nbsp;&nbsp; logger2.info("info!!!"); <br>
&nbsp;&nbsp; logger2.warn("warn!!!"); <br>
&nbsp;&nbsp; logger2.error("error!!!"); <br>
&nbsp;&nbsp; //只有这个错误才会写入2000日志 <br>
&nbsp;&nbsp; logger2.fatal("fatal!!!");<br>
//把日志发送到mail <br>
&nbsp;&nbsp; Logger logger3 = Logger.getLogger("MailLog"); <br>
&nbsp;&nbsp; //SMTPAppender sa = new SMTPAppender(); <br>
&nbsp;&nbsp; logger3.warn("warn!!!"); <br>
&nbsp;&nbsp; logger3.error("error!!!"); <br>
&nbsp;&nbsp; logger3.fatal("fatal!!!"); <br>
&nbsp; } <br>
&nbsp;}]]></description>
</item><item>
<title><![CDATA[Java安全通信、数字证书及应用实践]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=guan1200&amp;id=8118</link>
<author>guan1200</author>
<pubDate>2005/8/30 10:17:26</pubDate>
<description><![CDATA[<font size="4"><a>　<strong><font color="#0e3e92"><table border="0" cellpadding="0" cellspacing="0" width="603"><tbody><tr><td valign="top" width="220"><table border="0" cellpadding="0" cellspacing="0" width="220"><tbody><tr><td colspan="2"><font class="f21" color="#0e3e92"><b>[文章信息]</b></font></td></tr></tbody></table></td></tr></tbody></table></font></strong>
</a></font>
<table border="0" cellpadding="0" cellspacing="0" width="220">

<tbody>
<tr>
<td valign="top" width="62"><font size="4">作者:</font></td>
<td valign="top" width="158"><font color="#0e3e92" size="4">柴政</font></td></tr></tbody>
</table>

<p><font size="4"><strong><font color="#0e3e92">[文章导读]</font></strong></font></p>

<p><font size="4"><span class="f14">在本文中，我用详细的语言和大量的图片及完整的程序源码向你展示了在 JAVA中如何实现生成数字证书</span></font></p>

<p><font size="4"><span class="f14"><strong><font color="#0e3e92">[正文]</font></strong></span></font></p>

<p><font size="4"><span class="f14"><strong>摘要</strong>： <br><br>　　在本文中，我用详细的语言和大量的图片及完
整的程序源码向你展示了在
JAVA中如何实现通过消息摘要、消息验证码达到安全通信、以及用Java的工具生成数字证书，和用程序给数字证书签名、以及用签名后的数学证书签名
applet突破applet的访问权限的过程，给出了全部例子的详细代码。<br><br>　　通过本文中你可以学到以下知识： <br><br>　　 ● 程序间如何安全通信 <br><br>　　 ● 什么是 及 如何生成消息摘要 <br><br>　　 ● 什么是 及 如何生成消息验证码 <br><br>　　 ● 如何使用 Java工具生成和维护数字证书库 <br><br>　　 ● 如何用程序给数字证书验证签名 <br><br>　　 ● 如何利用数字证书给 applet签名突破applet的访问权限 <br><br>　　<strong>关键字</strong>： <br><br>　　消息摘要、消息验证码、指纹、加密、安全、 Java、数字签名、applet、数字证书 <br><br>　　<strong>一、基础知识</strong> <br><br>　　计算机安全通信过程中，常使用消息摘要和消息验证码来保证传输的数据未曾被第三方修改。 <br><br>　
　消息摘要是对原始数据按照一定算法进行计算得到的结果，它主要检测原始数据是否被修改过。消息摘要与加密不同，加密是对原始数据进行变换，可以从变换后
的数据中获得原始数据，而消息摘要是从原始数据中获得一部分信息，它比原始数据少得多，因此消息摘要可以看作是原始数据的指纹。 <br><br>　　例：下面一段程序计算一段字符串的消息摘要 </span></font></p>
<font size="4"><span class="f14">
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">
<p><span class="f14">package com.messagedigest; <br>import java.security.*; <br>public class DigestPass { <br>　public static void main(String[] args) throws Exception{ <br>　　String str="Hello,I sent to you 80 yuan."; <br>　　MessageDigest md = MessageDigest.getInstance("MD5");//常用的有MD5,SHA算法等 <br>　　md.update(str.getBytes("UTF-8"));//传入原始字串 <br>　　byte[] re = md.digest();//计算消息摘要放入byte数组中 <br>　　//下面把消息摘要转换为字符串 <br>　　String result = ""; <br>　　for(int i=0;i＜re.length;i++){ <br>　　　result += Integer.toHexString((0x000000ff&amp;re[i])|0xffffff00).substring(6); <br>　　} <br>　　System.out.println(result); <br>　} <br>} </span></p></div>
<p>当我们有时需要对一个文件加密时，以上方式不再适用。 <br><br>　　又例：下面一段程序计算从输入（出）流中计算消息摘要。</p>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">
<p>package com.messagedigest; <br>import java.io.*; <br>import java.security.*; <br>public class DigestInput { <br>　public static void main(String[] args) throws Exception{ <br>　　String fileName = "test.txt"; <br>　　MessageDigest md = MessageDigest.getInstance("MD5"); <br>　　FileInputStream fin = new FileInputStream(fileName); <br>　　DigestInputStream din = new DigestInputStream(fin,md);//构造输入流 <br>　　//DigestOutputStream dout = new DigestOutputStream(fout,md); <br>　　//使用输入（出）流可以自己控制何时开始和关闭计算摘要 <br>　　//也可以不控制，将全过程计算 <br>　　//初始时是从开始即开始计算，如我们可以开始时关闭，然后从某一部分开始，如下： <br>　　//din.on(false); <br>　　int b; <br>　　while((b=din.read())!=-1){ <br>　　　//做一些对文件的处理 <br>　　　//if(b=='$') din.on(true); //当遇到文件中的符号$时才开始计算 <br>　　} <br>　　byte[] re = md.digest();//获得消息摘要 <br>　　//下面把消息摘要转换为字符串 <br>　　String result = ""; <br>　　for(int i=0;i＜re.length;i++){ <br>　　　result += Integer.toHexString((0x000000ff&amp;re[i])|0xffffff00).substring(6); <br>　　} <br>　　System.out.println(result); <br>　} <br>} </p></div>当A和B通信时，A将数据传给B时，同时也将数据的消息摘要传给B，B收到后可以用该消息摘要验证A传的消息是否正确。这时会产生问题，即若传递过程中别人修改了数据时，同时也修改了消息摘要。B就无法确认数据是否正确。消息验证码可以解决这一问题。 <br><br>　　使用消息验证码的前提是 A和B双方有一个共同的密钥，这样A可以将数据计算出来的消息摘要加密后发给B，以防止消息摘要被改。由于使用了共同的密钥，所以称为“验证码”。 <br><br>　　例、下面的程序即可利用共同的密钥来计算消息摘要的验证码 <br>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">package com.mac; <br>import java.io.*; <br>import java.security.*; <br>import javax.crypto.*; <br>import javax.crypto.spec.*; <br>public class MyMac { <br>　public static void main(String[] args) throws Exception{ <br>　　//这是一个消息摘要串 <br>　　String str="TestString"; <br>　　//共同的密钥编码，这个可以通过其它算法计算出来 <br>　　byte[] kb={11,105,-119,50,4,-105,16,38,-14,-111,21,-95,70,-15,76,-74, <br>　　　　67,-88,59,-71,55,-125,104,42}; <br>　　//获取共同的密钥 <br>　　SecretKeySpec k = new SecretKeySpec(kb,"HMACSHA1"); <br>　　//获取Mac对象 <br>　　Mac m = Mac.getInstance("HmacMD5"); <br>　　m.init(k); <br>　　m.update(str.getBytes("UTF-8")); <br>　　byte[] re = m.doFinal();//生成消息码 <br>　　//下面把消息码转换为字符串 <br>　　String result = ""; <br>　　for(int i=0;i＜re.length;i++){ <br>　　　result += Integer.toHexString((0x000000ff&amp;re[i])|0xffffff00).substring(6); <br>　　} <br>　　System.out.println(result); <br>　} <br>} </div>
<p>使用以上两种技术可以保证数据没有经过改变，但接收者还无法确定数据是否确实是某个人发来的。尽管消息码可以确定数据是某个有同样密钥的人发来的，但这要求双方具有共享的密钥，若有一组用户共享，我们就无法确定数据的来源了。 <br><br>　
　数字签名可以解决这一问题。数字签名利用非对称加密技术，发送者使用私钥加密数据产生的消息摘要（签名），接收者使用发送者的公钥解密消息摘要以验证签
名是否是某个人的。由于私钥只有加密者才有，因此如果接收者用某个公钥解密了某个消息摘要，就可以确定这段消息摘要必然是对应的私钥持有者发来的。 <br><br>　　使用数字签名的前提是接收数据者能够确信验证签名时（用发送者的私钥加密消息摘要）所用的公钥确实是某个人的 (因为有可能有人假告公钥)。数字证书可以解决这个问题。 <br><br>　
　数字证书含有两部分数据：一部分是对应主体（单位或个人）的信息，另一部分是这个主体所对应的公钥。即数字证书保存了主体和它的公钥的一一对应关系。同
样，数字证书也有可能被假造，如何判定数字证书的内容的真实性呢？所以，有效的数字证书必须经过权威
CA的签名，即权威CA验证数字证书的内容的真实性，然后再在数字证书上使用自己的私钥签名（相当于在证书加章确认）。 <br><br>　　这样，当用户收到这样的数字证书后，会用相应的权威 CA的公钥验证该证书的签名(因为权威的CA的公钥在操作系统中己经安装)。根据非对称加密的原理，如果该证书不是权威CA签名的，将不能通过验证，即该证书是不可靠的。 <br><br>　　若通过验证，即可证明此证书含的信息（发信人的公钥和信息）是无误的。于是可以信任该证书，便可以通过该证书内含的公钥来确认数据确实是发送者发来的。 <br><br>　
　于是，双方通信时，
A把数据的消息摘要用自己的私钥加密（即签名），然后把自己的数字证书和数据及签名后的消息摘要一起发送给B，B处查看A的数字证书，如果A的数字证书是
经过权威CA验证可靠的，便信任A，便可使用A的数字证书中附带的A的公钥解密消息摘要（这一过程同时确认了发送数据的人又可以解密消息摘要），然后通过
解密后的消息摘要验证数据是否正确无误没被修改。 <br><br>　　利用这一原理，我们可以突破
java的applet小程序在浏览器中的权限，由于默认的applet权限控制不允许它访问操作系统级的一切。于是我们可以用我们数字证书来给
applet签名，然后客户端收到该applet时，系统会自动查看给该applet签名的数字证书并提供给终端用户判定是否信认该数字证书，如果用户信
认，则该applet便有了访问系统的权限。</p>
<p><strong>二、 Java中的数字证书的生成及维护方法</strong></p>
<p>Java中的keytool.exe可以用来创建数字证书，所有的数字证书是以一条一条(采用别名区别)的形式存入证书库的中，证书库中的一条证书
包含该条证书的私钥，公钥和对应的数字证书的信息。证书库中的一条证书可以导出数字证书文件，数字证书文件只包括主体信息和对应的公钥。 <br><br>　　每一个证书库是一个文件组成，它有访问密码，在首次创建时，它会自动生成证书库，并要求指定访问证书库的密码。 <br><br>　　在创建证书的的时候，需要填写证书的一些信息和证书对应的私钥密码。这些信息包括 CN=xx,OU=xx,O=xx,L=xx,ST=xx,C=xx，它们的意思是： <br><br>　　CN(Common Name名字与姓氏) <br><br>　　OU(Organization Unit组织单位名称) <br><br>　　O(Organization组织名称) <br><br>　　L(Locality城市或区域名称) <br><br>　　ST(State州或省份名称) <br><br>　　C(Country国家名称） <br><br>　　可以采用交互式让工具提示输入以上信息，也可以采用参数 <br><br>-dname "CN=xx,OU=xx,O=xx,L=xx,ST=xx,C=xx"来自动创建。 <br><br>　　<strong>1、示例</strong> <br><br>　　如下所示一句采用交互式创建一个证书，指定证书库为 abnerCALib，创建别名为abnerCA的一条证书，它指定用RSA算法生成， <br><br>　　且指定密钥长度为 1024，证书有效期为3650天：</p>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">
<p>C:\j2sdk1.4.1_01\mykeystore＞keytool -genkey -alias abnerCA -keyalg RSA -keysize 1024 -keystore abnerCALib -validity 3650 </p></div>
<p>如下图所示： <br><a href="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/2005818204627780.JPG" target="_blank"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/2005818204627780.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a></p>
<p>上图中最后一步，我们输入的是 CN，代表中国的缩写，也可以直接输入“中国”两个字。 <br><br>　　<strong>2、证书的操作方法</strong> <br><br>　　● 证书的显示 <br><br>　　如： <br></p>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">keytool –list –keystore abnerCALib </div>
<p>将显示 abnerCALib证书库的的所有证书列表：如下图示： </p>
<p><a href="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/200581820515892.JPG" target="_blank"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/200581820515892.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a><br>又如： keytool -list -alias abnerCA -keystore abnerCALib <br><br>　　将显示 abnerCALib证书库中别名为abnerCA的证书的信息。如下图所示： </p>
<p><a href="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/2005818205129483.JPG" target="_blank"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/2005818205129483.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a></p>
<p>又如： keytool -list -v -alias abnerCA -keystore abnerCALib <br><br>　　将显示证书的详细信息（ -v参数）如下图所示： <br><br><a href="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/2005818205159558.JPG" target="_blank"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/2005818205159558.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a></p>
<p>● 将证书导出到证书文件 <br><br>　　如： keytool -export -alias abnerCA -file abnerCA.cer -keystore abnerCALib <br>　　将把证书库 abnerCALib中的别名为abnerCA的证书导出到abnerCA.cer证书文件中， <br><br>　　它包含证书主体的信息及证书的公钥，不包括私钥，可以公开，如下图所示 : <br><br><a href="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/2005818205225949.JPG" target="_blank"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/Blog/myblog/uploadfile/2005818205225949.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a></p>
<p>上面导出的证书文件是以二进制编码文件，无法用文本编辑器正确显示，因此不利用公布证书，可以加上 -rfc参数以一种可打印的编者编码输出。 <br><br>　　如： <br></p>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">keytool -export –rfc -alias abnerCA -file abnerCA.cer -keystore abnerCALib -storepass 100200</div>这个命令在命令行中指定了证书库的访问密码，同时指定以可查看编码的方式输出。 <br>　<br>　　<strong>3、通过证书文件查看证书的信息 </strong><br><br>　　通过命令 :keytool –printcert –file abnerCA.cer可以查看证书文件的信息。 <br><br>　　也可以在 windows中双击产生的证书文件直接查看。 <br><br>　　● 证书条目的删除 <br><br>　　keytool的命令行参数-delete可以删除密钥库中的条目，如： <br><br>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">keytool -delete -alias abnerCA -keystore abnerCALib</div>这条命令将 abnerCALib库中的abnerCA这一条证书删除了。 <br><br>　　● 证书条目口令的修改 <br><br>　　如： <br>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">keytool –keypasswd –alias abnerCA –keystore abnerCALib</div>
<p>可以以交互的方式修改 abnerCALib证书库中的条目为abnerCA的证书。</p>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">
<p>Keytool –keypasswd –alias abnerCA –keypass 123456 –new 200100 –storepass 1002 00 –keystore abnerCALib </p></div>
<p>这一行命令以非交互式的方式修改库中别名为 abnerCA的证书的密码为新密码123456，行中的200100是指该条证书的原密码， 1002 00是指证书库的密码。 </p>
<p><strong>三、数字证书的签发（签名）</strong></p>
<p>我们在上面创建好了数字证书，但这些数字证书还没有经过权威 CA的证实（即签名）。一般情况下，我们需要将这些证书发送给权威的CA，并申请其签名以确认数字证书让客户信任。 <br><br>　
　下面我们将模仿自己是一个权威的数字证书认证机构
CA，这个机构将采用自己的私钥来签发其它的证书。这个签发过程是这样的：我们自己是CA，我们自己有一个自签的数字证书存入数字证书库中。在数字证书库
中的这个我们的CA数字证书，它含有私钥，公钥和我们这个CA的主体信息。下面这一个指令可以创建一个CA的自签的数字证书： <br><br>　　
keytool –genkey –dname
“CN=美森系统软件有限公司,OU=美森系统软件有限公司,O=美森系统软件有限公司,L=成都市,ST=四川省,C=中国” –alias
MissionCA –keyalg RSA –keysize 1024 –keystore abnerCALib –keypass
200100 –storepass 100200 –validity 3650 <br><br>　　上面，我们在
abnerCALib这个数字证书库中创建了一个别名为：missionCA、有效期为3650天、算法为RSA且密钥长度为1024的数字证书，这条证
书的私钥密码为：200100，证书库的访问密码为：100200。这条别名为missionCA的证书代表我们自己的权威CA即：美森系统软件有限公司
这个权威CA。以后我们将用这个证书来签名其它的数字证书。 <br><br>　　现在我要给自己申请一个数字证书，我可以这么做：先在数字证书库中创建一条证书： <br><br>keytool
–genkey –dname “CN=柴政,OU=美森系统软件有限公司,O=美森系统软件有限公司,L=成都市,ST=四川省,C=中国”
–alias abnerCA –keyalg RSA –keysize 1024 –keystore abnerCALib –keypass
200100 –storepass 100200 –validity 3650 <br><br>　　这样创建了一个别名为 abnerCA的数字证书，我们可以将它导出为cer文件（见前）。 <br><br>　　接着，我们可以用上一步生成的 CA的自签证书来签名我这个数字证书了。 <br><br>　　CA签名数字证书的过程需用以下程序来进行，这个程序是自解释的：</p>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">
<p>package com.security; <br>import java.io.*; <br>import java.security.*; <br>import java.security.cert.*; <br>import java.util.*; <br>import java.math.*; <br>import sun.security.x509.*; <br>/** <br>* ＜p＞Description: 该程序根据签发者（CA）的证书信息（即CA的私钥）来对被签发者 <br>* 的证书进行签名，过程即是使用CA的证书和被签证书来重构形成一个新的证书＜/p＞ <br>* @author abnerchai <br>* @version 1.0 <br>*/ <br><br>　public class SignCert { <br>　　public static void main(String[] args) throws Exception{ <br>　　　char[] storepass = "100200".toCharArray();<br>　　　//存放CA证书和被签证书的证书库的访问密码 <br>　　　char[] cakeypass = "200100".toCharArray();//CA数字证书条目的访问密码 <br>　　　String alias = "missionCA";<br>　　　//CA证书在证书库中的别名，这个CA的证书用来签名其它的证书 <br>　　　String name = "abnerCALib";//存放CA证书和被签证书的证书库的名字 <br>　　　String newLib = "SignedLib";<br>　　　//新证书库的名字，如果需要将签名后的证书放入新库，这是新库的名字 <br>　　　char[] newLibPass = "100200".toCharArray();//设置新库的访问密码 <br>　　　String cerFileName = "abnerCA.cer";//被签证书的证书文件名 <br>　　　String aliasName = "abnerCA";//被签证书在证书库中的alias别名 <br>　　　char[] namePass = "200100".toCharArray();<br>　　　//被签证书的条目在证书库的私钥密码 <br>　　　int n =3; //被签证书的有效期，以年为单位，以当前时间开始计算 <br>　　　int sn = 200406001;<br>　　　//序列号可自己定义，这里定义的意义为2004年6月签发，是本年度CA签发的第多少个以001计算，要求唯一 <br>　　　String afteraliasName = "abnerCA_Signed"; <br>　　　//签名后新产生的被签过名的证书在库中的别名 <br>　　　char[] afterNewPass = "200100".toCharArray(); <br>　　　//签名后新产生的被签过名的证书在库的条目的私钥的密码 <br>　　　//装载证书库 <br>　　　FileInputStream in = new FileInputStream(name); <br>　　　KeyStore ks = KeyStore.getInstance("JKS");//JKS为证书库的类型 <br>　　　ks.load(in,storepass); <br>　　　//从证书库中读出签发者（CA）的证书 <br>　　　java.security.cert.Certificate cl = ks.getCertificate(alias);<br>　　　//读出一个CA证书,这里的l是字母l不是数据字1 <br>　　　PrivateKey privateKey = (PrivateKey)ks.getKey(alias,cakeypass);<br>　　　//根据别名和证书密码读出CA证书的私钥 <br>　　　in.close(); <br>　　　//从证书库中读出的签发者(CA)的证书中提取签发者的信息 <br>　　　byte[] encodl = cl.getEncoded();//提取证书的编码，这里是字母l不是数据字1 <br>　　　X509CertImpl cimpl = new X509CertImpl(encodl);<br>　　　//这里是字母l不是数据字1，根据证书的编码创建X509CertImpl类型的对象 <br>　　　//根据上面的对象获得X509CertInfo类型的对象，该对象封装了证书的全部内容。 <br>　　　X509CertInfo cinfo_first = <br>　　　　(X509CertInfo)cimpl.get(X509CertImpl.NAME+"."+X509CertImpl.INFO); <br>　　　//然后获得X500Name类型的签发者信息 <br>　　　X500Name issuer = (X500Name) <br>　　　cinfo_first.get(X509CertInfo.SUBJECT+"."+CertificateIssuerName.DN_NAME); <br>　　　//获取待签发的证书，即获取被签发者的证书 <br>　　　//可从密钥库中获取，也可从导出的证书文件中获取，这里给出两种方式 　　//////////////////////////////////////////////////////////////////////// <br><br>//方式一、采用从导出的cer文件中获取 start <br><br>/////////////////////////////////////////////////////////////////////////////// <br><br>/* <br><br>　　CertificateFactory cf = CertificateFactory.getInstance("X.509");<br>　　//X.509是使用最多的一种数字证书标准 <br><br>　　FileInputStream in2 = new FileInputStream(cerFileName);//被签证书文件 <br><br>　　java.security.cert.Certificate c2 = cf.generateCertificate(in2);<br>　　//生成需要被签的证书 <br>　　in2.close(); <br>　　byte[] encod2 = c2.getEncoded(); <br>　　X509CertImpl cimp2 = new X509CertImpl(encod2); <br><br>　　//获得被签证书的详细内容，然后根据这个证书生成新证书 <br><br>　　X509CertInfo cinfo_second = <br>　　　(X509CertInfo)cimp2.get(X509CertImpl.NAME+"."+X509CertImpl.INFO); <br>*/ <br><br>/////////////////////////////////////////////////////////////////////////////// <br><br>//end 方式一 <br><br>/////////////////////////////////////////////////////////////////////////////// <br><br>/////////////////////////////////////////////////////////////////////////////// <br><br>//方式二、从证书库中读出被签的证书 start <br><br>/////////////////////////////////////////////////////////////////////////////// <br><br>　　java.security.cert.Certificate c3 = ks.getCertificate(aliasName);<br>　　//从证书库中读出被签证书，然后生成新的证书 <br>　　byte[] encod3 = c3.getEncoded(); <br>　　X509CertImpl cimp3 = new X509CertImpl(encod3); <br>　　X509CertInfo cinfo_second = <br>　
　　(X509CertInfo)cimp3.get(X509CertImpl.NAME+"."+X509CertImpl.INFO);
///////////////////////////////////////////////////////////////////////////
<br><br>//end方式二 <br><br>/////////////////////////////////////////////////////////////////////////// //设置新证书的有效期，使之为当前向后n年有效，新证书的 <br><br>　　//截止日期不能超过CA证书的有效日期 <br><br>　　Date beginDate = new Date(); <br>　　Calendar cal = Calendar.getInstance(); <br>　　cal.setTime(beginDate); <br>　　cal.add(cal.YEAR,n); <br>　　Date endDate = cal.getTime(); <br>　　CertificateValidity cv = new CertificateValidity(beginDate,endDate); <br>　　cinfo_second.set(X509CertInfo.VALIDITY,cv); <br>　　//设置新证书的序列号 <br><br>　　CertificateSerialNumber csn = new CertificateSerialNumber(sn); <br>　　cinfo_second.set(X509CertInfo.SERIAL_NUMBER,csn); <br>　　//设置新证书的签发者 <br>　　cinfo_second.set(X509CertInfo.ISSUER+"."+CertificateIssuerName.DN_NAME,issuer); <br>　　//新的签发者是CA的证书中读出来的 <br><br>　　//设置新证书的算法，指定CA签名该证书所使用的算法为md5WithRSA <br><br>　　AlgorithmId algorithm = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid); <br>　　cinfo_second.set(CertificateAlgorithmId.NAME+"."+ <br>　　CertificateAlgorithmId.ALGORITHM,algorithm); <br><br>　　//创建新的签名后的证书 <br><br>　　X509CertImpl newcert = new X509CertImpl(cinfo_second); <br><br>　　//签名,使用CA证书的私钥进行签名，签名使用的算法为MD5WithRSA <br><br>　　newcert.sign(privateKey,"MD5WithRSA");//这样便得到了经过CA签名后的证书 <br><br>　　//把新证书存入证书库 <br>　　//把新生成的证书存入一个新的证书库，也可以存入原证书库， <br>　　//存入新证书库，则新证书库中不仅包含原证书库中的所有条目， <br>　　//而且新增加了一个这次产生的条目。注意，这时，新产生的签名后的证书只 <br>　　//包括公钥和主体信息及签名信息，不包括私钥信息。这里给出两种方式。 <br>/////////////////////////////////////////////////////////////////////////// <br><br>//方式一：存入新密钥库 <br><br>/////////////////////////////////////////////////////////////////////////// <br><br>/* <br><br>ks.setCertificateEntry(afteraliasName,newcert); <br>FileOutputStream out = new FileOutputStream(newLib); <br>//存入新库signedLib，并设置新库的库访问密码 <br>ks.store(out,newLibPass); <br>out.close(); <br>*/ <br><br>/////////////////////////////////////////////////////////////////////////// <br><br>//end 方式一 <br><br>/////////////////////////////////////////////////////////////////////////// <br><br>//也可以采用另外一种方式，存入原证书库中 <br><br>//存入原库中，即在原证书库中增加一条证书，这个证书是原证书经过签名后的证书 <br><br>//这个新证书含有私钥和私钥密码 <br><br>/////////////////////////////////////////////////////////////////////////// <br><br>//方式二，存入原密钥库 <br><br>/////////////////////////////////////////////////////////////////////////// <br><br>//先在原库中读出被签证书的私钥 <br><br>PrivateKey prk = (PrivateKey)ks.getKey(aliasName,namePass); <br>java.security.cert.Certificate[] cchain = {newcert}; <br>//存入原来的库,第二个参数为原证书的私钥，第三个参数为新证书的私钥密码，第三个参数为新证书 <br><br>ks.setKeyEntry(afteraliasName,prk,afterNewPass,cchain); //用新密钥替代原来的没有签名的证书的密码 <br><br>FileOutputStream out2 = new FileOutputStream(name); <br>ks.store(out2,storepass);//存入原来的库中，第二个参数为该库的访问密码 <br><br>/////////////////////////////////////////////////////////////////////////// <br><br>//end 方式二 <br><br>/////////////////////////////////////////////////////////////////////////// <br><br>} <br><br>} </p></div>
<p>运行以上程序，即可运用 MissionCA证书来签发abnerCA证书，运行后在abnerCALib中增加一条别名为abnerCA_Signed的数字证书，我们将它导出为cer文件（导出方法见前）。 <br><br>　　至此，我们己经用 CA的证书以我们的数字证书签名了。在windows中，双击导出的abnerCA_Signend.cer文件，出现如下图所示： <br><a href="http://bbs.csai.cn/blog/uploadfile/200581821535703.JPG"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/uploadfile/200581821535703.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a></p>
<p>上图中证书信息一栏显示“不能验证该证书”，原因是因为，我们的这个数字证书的签发者 missionCA证书没有安装到系统中。我们可以将证书库中别名为missionCA的自签数字证书导出为cer文件，然后安装到系统中。再次查双击看此证书，如下图所示： <br><a href="http://bbs.csai.cn/blog/uploadfile/200581821610464.JPG"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/uploadfile/200581821610464.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a></p>
<p>到此，我们己经获得了一个由我们自己的 CA签名颁发的个人数字证书。并且将我们自己的CA证书安装到系统中成为系统信任的根证书。于是，以后只要是由我们的这个CA证书签名颁发的数字证书都会受到系统的信任。 <br><br><strong>四、利用数字证书给 applet签名</strong></p>
<p>现在假设我们公司给
xx公司做一个项目，这个项目中需要用到applet，且这些applet需要特权以实现一些特殊的功能(如读出客户端用户系统中C:\winNT\
system.ini文件中的内容并显示)。那么我们可以颁发一个数字证书，并给这个数字证书签名，然后用签名后的这个数字证书来签名我们的
applet，使客户信任。具体过程如下： <br><br>　　1、生成一个用于此项目签名 applet 的数字证书，别名定为： mission_water <br><br>　　生成一个用于此项目签名的数字证书如下： <br><br>　
　keytool –genkey –dname
“CN=美森软件-水公司项目,OU=美森系统软件有限公司,O=美森系统软件有限公司,L=成都市,ST=四川省,C=中国” –alias
Mission_Water –keyalg RSA –keysize 1024 –keystore abnerCALib –keypass
200100 –storepass 100200 –validity 3650 <br><br>　　2、用我们的 CA(missinCA) 来签发这个数字证书 <br><br>　　然后，运行我们在前面第三节中给定的程序，注意：运行此程序前，请修改以下参数：</p>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">
<p>String cerFileName = "Mission_Water.cer"; <br><br>String aliasName = "Mission_Water"; <br><br>String afteraliasName = "Mission_Water_Signed"; </p></div>然后运行，程序会在 abnerCALib证书库中产生一个别名为：Mission_Water_Signed的数字证书，这个证书是经过我们的CA（MissionCA）签发的。 <br><br>　　下面，我们用以下指令导出这个证书： <br>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">keytool -export -rfc -alias Mission_Water_Signed -file Mission_Water_Signed.cer -keystore abnerCALib</div>会生成一个 Mission_Water_Signed.cer 文件。 <br><br>　　3、用签发后的数字证书来签名我们的 applet <br><br>　　我们现在来做一个简单的 applet，它的代码如下： <br>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">package com.applet; <br><br>import java.awt.*; <br><br>import java.awt.event.*; <br><br>import java.applet.*; <br><br>import javax.swing.*; <br><br>import java.io.*; <br><br>public class ShowFileApplet extends JApplet { <br><br>private boolean isStandalone = false; <br><br>private String content = "文件的内容是："; //自定义的提示信息 <br><br>private String fileName = "C:\\WINNT\\system.ini";//读出这个文件的内容 <br><br>private TextArea ta = new TextArea(10,80);//自定义的输出框 <br><br>public String getParameter(String key, String def) { <br><br>return isStandalone ? System.getProperty(key, def) : <br><br>(getParameter(key) != null ? getParameter(key) : def); <br><br>} <br><br>public ShowFileApplet() { <br><br>} <br><br>public void init() { <br><br>try { <br><br>jbInit(); <br><br>myInit();//自己定义的方法 <br><br>} <br><br>catch(Exception e) { <br><br>e.printStackTrace(); <br><br>} <br><br>} <br><br>private void jbInit() throws Exception { <br><br>this.setSize(new Dimension(400,300)); <br><br>} <br><br>/** <br><br>* 自定义的初始化方法，读入系统中的一个文件的内容并保存起来，然后，增加一个 <br><br>* 可视化的输出框 <br><br>*/ <br><br>private void myInit(){ <br><br>String s; <br><br>BufferedReader in; <br><br>try { <br><br>in = new BufferedReader(new FileReader(fileName)); <br><br>while ( (s = in.readLine()) != null) { <br><br>content +=s + "\n"; <br><br>} <br><br>}catch (IOException ex) { <br><br>ex.printStackTrace(); <br><br>} <br><br>System.out.println(content); <br><br>ta.setText(content); <br><br>getContentPane().add(ta); <br><br>} <br><br>/* <br><br>*重载的方法，输出内容 <br><br>**/ <br><br>public void paint(Graphics g){ <br><br>ta.setText(content); <br><br>} <br><br>public String getAppletInfo() { <br><br>return "Applet Information"; <br><br>} <br><br>public String[][] getParameterInfo() { <br><br>return null; <br><br>} <br><br>//static initializer for setting look &amp; feel <br><br>static { <br><br>try { <br><br>} <br><br>catch(Exception e) { <br><br>} <br><br>} <br><br>} </div>好了，这个 applet写好了，下面我们来把这个applet编译打包成jar文件。 <br><br>　　编译此 applet文件，会在当前目录(当前目录为classes目录)下生成一个com\applet的目录结构，在applet目录下有一个ShowFileApplet.class，进入当前目录，执行： <br><br>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">jar cvf myapplet.jar com/applet/*.* </div>于是在当前目录下产生一个 myapplet.jar文件。 <br><br>　
　然后再在当前目录（当前目录为
classes目录）下新建一个applet目录，专门存放applet的jar文件，把前面生成的数字证书库abnerCALib这个文件也copy到
applet目录下面来，同时把刚才生成的myapplet.jar文件也移到applet目录下面来。然后进入该目录执行： <br><br>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">jarsigner -keystore abnerCALib myapplet.jar Mission_Water_Signed <br><br>Enter Passphrase for keystore: 100200 <br><br>Enter key password for Mission_Water_Signed: 200100 </div>
<p>即用 Mission_Water_Signed这个我们的CA签发的数字证书给这个applet签名了。</p>
<p>4、运行我们的 applet<strong> </strong><br><br>　　我们来写一个 html文件来运行这个签名后的applet，内容如下：</p>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">
<p>＜!-- ShowFileApplet.html --＞ <br><br>＜html＞ <br><br>＜head＞ <br><br>＜meta http-equiv="Content-Type" content="text/html; charset=GB2312"＞ <br><br>＜title＞HTMLTestPage＜/title＞ <br><br>＜/head＞＜body＞ <br><br>applet将会显示，如果你的浏览器支持Java＜br＞ <br><br>＜applet <br><br>archive = "./applet/myapplet.jar" <br><br>code = "com.applet.ShowFileApplet.class" <br><br>name = "TestApplet" <br><br>width = "400" <br><br>height = "300" <br><br>hspace = "0" <br><br>vspace = "0" <br><br>align = "middle" <br><br>＞ <br><br>＜/applet＞ <br><br>＜/body＞ <br><br>＜/html＞ </p></div>
<p>这个
HTML文件可以运行applet，但如果浏览器不支持Java，即没有安装JRE，它不会提示用户去下载安装。我们可以用Java自带的
htmlconverter工具转换一下这个HTML文件，转换后的文件可以在支持JAVA2的浏览器中（不管该浏览器是否设置了使用java2运行
applet，它都会在Java2环境中运行applet，如果浏览器不支持Java2，则会自动下载所需的文件。 <br><br>　　在 DOS方式下运行htmlconverter，弹出如下图所示画框，按图中所示选择刚才的那个HTML文件，如下图所示： <br><a href="http://bbs.csai.cn/blog/uploadfile/2005818211939498.JPG"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/uploadfile/2005818211939498.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a></p>
<p>点“转换”，将会在当前目录下生成一个 HTML文件，并把原来的HTML文件备份了。 <br><br>　　生成后的 HTML文件内容如下所示： <br></p>
<div class="quote" title="Click to run the code" style="" onclick="preWin=window.open('','','');preWin.document.open();preWin.document.write(this.innerText);preWin.document.close();" ;="">＜!-- ShowFileApplet.html --＞ <br><br>＜html＞ <br><br>＜head＞ <br><br>＜meta http-equiv="Content-Type" content="text/html; charset=GB2312"＞ <br><br>＜title＞HTMLTestPage＜/title＞ <br><br>＜/head＞ <br><br>＜body＞ <br><br>applet将会显示，如果你的浏览器支持Java＜br＞ <br><br>＜OBJECT <br><br>classid = "clsid:CAFEEFAC-0014-0001-0001-ABCDEFFEDCBA" <br><br>codebase = "http://java.sun.com/products/plugin/autodl/jinstall-1_4_1_01-windows-i586.cab#Version=1,4,1,1" <br><br>WIDTH = "400" HEIGHT = "300" NAME = "TestApplet" ALIGN = "middle" VSPACE = "0" HSPACE = "0" ＞ <br><br>＜PARAM NAME = CODE VALUE = "com.applet.ShowFileApplet.class" ＞ <br><br>＜PARAM NAME = ARCHIVE VALUE = "./applet/myapplet.jar" ＞ <br><br>＜PARAM NAME = NAME VALUE = "TestApplet" ＞ <br><br>＜PARAM NAME = "type" VALUE = "application/x-java-applet;jpi-version=1.4.1_01"＞ <br><br>＜PARAM NAME = "scriptable" VALUE = "false"＞ <br><br>＜COMMENT＞ <br><br>＜EMBED <br><br>type = "application/x-java-applet;jpi-version=1.4.1_01" <br><br>CODE = "com.applet.ShowFileApplet.class" <br><br>ARCHIVE = "./applet/myapplet.jar" <br><br>NAME = "TestApplet" <br><br>WIDTH = "400" <br><br>HEIGHT = "300" <br><br>ALIGN = "middle" <br><br>VSPACE = "0" <br><br>HSPACE = "0" <br><br>scriptable = false <br><br>pluginspage = "http://java.sun.com/products/plugin/index.html#download"＞ <br><br>＜NOEMBED＞ <br><br>＜/NOEMBED＞ <br><br>＜/EMBED＞ <br><br>＜/COMMENT＞ <br><br>＜/OBJECT＞ <br><br>＜/body＞ <br><br>＜/html＞ </div>
<p>双击打开运行这个文件或把这个文件及 applet目录发布到WEB Server中去，可以访问运行这个applet。运行时，弹出如下图所示对话框： <br><a href="http://bbs.csai.cn/blog/uploadfile/2005818212030330.JPG"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/uploadfile/2005818212030330.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a></p>
<p>如果此时你点“是”，则在这次会话过程中，此
applet具有访问本地文件系统的权限，但下次运行时还要提示此信息。如果你点“总是有效”则以后每次访问此类含有由
Mission_Water_Signed数字证书签发的applet页面，都不会再弹出此选择框。因为：你选择了总是有效，这样，Java会在Java
Plug-in中记录这个信任的数字证书，除非你把Java
Plug-in中记录的这个信任证书删除。在win2k中，可以在“控制面版”-＞Java Plug-in中看到。如下图所示： <br><a href="http://bbs.csai.cn/blog/uploadfile/200581821215513.JPG"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/uploadfile/200581821215513.JPG" border="0"><img onmousewheel="return bbimg(this)" title="点击新窗口查看大图" onload="java_script_:if(this.width>600)this.width=600" border="0"></a></p>
<p>点选择“总是有效”后，该程序运行的结果如下图所示： </p>
<p><a href="http://bbs.csai.cn/blog/uploadfile/2005818212148714.JPG"><img style="border-color: rgb(0, 0, 0);" alt="" src="http://bbs.csai.cn/blog/uploadfile/2005818212148714.JPG" border="0"></a></p></span></font>]]></description>
</item><item>
<title><![CDATA[mysql:General error message from server: "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='"]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=guan1200&amp;id=8060</link>
<author>guan1200</author>
<pubDate>2005/8/27 18:13:45</pubDate>
<description><![CDATA[<a>　<font size="4"><span id="ArticleContent1_ArticleContent1_lblContent">最近将mysql的版本升级成4.1.7。但是在利用hibernate2对数据库进行查询时报以下错误（插入更新操作正常）：<br>09:42:05,248
ERROR JDBCExceptionReporter:46 - General error message from server:
"Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and
(utf8_general_ci,COERCIBLE) for operation '='"<br>09:42:05,248&nbsp; WARN JDBCExceptionReporter:38 - SQL Error: 1267, SQLState: S1000<br>09:42:05,248
ERROR JDBCExceptionReporter:46 - General error message from server:
"Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and
(utf8_general_ci,COERCIBLE) for operation '='"<br>09:42:05,264 ERROR JDBCExceptionReporter:38 - Could not execute query<br>java.sql.SQLException: General error message from server: "<font color="#ff3333">Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='"<br></font>&nbsp;at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)<br>&nbsp;at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)<br>&nbsp;at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)<br>&nbsp;at com.mysql.jdbc.Connection.execSQL(Connection.java:2247)<br>&nbsp;at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1586)<br>&nbsp;at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:92)<br>&nbsp;at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)<br>&nbsp;at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:795)<br>&nbsp;at net.sf.hibernate.loader.Loader.doQuery(Loader.java:189)<br>&nbsp;at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)<br>&nbsp;at net.sf.hibernate.loader.Loader.doList(Loader.java:950)<br>&nbsp;at net.sf.hibernate.loader.Loader.list(Loader.java:941)<br>&nbsp;at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)<br>&nbsp;at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)<br>&nbsp;at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)<br>&nbsp;at org.apache.jsp.test2_jsp._jspService(test2_jsp.java:88)<br>&nbsp;at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)<br>&nbsp;at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)<br>&nbsp;at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)<br>&nbsp;at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)<br>&nbsp;at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)<br>&nbsp;at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)<br>&nbsp;at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)<br>&nbsp;at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)<br>&nbsp;at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)<br>&nbsp;at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)<br>&nbsp;at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)<br>&nbsp;at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)<br>&nbsp;at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)<br>&nbsp;at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)<br>&nbsp;at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)<br>&nbsp;at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)<br>&nbsp;at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)<br>&nbsp;at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)<br>&nbsp;at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)<br>&nbsp;at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)<br>&nbsp;at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)<br>&nbsp;at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)<br>&nbsp;at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)<br>&nbsp;at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)<br>&nbsp;at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)<br>&nbsp;at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)<br>&nbsp;at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)<br>&nbsp;at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)<br>&nbsp;at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)<br>&nbsp;at java.lang.Thread.run(Thread.java:534)<br><br><br>仔细分析上面红色字，感觉到应该是字符集出错了。所以在创建表的时候指定字符集（我在xml文件中指定的是utf8，所以表也应该指定为utf8）,创建表的格式如下<br>CREATE TABLE `table_name` <br>(<br>&nbsp;******) <br>ENGINE=InnoDB DEFAULT CHARSET=utf8</span></font></a>]]></description>
</item><item>
<title><![CDATA[Transformiix不支持disable-output-escaping的解决方法]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=guan1200&amp;id=7226</link>
<author>guan1200</author>
<pubDate>2005/7/14 16:57:28</pubDate>
<description><![CDATA[<font size="3">Transformiix不支持disable-output-escaping的解决方法
最近写了一个多浏览器兼容的XSLT程序，主要问题集中在disable-output-escaping的支持上，发表一下看法，大家一起讨论。<br>

&nbsp;&nbsp;&nbsp;&nbsp; 内嵌在浏览器中的XSLT Processor主要是两种：MSIE的MSXML；包括Netscape、Mozilla、Firefox等浏览器用的都是Mozilla的Transformiix。<br>

&nbsp;&nbsp;&nbsp;&nbsp; 在http://www.w3.org/TR/xslt对XSLT的标准中，
http://www.w3.org/TR/xslt#output提到：“An XSLT processor may output the result tree as a sequence of
bytes, although it is not required to be able to do so[17
Conformance]“
http://www.w3.org/TR/xslt#disable-output-escaping：“An XSLT processor is not required to support disabling
output escaping.“
很不幸，Transformiix不支持disable-output-escaping

<br>

&nbsp;&nbsp;&nbsp;
由于XML文件中，需要在浏览器上正常显示CDATA中的HTML代码，这在MSIE中，调用disable-output-escaping当然没有问
题，但是既然要多浏览器兼容，就不得不考虑在Transformiix中的情况，这完全可以通过javascript解决，国外网站上已经有了一些解决方
案，下面给出实例代码：<br>

&nbsp;&lt;?xml version="1.0"?&gt;
<br>

&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="html" encoding="GB2312" indent="yes"/&gt;

  <br>

&lt;xsl:template match="/"&gt;<br>

&nbsp;&lt;xsl:apply-templates/&gt;
  <br>

&lt;/xsl:template&gt;

  <br>
<br>

&lt;xsl:template match="mynode"&gt;<br>

&nbsp;&lt;html&gt;<br>

&nbsp;&lt;head&gt;<br>

&nbsp;&lt;title&gt;
        <br>

&lt;/title&gt;
      <br>

&lt;/head&gt;<br>

&nbsp;&lt;body&gt;<br>

&nbsp;&lt;center id="content"&gt;<br>

&nbsp;&lt;xsl:apply-templates select="text"/&gt;<br>

&nbsp;&lt;/center&gt;
      <br>

&lt;/body&gt;<br>

&nbsp;&lt;/html&gt;<br>

&nbsp;&lt;/xsl:template&gt;<br>

&nbsp;&lt;xsl:template match="text"&gt;
    <br>

&nbsp;&nbsp;&nbsp; &lt;xsl:value-of disable-output-escaping="yes" select="."/&gt;
    <br>

&nbsp;&nbsp;&nbsp; &lt;xsl:if test="system-property('xsl:vendor')='Transformiix'"&gt;
      <br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;script language="javascript"&gt;
        <br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; var el = document.getElementById("content");
        el.innerHTML = el.firstChild.data;
      <br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;/script&gt;<br>

&nbsp;&nbsp;&nbsp;&nbsp; &lt;/xsl:if&gt;<br>

&nbsp;&lt;/xsl:template&gt;
<br>

&lt;/xsl:stylesheet&gt;</font>
]]></description>
</item><item>
<title><![CDATA[XMLDOM属性列表]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=guan1200&amp;id=6755</link>
<author>guan1200</author>
<pubDate>2005/6/23 10:44:41</pubDate>
<description><![CDATA[<font size="4"></font><p><font size="4"><strong>The Microsoft XML Parser</strong></font></p>
<p><font size="4">To create an XML Document object with JavaScript, use the following code:</font></p>
<table class="ex" id="table2" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<td><pre><font size="4">var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")</font></pre><pre><font size="4">xmlDoc.appendChild(xmlDoc.createElement("root"))</font></pre></td></tr></tbody></table>
<h2><font size="4">XML Parser in Mozilla Browsers</font></h2>
<p><font size="4">Plain XML documents are displayed in a tree-like structure in Mozilla (just like IE).</font></p>
<p><font size="4">Mozilla also supports parsing of XML data that resides in a file, using JavaScript. The parsed data can be displayed as HTML.</font></p>
<p><font size="4">To create an XML Document object with JavaScript in Mozilla, use the following code:</font></p>
<table class="ex" id="table5" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<td><pre><font size="4">var xmlDoc=document.implementation.createDocument("<i>ns</i>","<i>root</i>",null)</font></pre></td></tr></tbody></table>
<p><font size="4">The first parameter, <i>ns</i>, defines the namespace used for the XML document. The second parameter, <i>root</i>, is the XML root element in the XML file. The third parameter, null, is always null because it is not implemented yet.</font></p>
<h2><font size="4">Loading an XML File Into the Parser</font></h2>
<p><font size="4">The following code loads an existing XML document ("note.xml") into the XML parser:</font></p>
<p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<td><pre><font size="4">&lt;script type="text/javascript"&gt;<br><br>var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")<br>xmlDoc.async="false"<br>xmlDoc.load("note.xml")<br>...<br>...<br>...</font></pre><pre><font size="4">&lt;/script&gt;//ie和firefox都支持load,firefox不支持loadXML(string text)</font></pre></td></tr></tbody></table></p>
<p><font size="4">The first line of the script creates an instance of
the Microsoft XML parser. The third line tells the parser to load an
XML document called "note.xml". The second line turns off asynchronized
loading, to make sure that the parser will not continue execution of
the script before the document is fully loaded.</font></p>
<h2><font size="4">Accessing XML Elements by Name</font></h2>
<p><font size="4">Addressing elements by number is NOT the preferred way to extract elements from XML documents. Using names is a better way:</font></p>
<p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<td><pre><font size="4">&lt;script type="text/javascript"&gt;<br>function loadXML()<br>{<br>var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")<br>xmlDoc.async="false"<br>xmlDoc.load("note.xml")//注意firefox的load("note.xml")并不会读该文件,须要给fox增加loadXML()涵数<br><br>xmlDoc.getElementsByTagName("to").item(0).text<br>xmlDoc.getElementsByTagName("from").item(0).text<br>xmlDoc.getElementsByTagName("heading").item(0).text<br>xmlDoc.getElementsByTagName("body").item(0).text<br>}<br>&lt;/script&gt;</font></pre></td></tr></tbody></table></p>
<p><font size="4"><b>Important:</b> To extract the text (Jani) from an
element like this: &lt;from&gt;Jani&lt;/from&gt;, the syntax is:
getElementsByTagName("from").item(0).text, and NOT like this:
getElementsByTagName("from").text. The reason for this is that the
result returned from getElementsByTagName is an array of nodes,
containing all nodes found within the XML document with the specified
tag name (in this case "from").</font></p>
<p class="intro"><font size="4">The XMLHttpRequest object is supported in Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0 / Firefox, and Netscape 7.</font></p>
<hr style="height: 4px;">

<h2><font size="4">What is an HTTP Request?</font></h2>
<p><font size="4">With an HTTP request, a web page can make a request
to, and get a response from a web server - without reloading the page.
The user will stay on the same page, and he or she will not notice that
scripts might request pages, or send data to a server in the background.</font></p>
<p><font size="4"><b>By using the XMLHttpRequest object, a web developer can change a page with data from the server after the page has loaded.</b></font></p>
<p><font size="4"><a href="http://www.google.com/webhp?complete=1" target="_blank">Google Suggest</a>
is using the XMLHttpRequest object to create a very dynamic web
interface: When you start typing in Google's search box, a JavaScript
sends the letters off to a server and the server returns a list of
suggestions.</font></p>
<h2><font size="4">Creating an XMLHttpRequest Object</font></h2>
<p><font size="4">For Mozilla, Firefox, Safari, and Netscape:</font></p>
<p>
<table class="ex" id="table8" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<td><pre><font size="4">var xmlhttp=new XMLHttpRequest()</font></pre></td></tr></tbody></table></p>
<p><font size="4">For Internet Explorer:</font></p>
<p>
<table class="ex" id="table9" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<td><pre><font size="4">var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")</font></pre></td></tr></tbody></table></p>
<h3><font size="4">Example</font></h3>
<p>
<table class="ex" id="table10" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<td><pre><font size="4">&lt;script type="text/javascript"&gt;<br>var xmlhttp</font></pre><pre><font size="4">function loadXMLDoc(url)<br>{<br>// code for Mozilla, etc.<br>if (window.XMLHttpRequest)<br>  {<br>  xmlhttp=new XMLHttpRequest()<br>  xmlhttp.onreadystatechange=xmlhttpChange<br>  xmlhttp.open("GET",url,true)<br>  xmlhttp.send(null)<br>  }<br>// code for IE<br>else if (window.ActiveXObject)<br>  {<br>  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")<br>    if (xmlhttp)<br>    {<br>    xmlhttp.onreadystatechange=xmlhttpChange<br>    xmlhttp.open("GET",url,true)<br>    xmlhttp.send()<br>    }<br>  }<br>}</font></pre><pre><font size="4">function xmlhttpChange()<br>{<br>// if xmlhttp shows "loaded"<br>if (xmlhttp.readyState==4)<br>  {<br>  // if "OK"<br>  if (xmlhttp.status==200)<br>    {<br>    // ...some code here...<br>    }<br>  else<br>    {<br>    alert("Problem retrieving XML data")<br>    }<br>  }<br>}<br>&lt;/script&gt;</font></pre></td></tr></tbody></table></p>
<h2><font size="4">Why are we Using async in our Examples?</font></h2>
<p><font size="4">Most of the examples here use the async mode (the third parameter of open() set to true).</font></p>
<p><font size="4">The async parameter specifies whether the request
should be handled asynchronously or not. True means that script
continues to run after the send() method, without waiting for a
response from the server. false means that the script waits for a
response before continuing script processing. By setting this parameter
to false, you run the risk of having your script hang if there is a
network or server problem, or if the request is long (the UI locks
while the request is being made) a user may even see the "Not
Responding" message. It is safer to send asynchronously and design your
code around the onreadystatechange event</font></p>
<h2><font size="4">The XMLHttpRequest Object Reference</font></h2>
<h3><font size="4">Methods</font></h3>
<p>
<table class="ex" id="table11" border="1" cellpadding="3" cellspacing="0" width="100%">
<tbody>
<tr valign="top">
<th align="left" width="45%"><font size="4">Method</font></th>
<th align="left" width="55%"><font size="4">Description</font></th></tr>
<tr valign="top">
<td><font size="4">abort()</font></td>
<td><font size="4">Cancels the current request</font></td></tr>
<tr valign="top">
<td><font size="4">getAllResponseHeaders()</font></td>
<td><font size="4">Returns the complete set of http headers as a string</font></td></tr>
<tr valign="top">
<td><font size="4">getResponseHeader("headername")</font></td>
<td><font size="4">Returns the value of the specified http header</font></td></tr>
<tr valign="top">
<td><font size="4">open("method","URL",async,"uname","pswd")</font></td>
<td><font size="4">Specifies the method, URL, and other optional attributes of a request 
      </font><p><font size="4">The method parameter can have a value of
"GET", "POST", or "PUT" (use "GET" when requesting data and use "POST"
when sending data (especially if the length of the data is greater than
512 bytes.</font></p>
<p><font size="4">The URL parameter may be either a relative or complete URL.</font></p>
<p><font size="4">The async parameter specifies whether the request
should be handled asynchronously or not. true means that script
processing carries on after the send() method, without waiting for a
response. false means that the script waits for a response before
continuing script processing</font></p></td></tr>
<tr valign="top">
<td><font size="4">send(content)</font></td>
<td><font size="4">Sends the request</font></td></tr>
<tr valign="top">
<td><font size="4">setRequestHeader("label","value")</font></td>
<td><font size="4">Adds a label/value pair to the http header to be sent</font></td></tr></tbody></table></p>
<h3><font size="4">Properties</font></h3>
<p>
<table class="ex" id="table12" border="1" cellpadding="3" cellspacing="0" width="100%">
<tbody>
<tr valign="top">
<th align="left" width="30%"><font size="4">Property</font></th>
<th align="left" width="70%"><font size="4">Description</font></th></tr>
<tr valign="top">
<td><font size="4">onreadystatechange</font></td>
<td><font size="4">An event handler for an event that fires at every state change</font></td></tr>
<tr valign="top">
<td><font size="4">readyState</font></td>
<td><font size="4">Returns the state of the object: 
      </font><p><font size="4">0 = uninitialized<br>
1 = loading<br>
2 = loaded<br>
3 = interactive<br>
4 = complete </font></p></td></tr>
<tr valign="top">
<td><font size="4">responseText</font></td>
<td><font size="4">Returns the response as a string</font></td></tr>
<tr valign="top">
<td><font size="4">responseXML</font></td>
<td><font size="4">Returns the response as XML. This property returns
an XML document object, which can be examined and parsed using W3C DOM
node tree methods and properties</font></td></tr>
<tr valign="top">
<td><font size="4">status</font></td>
<td><font size="4">Returns the status as a number (e.g. 404 for "Not Found" or 200 for "OK")</font></td></tr>
<tr valign="top">
<td><font size="4">statusText</font></td>
<td><font size="4">Returns the status as a string (e.g. "Not Found" or "OK")</font></td></tr></tbody></table></p>
<h1><font size="4">XML DOM Node Types</font></h1>
<h2><font size="4">The DOM Structure</font></h2>
<p><font size="4">The DOM presents a document as a hierarchy of node objects.</font></p>
<p><font size="4">The following table lists the different W3C node types, and which node types they may have as children:</font></p>
<p>
<table class="ex" id="table1" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="30%"><font size="4">Node type</font></th>
<th align="left" valign="top" width="40%"><font size="4">Description</font></th>
<th align="left" valign="top" width="30%"><font size="4">Children</font></th></tr>
<tr>
<td valign="top"><font size="4">Document</font></td>
<td valign="top"><font size="4">Represents the entire document (it is the root-node of the DOM tree)</font></td>
<td valign="top"><font size="4">Element (max. one), ProcessingInstruction, Comment, DocumentType</font></td></tr>
<tr>
<td valign="top"><font size="4">DocumentFragment</font></td>
<td valign="top"><font size="4">Represents a "lightweight" Document object, which can hold a portion of a document</font></td>
<td valign="top"><font size="4">Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference</font></td></tr>
<tr>
<td valign="top"><font size="4">DocumentType</font></td>
<td valign="top"><font size="4">Represents a list of the entities that are defined for the document</font></td>
<td valign="top"><font size="4">None</font></td></tr>
<tr>
<td valign="top"><font size="4">EntityReference</font></td>
<td valign="top"><font size="4">Represents an entity reference</font></td>
<td valign="top"><font size="4">Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference</font></td></tr>
<tr>
<td valign="top"><font size="4">Element</font></td>
<td valign="top"><font size="4">Represents an element</font></td>
<td valign="top"><font size="4">Element, Text, Comment, ProcessingInstruction, CDATASection, EntityReference</font></td></tr>
<tr>
<td valign="top"><font size="4">Attr</font></td>
<td valign="top"><font size="4">Represents an attribute</font></td>
<td valign="top"><font size="4">Text, EntityReference</font></td></tr>
<tr>
<td valign="top"><font size="4">ProcessingInstruction</font></td>
<td valign="top"><font size="4">Represents a "processing instruction"</font></td>
<td valign="top"><font size="4">None</font></td></tr>
<tr>
<td valign="top"><font size="4">Comment</font></td>
<td valign="top"><font size="4">Represents a comment</font></td>
<td valign="top"><font size="4">None</font></td></tr>
<tr>
<td valign="top"><font size="4">Text</font></td>
<td valign="top"><font size="4">Represents textual content (character data) in an element or attribute</font></td>
<td valign="top"><font size="4">None</font></td></tr>
<tr>
<td valign="top"><font size="4">CDATASection</font></td>
<td valign="top"><font size="4">Represents a block of text that may contains characters that would otherwise be treated as markup</font></td>
<td valign="top"><font size="4">None</font></td></tr>
<tr>
<td valign="top"><font size="4">Entity</font></td>
<td valign="top"><font size="4">Represents an entity</font></td>
<td valign="top"><font size="4">Element, ProcessingInstruction, Comment, Text, CDATASection, EntityReference</font></td></tr>
<tr>
<td valign="top"><font size="4">Notation</font></td>
<td valign="top"><font size="4">Represents a notation declared in the DTD</font></td>
<td valign="top"><font size="4">None</font></td></tr></tbody></table><font size="4"><br>
</font></p>
<hr style="height: 4px;">

<h2><font size="4">Node Types - Return Values</font></h2>
<p><font size="4">Below is a list of what the nodeName and the nodeValue properties will return for each nodetype:</font></p>
<p>
<table class="ex" id="table2" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="30%"><font size="4">Node type</font></th>
<th align="left" valign="top" width="40%"><font size="4">nodeName returns</font></th>
<th align="left" valign="top" width="30%"><font size="4">nodeValue returns</font></th></tr>
<tr>
<td valign="top"><font size="4">Document</font></td>
<td valign="top"><font size="4">#document</font></td>
<td valign="top"><font size="4">null</font></td></tr>
<tr>
<td valign="top"><font size="4">DocumentFragment</font></td>
<td valign="top"><font size="4">#document fragment</font></td>
<td valign="top"><font size="4">null</font></td></tr>
<tr>
<td valign="top"><font size="4">DocumentType</font></td>
<td valign="top"><font size="4">doctype name</font></td>
<td valign="top"><font size="4">null</font></td></tr>
<tr>
<td valign="top"><font size="4">EntityReference</font></td>
<td valign="top"><font size="4">entity reference name</font></td>
<td valign="top"><font size="4">null</font></td></tr>
<tr>
<td valign="top"><font size="4">Element</font></td>
<td valign="top"><font size="4">element name</font></td>
<td valign="top"><font size="4">null</font></td></tr>
<tr>
<td valign="top"><font size="4">Attr</font></td>
<td valign="top"><font size="4">attribute name</font></td>
<td valign="top"><font size="4">attribute value</font></td></tr>
<tr>
<td valign="top"><font size="4">ProcessingInstruction</font></td>
<td valign="top"><font size="4">target</font></td>
<td valign="top"><font size="4">content of node</font></td></tr>
<tr>
<td valign="top"><font size="4">Comment</font></td>
<td valign="top"><font size="4">#comment</font></td>
<td valign="top"><font size="4">comment text</font></td></tr>
<tr>
<td valign="top"><font size="4">Text</font></td>
<td valign="top"><font size="4">#text</font></td>
<td valign="top"><font size="4">content of node</font></td></tr>
<tr>
<td valign="top"><font size="4">CDATASection</font></td>
<td valign="top"><font size="4">#cdata-section</font></td>
<td valign="top"><font size="4">content of node</font></td></tr>
<tr>
<td valign="top"><font size="4">Entity</font></td>
<td valign="top"><font size="4">entity name</font></td>
<td valign="top"><font size="4">null</font></td></tr>
<tr>
<td valign="top"><font size="4">Notation</font></td>
<td valign="top"><font size="4">notation name</font></td>
<td valign="top"><font size="4">null</font></td></tr></tbody></table><font size="4"><br>
</font></p>
<hr style="height: 4px;">

<h2><font size="4">NodeTypes - Named Constants</font></h2>
<p>
<table class="ex" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="15%"><font size="4">NodeType</font></th>
<th align="left" valign="top" width="85%"><font size="4">Named Constant</font></th></tr>
<tr>
<td valign="top"><font size="4">1</font></td>
<td valign="top"><font size="4">ELEMENT_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">2</font></td>
<td valign="top"><font size="4">ATTRIBUTE_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">3</font></td>
<td valign="top"><font size="4">TEXT_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">4</font></td>
<td valign="top"><font size="4">CDATA_SECTION_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">5</font></td>
<td valign="top"><font size="4">ENTITY_REFERENCE_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">6</font></td>
<td valign="top"><font size="4">ENTITY_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">7</font></td>
<td valign="top"><font size="4">PROCESSING_INSTRUCTION_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">8</font></td>
<td valign="top"><font size="4">COMMENT_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">9</font></td>
<td valign="top"><font size="4">DOCUMENT_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">10</font></td>
<td valign="top"><font size="4">DOCUMENT_TYPE_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">11</font></td>
<td valign="top"><font size="4">DOCUMENT_FRAGMENT_NODE</font></td></tr>
<tr>
<td valign="top"><font size="4">12</font></td>
<td valign="top"><font size="4">NOTATION_NODE</font></td></tr></tbody></table></p>
<p><font size="4">XML DOM - The Attr Object</font></p>
<h2><font size="4">The Attr object</font></h2>
<p><font size="4">The attr object represents an attribute of an element object.</font></p>
<p><font size="4">The attr object's properties and methods are described below:</font></p>
<h3><font size="4">Properties</font></h3>
<p>
<table class="ex" id="table8" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="25%"><font size="4">Property</font></th>
<th align="left" valign="top" width="75%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">attributes</font></td>
<td valign="top"><font size="4">Returns a NamedNodeMap that contains all attributes of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">childNodes</font></td>
<td valign="top"><font size="4">Returns a node list that contains all children of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">firstChild</font></td>
<td valign="top"><font size="4">Returns the first child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">lastChild</font></td>
<td valign="top"><font size="4">Returns the last child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">name</font></td>
<td valign="top"><font size="4">Returns the name of the attribute</font></td></tr>
<tr>
<td valign="top"><font size="4">nextSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately following a node. Two nodes are siblings if they have the same parent node</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeName</font></td>
<td valign="top"><font size="4">Returns the name of the node (depending on the node type)</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeType</font></td>
<td valign="top"><font size="4">Returns the node type as a number</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeValue</font></td>
<td valign="top"><font size="4">Returns the value of the node</font></td></tr>
<tr>
<td valign="top"><font size="4">ownerDocument</font></td>
<td valign="top"><font size="4">Returns the Document object of a node (returns the root node of the document)</font></td></tr>
<tr>
<td valign="top"><font size="4">parentNode</font></td>
<td valign="top"><font size="4">Returns the parent node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">previousSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately preceding a node. Two nodes are siblings if they have the same parent node</font></td></tr>
<tr>
<td valign="top"><font size="4">value</font></td>
<td valign="top"><font size="4">Returns the value of the attribute</font></td></tr></tbody></table></p>
<h3><font size="4">Methods</font></h3>
<table class="ex" id="table10" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="40%"><font size="4">Method</font></th>
<th align="left" valign="top" width="60%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">appendChild(tagname)</font></td>
<td valign="top"><font size="4">Appends a new child node to a node</font></td></tr>
<tr>
<td valign="top"><font size="4">cloneNode(boolean)</font></td>
<td valign="top"><font size="4">Creates an exact clone node of a node.
If the boolean parameter is set to true, the cloned node clones all the
child nodes of the original node as well</font></td></tr>
<tr>
<td valign="top"><font size="4">hasChildNodes()</font></td>
<td valign="top"><font size="4">Returns true if a node has child nodes. Otherwise it returns false</font></td></tr>
<tr>
<td valign="top"><font size="4">insertBefore(newnode,refnode)</font></td>
<td valign="top"><font size="4">Inserts a new node (newnode) before the existing node (refnode)</font></td></tr>
<tr>
<td valign="top"><font size="4">removeChild(nodename)</font></td>
<td valign="top"><font size="4">Removes the specified node and returns it</font></td></tr>
<tr>
<td valign="top"><font size="4">replaceChild(newnode,oldnode)</font></td>
<td valign="top"><font size="4">Replaces the oldnode with the newnode, and returns the oldnode</font></td></tr></tbody></table>
<h2><font size="4">The CDATASection&nbsp; comment object</font></h2>
<p><font size="4">The CDATASection object represents CDATASection nodes
in a document. A CDATASection node is used to escape parts of text
which normally would be recognized as markup.</font></p>
<p><font size="4">The CDATASection object's properties and methods are described below:</font></p>
<h3><font size="4">Properties</font></h3>
<table class="ex" id="table8" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="25%"><font size="4">Property</font></th>
<th align="left" valign="top" width="75%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">attributes</font></td>
<td valign="top"><font size="4">Returns a NamedNodeMap that contains all attributes of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">childNodes</font></td>
<td valign="top"><font size="4">Returns a node list that contains all children of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">data</font></td>
<td valign="top"><font size="4">Returns the data of the node</font></td></tr>
<tr>
<td valign="top"><font size="4">firstChild</font></td>
<td valign="top"><font size="4">Returns the first child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">lastChild</font></td>
<td valign="top"><font size="4">Returns the last child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">length</font></td>
<td valign="top"><font size="4">Returns the length of the data (in characters)</font></td></tr>
<tr>
<td valign="top"><font size="4">nextSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately following a node. Two nodes are siblings if they have the same parent node</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeName</font></td>
<td valign="top"><font size="4">Returns the name of the node (depending on the node type)</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeType</font></td>
<td valign="top"><font size="4">Returns the node type as a number</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeValue</font></td>
<td valign="top"><font size="4">Returns the value of the node</font></td></tr>
<tr>
<td valign="top"><font size="4">ownerDocument</font></td>
<td valign="top"><font size="4">Returns the Document object of a node (returns the root node of the document)</font></td></tr>
<tr>
<td valign="top"><font size="4">parentNode</font></td>
<td valign="top"><font size="4">Returns the parent node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">previousSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately preceding a node. Two nodes are siblings if they have the same parent node</font></td></tr></tbody></table>
<h3><font size="4">Methods</font></h3>
<table class="ex" id="table10" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="40%"><font size="4">Method</font></th>
<th align="left" valign="top" width="60%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">appendChild(tagname)</font></td>
<td valign="top"><font size="4">Appends a new child node to a node</font></td></tr>
<tr>
<td valign="top"><font size="4">appendData(strdata)</font></td>
<td valign="top"><font size="4">Appends the specified string to the existing data</font></td></tr>
<tr>
<td valign="top"><font size="4">cloneNode(boolean)</font></td>
<td valign="top"><font size="4">Creates an exact clone node of a node.
If the boolean parameter is set to true, the cloned node clones all the
child nodes of the original node as well</font></td></tr>
<tr>
<td valign="top"><font size="4">deleteData(offset,count)</font></td>
<td valign="top"><font size="4">Removes the specified range of characters from the data</font></td></tr>
<tr>
<td valign="top"><font size="4">hasChildNodes()</font></td>
<td valign="top"><font size="4">Returns true if a node has child nodes. Otherwise it returns false</font></td></tr>
<tr>
<td valign="top"><font size="4">insertBefore(newnode,refnode)</font></td>
<td valign="top"><font size="4">Inserts a new node (newnode) before the existing node (refnode)</font></td></tr>
<tr>
<td valign="top"><font size="4">insertData(offset,string)</font></td>
<td valign="top"><font size="4">Inserts the stringdata at the specified offset</font></td></tr>
<tr>
<td valign="top"><font size="4">removeChild(nodename)</font></td>
<td valign="top"><font size="4">Removes the specified node and returns it</font></td></tr>
<tr>
<td valign="top"><font size="4">replaceChild(newnode,oldnode)</font></td>
<td valign="top"><font size="4">Replaces the oldnode with the newnode, and returns the oldnode</font></td></tr>
<tr>
<td valign="top"><font size="4">replaceData(offset,count,stringdata)</font></td>
<td valign="top"><font size="4">Replaces the characters from the specified offset with the stringdata</font></td></tr></tbody></table>
<h2><font size="4">The Document object</font></h2>
<p><font size="4">The document object is the root element in the node-tree. All nodes in the node tree are child nodes of the document object.</font></p>
<p><font size="4">The document object's properties, methods, and events are described below:</font></p>
<h3><font size="4">Properties</font></h3>
<table class="ex" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="30%"><font size="4">Property</font></th>
<th align="left" valign="top" width="70%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">attributes</font></td>
<td valign="top"><font size="4">Returns a NamedNodeMap that contains all attributes of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">childNodes</font></td>
<td valign="top"><font size="4">Returns a node list that contains all children of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">doctype</font></td>
<td valign="top"><font size="4">Returns the DTD or Schema for the document</font></td></tr>
<tr>
<td valign="top"><font size="4">documentElement</font></td>
<td valign="top"><font size="4">Returns the root element of the document</font></td></tr>
<tr>
<td valign="top"><font size="4">firstChild</font></td>
<td valign="top"><font size="4">Returns the first child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">implementation</font></td>
<td valign="top"><font size="4">Returns the DOMImplementation object for this particular document</font></td></tr>
<tr>
<td valign="top"><font size="4">lastChild</font></td>
<td valign="top"><font size="4">Returns the last child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">nextSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately following a node. Two nodes are siblings if they have the same parent node</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeName</font></td>
<td valign="top"><font size="4">Returns the name of the node</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeType</font></td>
<td valign="top"><font size="4">Returns the node type as a number</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeValue</font></td>
<td valign="top"><font size="4">Returns the value of the node</font></td></tr>
<tr>
<td valign="top"><font size="4">ownerDocument</font></td>
<td valign="top"><font size="4">Returns the Document object of a node (returns the root node of the document)</font></td></tr>
<tr>
<td valign="top"><font size="4">parentNode</font></td>
<td valign="top"><font size="4">Returns the parent node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">previousSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately preceding a node. Two nodes are siblings if they have the same parent node</font></td></tr></tbody></table>
<h3><font size="4">Methods</font></h3>
<table class="ex" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="40%"><font size="4">Method</font></th>
<th align="left" valign="top" width="60%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">appendChild(tagname)</font></td>
<td valign="top"><font size="4">Appends a new child node to a node</font></td></tr>
<tr>
<td valign="top"><font size="4">cloneNode(boolean)</font></td>
<td valign="top"><font size="4">Creates an exact clone node of a node.
If the boolean parameter is set to true, the cloned node clones all the
child nodes of the original node as well</font></td></tr>
<tr>
<td valign="top"><font size="4">createAttribute(attrname)</font></td>
<td valign="top"><font size="4">Creates an Attr node with the specified name</font></td></tr>
<tr>
<td valign="top"><font size="4">createCDATASection(text)</font></td>
<td valign="top"><font size="4">Creates a CDATASection node, containing the specified text</font></td></tr>
<tr>
<td valign="top"><font size="4">createComment(text)</font></td>
<td valign="top"><font size="4">Creates a comment node, containing the specified text</font></td></tr>
<tr>
<td valign="top"><font size="4">createDocumentFragment()</font></td>
<td valign="top"><font size="4">Creates an empty documentFragment object</font></td></tr>
<tr>
<td valign="top"><font size="4">createElement(tagname)</font></td>
<td valign="top"><font size="4">Creates an element node with the specified name</font></td></tr>
<tr>
<td valign="top"><font size="4">createEntityReference(refname)</font></td>
<td valign="top"><font size="4">Creates an entityReference node with the specified name</font></td></tr>
<tr>
<td valign="top"><font size="4">createProcessingInstruction(target,text)</font></td>
<td valign="top"><font size="4">Creates a processingInstruction node, containing the specified target and text</font></td></tr>
<tr>
<td valign="top"><font size="4">createTextNode(text)</font></td>
<td valign="top"><font size="4">Creates a text node, containing the specified text</font></td></tr>
<tr>
<td valign="top"><font size="4">getElementsByTagName(tagname)</font></td>
<td valign="top"><font size="4">Returns the specified node, and all its child nodes, as a node list</font></td></tr>
<tr>
<td valign="top"><font size="4">hasChildNodes()</font></td>
<td valign="top"><font size="4">Returns true if a node has child nodes. Otherwise it returns false</font></td></tr>
<tr>
<td valign="top"><font size="4">insertBefore(newnode,refnode)</font></td>
<td valign="top"><font size="4">Inserts a new node (newnode) before the existing node (refnode)</font></td></tr>
<tr>
<td valign="top"><font size="4">removeChild(nodename)</font></td>
<td valign="top"><font size="4">Removes the specified node and returns it</font></td></tr>
<tr>
<td valign="top"><font size="4">replaceChild(newnode,oldnode)</font></td>
<td valign="top"><font size="4">Replaces the oldnode with the newnode, and returns the oldnode</font></td></tr></tbody></table>
<h2><font size="4">The Element object</font></h2>
<p><font size="4">The element object represents the element nodes in
the document. If the element node contains text, this text is
represented in a text node.</font></p>
<p><font size="4">The element object's properties and methods are described below:</font></p>
<h3><font size="4">Properties</font></h3>
<table class="ex" id="table3" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="25%"><font size="4">Property</font></th>
<th align="left" valign="top" width="75%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">attributes</font></td>
<td valign="top"><font size="4">Returns a NamedNodeMap that contains all attributes of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">childNodes</font></td>
<td valign="top"><font size="4">Returns a node list that contains all children of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">firstChild</font></td>
<td valign="top"><font size="4">Returns the first child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">lastChild</font></td>
<td valign="top"><font size="4">Returns the last child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">nextSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately following a node. Two nodes are siblings if they have the same parent node</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeName</font></td>
<td valign="top"><font size="4">Returns the name of the node (depending on the node type)</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeType</font></td>
<td valign="top"><font size="4">Returns the node type as a number</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeValue</font></td>
<td valign="top"><font size="4">Returns the value of the node</font></td></tr>
<tr>
<td valign="top"><font size="4">ownerDocument</font></td>
<td valign="top"><font size="4">Returns the Document object of a node (returns the root node of the document)</font></td></tr>
<tr>
<td valign="top"><font size="4">parentNode</font></td>
<td valign="top"><font size="4">Returns the parent node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">previousSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately preceding a node. Two nodes are siblings if they have the same parent node</font></td></tr>
<tr>
<td valign="top"><font size="4">tagName</font></td>
<td valign="top"><font size="4">Returns the name of the element node</font></td></tr></tbody></table>
<h3><font size="4">Methods</font></h3>
<table class="ex" id="table6" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="40%"><font size="4">Method</font></th>
<th align="left" valign="top" width="60%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">appendChild(tagname)</font></td>
<td valign="top"><font size="4">Appends a new child node to a node</font></td></tr>
<tr>
<td valign="top"><font size="4">cloneNode(boolean)</font></td>
<td valign="top"><font size="4">Creates an exact clone node of a node.
If the boolean parameter is set to true, the cloned node clones all the
child nodes of the original node as well</font></td></tr>
<tr>
<td valign="top"><font size="4">getAttribute(attrname)</font></td>
<td valign="top"><font size="4">Returns the value of the specified attribute</font></td></tr>
<tr>
<td valign="top"><font size="4">getAttributeNode(attrname)</font></td>
<td valign="top"><font size="4">Returns the specified attribute node as an Attr object</font></td></tr>
<tr>
<td valign="top"><font size="4">getElementsByTagName(tagname)</font></td>
<td valign="top"><font size="4">Returns the specified node, and all its child nodes, as a node list</font></td></tr>
<tr>
<td valign="top"><font size="4">hasChildNodes()</font></td>
<td valign="top"><font size="4">Returns true if a node has child nodes. Otherwise it returns false</font></td></tr>
<tr>
<td valign="top"><font size="4">insertBefore(newnode,refnode)</font></td>
<td valign="top"><font size="4">Inserts a new node (newnode) before the existing node (refnode)</font></td></tr>
<tr>
<td valign="top"><font size="4">normalize()</font></td>
<td valign="top"><font size="4">Combines all subtree Text nodes into a single one</font></td></tr>
<tr>
<td valign="top"><font size="4">removeAttribute(attrname)</font></td>
<td valign="top"><font size="4">Removes the specified attribute's value</font></td></tr>
<tr>
<td valign="top"><font size="4">removeAttributeNode(attriname)</font></td>
<td valign="top"><font size="4">Removes the specified attribute node</font></td></tr>
<tr>
<td valign="top"><font size="4">removeChild(nodename)</font></td>
<td valign="top"><font size="4">Removes the specified node and returns it</font></td></tr>
<tr>
<td valign="top"><font size="4">replaceChild(newnode,oldnode)</font></td>
<td valign="top"><font size="4">Replaces the oldnode with the newnode, and returns the oldnode</font></td></tr>
<tr>
<td valign="top"><font size="4">setAttribute(attrname,attrvalue)</font></td>
<td valign="top"><font size="4">Sets the value of the named attribute</font></td></tr>
<tr>
<td valign="top"><font size="4">setAttributeNode(attrname)</font></td>
<td valign="top"><font size="4">Inserts the specified new attribute to the element</font></td></tr></tbody></table>
<h2><font size="4">The Node Object</font></h2>
<p><font size="4">The node object represents a node in the node-tree.</font></p>
<p><font size="4">The node object's properties and methods are described below:</font></p>
<h3><font size="4">Properties</font></h3>
<table class="ex" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="25%"><font size="4">Property</font></th>
<th align="left" valign="top" width="75%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">attributes</font></td>
<td valign="top"><font size="4">Returns a NamedNodeMap that contains all attributes of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">childNodes</font></td>
<td valign="top"><font size="4">Returns a node list that contains all children of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">firstChild</font></td>
<td valign="top"><font size="4">Returns the first child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">lastChild</font></td>
<td valign="top"><font size="4">Returns the last child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">nextSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately following a node. Two nodes are siblings if they have the same parent node</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeName</font></td>
<td valign="top"><font size="4">Returns the name of the node (depending on the node type)</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeType</font></td>
<td valign="top"><font size="4">Returns the node type as a number</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeValue</font></td>
<td valign="top"><font size="4">Returns the value of the node</font></td></tr>
<tr>
<td valign="top"><font size="4">ownerDocument</font></td>
<td valign="top"><font size="4">Returns the Document object of a node (returns the root node of the document)</font></td></tr>
<tr>
<td valign="top"><font size="4">parentNode</font></td>
<td valign="top"><font size="4">Returns the parent node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">previousSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately preceding a node. Two nodes are siblings if they have the same parent node</font></td></tr></tbody></table>
<h3><font size="4">Methods</font></h3>
<table class="ex" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="40%"><font size="4">Method</font></th>
<th align="left" valign="top" width="60%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">appendChild(tagname)</font></td>
<td valign="top"><font size="4">Appends a new child node to a node</font></td></tr>
<tr>
<td valign="top"><font size="4">cloneNode(boolean)</font></td>
<td valign="top"><font size="4">Creates an exact clone node of a node.
If the boolean parameter is set to true, the cloned node clones all the
child nodes of the original node as well</font></td></tr>
<tr>
<td valign="top"><font size="4">hasChildNodes()</font></td>
<td valign="top"><font size="4">Returns true if a node has child nodes. Otherwise it returns false</font></td></tr>
<tr>
<td valign="top"><font size="4">insertBefore(newnode,refnode)</font></td>
<td valign="top"><font size="4">Inserts a new node (newnode) before the existing node (refnode)</font></td></tr>
<tr>
<td valign="top"><font size="4">removeChild(nodename)</font></td>
<td valign="top"><font size="4">Removes the specified node and returns it</font></td></tr>
<tr>
<td valign="top"><font size="4">replaceChild(newnode,oldnode)</font></td>
<td valign="top"><font size="4">Replaces the oldnode with the newnode, and returns the oldnode</font></td></tr></tbody></table>
<h2><font size="4">The NodeList object</font></h2>
<p><font size="4">The nodeList object represents a node and its child nodes as a node-tree.</font></p>
<p><font size="4">The nodeList object's properties and methods are described below:</font></p>
<h3><font size="4">Properties</font></h3>
<table class="ex" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="25%"><font size="4">Property</font></th>
<th align="left" valign="top" width="75%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">length</font></td>
<td valign="top"><font size="4">Returns the number of items in the node list</font></td></tr></tbody></table>
<h3><font size="4">Methods</font></h3>
<table class="ex" id="table3" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="25%"><font size="4">Method</font></th>
<th align="left" valign="top" width="75%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">item(index)</font></td>
<td valign="top"><font size="4">Returns the item at the specified index in the node list</font></td></tr></tbody></table>
<h2><font size="4">The Text object</font></h2>
<p><font size="4">The text object represents the text of an attribute or element object. </font></p>
<p><font size="4">The text object's properties and methods are described below:</font></p>
<h3><font size="4">Properties</font></h3>
<table class="ex" id="table4" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="25%"><font size="4">Property</font></th>
<th align="left" valign="top" width="75%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">attributes</font></td>
<td valign="top"><font size="4">Returns a NamedNodeMap that contains all attributes of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">childNodes</font></td>
<td valign="top"><font size="4">Returns a node list that contains all children of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">data</font></td>
<td valign="top"><font size="4">Returns the data of the node</font></td></tr>
<tr>
<td valign="top"><font size="4">firstChild</font></td>
<td valign="top"><font size="4">Returns the first child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">lastChild</font></td>
<td valign="top"><font size="4">Returns the last child node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">length</font></td>
<td valign="top"><font size="4">Returns the length of the data (in characters)</font></td></tr>
<tr>
<td valign="top"><font size="4">nextSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately following a node. Two nodes are siblings if they have the same parent node</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeName</font></td>
<td valign="top"><font size="4">Returns the name of the node (depending on the node type)</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeType</font></td>
<td valign="top"><font size="4">Returns the node type as a number</font></td></tr>
<tr>
<td valign="top"><font size="4">nodeValue</font></td>
<td valign="top"><font size="4">Returns the value of the node</font></td></tr>
<tr>
<td valign="top"><font size="4">ownerDocument</font></td>
<td valign="top"><font size="4">Returns the Document object of a node (returns the root node of the document)</font></td></tr>
<tr>
<td valign="top"><font size="4">parentNode</font></td>
<td valign="top"><font size="4">Returns the parent node of a node</font></td></tr>
<tr>
<td valign="top"><font size="4">previousSibling</font></td>
<td valign="top"><font size="4">Returns the node immediately preceding a node. Two nodes are siblings if they have the same parent node</font></td></tr></tbody></table>
<h3><font size="4">Methods</font></h3>
<table class="ex" id="table6" border="1" cellspacing="0" width="100%">
<tbody>
<tr>
<th align="left" valign="top" width="40%"><font size="4">Method</font></th>
<th align="left" valign="top" width="60%"><font size="4">Description</font></th></tr>
<tr>
<td valign="top"><font size="4">appendChild(tagname)</font></td>
<td valign="top"><font size="4">Appends a new child node to a node</font></td></tr>
<tr>
<td valign="top"><font size="4">appendData(strdata)</font></td>
<td valign="top"><font size="4">Appends the specified string to the existing data</font></td></tr>
<tr>
<td valign="top"><font size="4">cloneNode(boolean)</font></td>
<td valign="top"><font size="4">Creates an exact clone node of a node.
If the boolean parameter is set to true, the cloned node clones all the
child nodes of the original node as well</font></td></tr>
<tr>
<td valign="top"><font size="4">deleteData(offset,count)</font></td>
<td valign="top"><font size="4">Removes the specified range of characters from the data</font></td></tr>
<tr>
<td valign="top"><font size="4">hasChildNodes()</font></td>
<td valign="top"><font size="4">Returns true if a node has child nodes. Otherwise it returns false</font></td></tr>
<tr>
<td valign="top"><font size="4">insertBefore(newnode,refnode)</font></td>
<td valign="top"><font size="4">Inserts a new node (newnode) before the existing node (refnode)</font></td></tr>
<tr>
<td valign="top"><font size="4">insertData(offset,string)</font></td>
<td valign="top"><font size="4">Inserts the stringdata at the specified offset</font></td></tr>
<tr>
<td valign="top"><font size="4">removeChild(nodename)</font></td>
<td valign="top"><font size="4">Removes the specified node and returns it</font></td></tr>
<tr>
<td valign="top"><font size="4">replaceChild(newnode,oldnode)</font></td>
<td valign="top"><font size="4">Replaces the oldnode with the newnode, and returns the oldnode</font></td></tr>
<tr>
<td valign="top"><font size="4">replaceData(offset,count,stringdata)</font></td>
<td valign="top"><font size="4">Replaces the characters from the specified offset with the stringdata</font></td></tr></tbody></table>]]></description>
</item><item>
<title><![CDATA[jsp生成静态的hmtl文件]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=guan1200&amp;id=6265</link>
<author>guan1200</author>
<pubDate>2005/6/2 11:51:14</pubDate>
<description><![CDATA[<font size="3"><strong>jsp生成静态的hmtl文件</strong><br>
为了减轻服务器压力，将原来的文章管理系统由JSP文件的从数据库中取数据显示改为由jsp生成静态html文件后直接访问html文件。下面是一个简单的示例
</font><p><font size="3"><strong>1.buildhtml.jsp</strong></font></p>
<p><font size="3">&lt;%@ page contentType="text/html; charset=gb2312" import="java.util.*,java.io.*"%&gt;<br>
&lt;%<br>
try{<br>
&nbsp;String title="jsp生成静态html文件";<br>
&nbsp;String content="小样，还搞不定你？";<br>
&nbsp;String editer="hpsoft";<br>
&nbsp;String filePath = "";<br>
&nbsp;filePath = getServletContext().getRealPath("/")+"template.htm";<br>
&nbsp;out.print(filePath);<br>
&nbsp;String templateContent="";<br>
&nbsp;FileInputStream fileinputstream = new FileInputStream(filePath);//读取模块文件<br>
&nbsp;int lenght = fileinputstream.available();<br>
&nbsp;byte bytes[] = new byte[lenght];<br>
&nbsp;fileinputstream.read(bytes);<br>
&nbsp;fileinputstream.close();<br>
&nbsp;templateContent = new String(bytes);<br>
&nbsp;out.print(templateContent);<br>
&nbsp;templateContent=templateContent.replaceAll("###title###",title);<br>
&nbsp;templateContent=templateContent.replaceAll("###content###",content);<br>
&nbsp;templateContent=templateContent.replaceAll("###author###",editer);//替换掉模块中相应的地方<br>
&nbsp;out.print(templateContent);<br>
&nbsp;// 根据时间得文件名<br>
&nbsp;Calendar calendar = Calendar.getInstance();<br>
&nbsp;String fileame = String.valueOf(calendar.getTimeInMillis()) +".html";<br>
&nbsp;fileame = getServletContext().getRealPath("/")+fileame;//生成的html文件保存路径<br>
&nbsp;FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件输出流<br>
&nbsp;byte tag_bytes[] = templateContent.getBytes();<br>
&nbsp;fileoutputstream.write(tag_bytes);<br>
&nbsp;fileoutputstream.close();<br>
}<br>
catch(Exception e){<br>
&nbsp;out.print(e.toString());<br>
}</font></p>
<p><font size="3">%&gt;</font></p>
<p><font size="3">模板文件</font></p>
<p><font size="3"><strong>2. template.htm</strong></font></p>
<p><font size="3">&lt;html&gt;<br>
&lt;head&gt;<br>
&lt;title&gt;###title###&lt;/title&gt;<br>
&lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312"&gt;<br>
&lt;LINK href="../css.css" rel=stylesheet type=text/css&gt;<br>
&lt;/head&gt;</font></p>
<p><font size="3">&lt;body&gt;<br>
&lt;table width="500" border="0" align="center" cellpadding="0" cellspacing="2"&gt;<br>
&nbsp; &lt;tr&gt; <br>
&nbsp;&nbsp;&nbsp; &lt;td align="center"&gt;###title###&lt;/td&gt;<br>
&nbsp; &lt;/tr&gt;<br>
&nbsp; &lt;tr&gt; <br>
&nbsp;&nbsp;&nbsp; &lt;td align="center"&gt;作者：###author###&amp;nbsp;&amp;nbsp;&lt;/td&gt;<br>
&nbsp; &lt;/tr&gt;<br>
&nbsp; &lt;tr&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;td&gt;###content###<br>
&nbsp;&lt;/td&gt;<br>
&nbsp;<br>
&nbsp; &lt;/tr&gt;</font></p>
<p><font size="3">&lt;/table&gt;<br>
&lt;/body&gt;<br>
&lt;/html&gt;</font></p>]]></description>
</item><item>
<title><![CDATA[XMLHttp 方式实现无刷屏,在IE,FireFox 上测试通过]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=guan1200&amp;id=6260</link>
<author>guan1200</author>
<pubDate>2005/6/2 11:07:42</pubDate>
<description><![CDATA[<p><font size="4">XMLHttp 方式实现无刷屏,在IE,FireFox 上测试通过</font></p>
<p><font size="4">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <br>&nbsp; "<a href="http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd">http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dtd</a>"&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;style&gt;<br>html {background-color:#eeeeee}<br>body {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; background-color:#ccffcc;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-family:Tahoma,Arial,Helvetica,sans-serif;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-size:12px;<br>&nbsp;&nbsp; margin-left:15%; <br>&nbsp;&nbsp; margin-right:15%;<br>&nbsp;&nbsp; border:3px groove #006600; <br>&nbsp;&nbsp; padding:15px<br>&nbsp; }<br>h1&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; text-align:left;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-size:1.5em;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; font-weight:bold<br>&nbsp;&nbsp;&nbsp;&nbsp; }<br>&lt;/style&gt;<br>&lt;script type="text/javascript"&gt;<br>// global flag<br>var isIE = false;</font></p>
<p><font size="4">// global request and XML document objects<br>var req;</font></p>
<p><font size="4">// retrieve XML document (reusable generic function);<br>// parameter is URL string (relative or complete) to<br>// an .xml file whose Content-Type is a valid XML<br>// type, such as text/xml; XML source must be from<br>// same domain as HTML file<br>function loadXMLDoc(url) {<br>&nbsp;&nbsp;&nbsp; // branch for native XMLHttpRequest object<br>&nbsp;&nbsp;&nbsp; if (window.XMLHttpRequest) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req = new XMLHttpRequest();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.onreadystatechange = processReqChange;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.open("GET", url, true);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.send(null);<br>&nbsp;&nbsp;&nbsp; // branch for IE/Windows ActiveX version<br>&nbsp;&nbsp;&nbsp; } else if (window.ActiveXObject) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; isIE = true;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req = new ActiveXObject("Microsoft.XMLHTTP");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.onreadystatechange = processReqChange;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.open("GET", url, true);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.send();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}</font></p>
<p><font size="4">// handle onreadystatechange event of req object<br>function processReqChange() {<br>&nbsp;&nbsp;&nbsp; // only if req shows "loaded"<br>&nbsp;&nbsp;&nbsp; if (req.readyState == 4) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // only if "OK"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (req.status == 200) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clearTopicList();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buildTopicList();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert("There was a problem retrieving the XML data:\n" +<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; req.statusText);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}</font></p>
<p><font size="4">// invoked by "Category" select element change;<br>// loads chosen XML document, clears Topics select<br>// element, loads new items into Topics select element<br>function loadDoc(evt) {<br>&nbsp;&nbsp;&nbsp; // equalize W3C/IE event models to get event object<br>&nbsp;&nbsp;&nbsp; evt = (evt) ? evt : ((window.event) ? window.event : null);<br>&nbsp;&nbsp;&nbsp; if (evt) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // equalize W3C/IE models to get event target reference<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (elem) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (elem.selectedIndex &gt; 0) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; loadXMLDoc(elem.options[elem.selectedIndex].value);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch(e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; alert("Unable to get XML data:\n" + msg);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}</font></p>
<p><font size="4">// retrieve text of an XML document element, including<br>// elements using namespaces<br>function getElementTextNS(prefix, local, parentElem, index) {<br>&nbsp;&nbsp;&nbsp; var result = "";<br>&nbsp;&nbsp;&nbsp; if (prefix &amp;&amp; isIE) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // IE/Windows way of handling namespaces<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = parentElem.getElementsByTagName(prefix + ":" + local)[index];<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // the namespace versions of this method <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // (getElementsByTagNameNS()) operate<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // differently in Safari and Mozilla, but both<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // return value with just local name, provided <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // there aren't conflicts with non-namespace element<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // names<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = parentElem.getElementsByTagName(local)[index];<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; if (result) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // get text, accounting for possible<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // whitespace (carriage return) text nodes <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (result.childNodes.length &gt; 1) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result.childNodes[1].nodeValue;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return result.firstChild.nodeValue;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return "n/a";<br>&nbsp;&nbsp;&nbsp; }<br>}</font></p>
<p><font size="4">// empty Topics select list content<br>function clearTopicList() {<br>&nbsp;&nbsp;&nbsp; var select = document.getElementById("topics");<br>&nbsp;&nbsp;&nbsp; while (select.length &gt; 0) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select.remove(0);<br>&nbsp;&nbsp;&nbsp; }<br>}</font></p>
<p><font size="4">// add item to select element the less<br>// elegant, but compatible way.<br>function appendToSelect(select, value, content) {<br>&nbsp;&nbsp;&nbsp; var opt;<br>&nbsp;&nbsp;&nbsp; opt = document.createElement("option");<br>&nbsp;&nbsp;&nbsp; opt.value = value;<br>&nbsp;&nbsp;&nbsp; opt.appendChild(content);<br>&nbsp;&nbsp;&nbsp; select.appendChild(opt);<br>}</font></p>
<p><font size="4">// fill Topics select list with items from<br>// the current XML document<br>function buildTopicList() {<br>&nbsp;&nbsp;&nbsp; var select = document.getElementById("topics");<br>&nbsp;&nbsp;&nbsp; var items = req.responseXML.getElementsByTagName("item");<br>&nbsp;&nbsp;&nbsp; // loop through &lt;item&gt; elements, and add each nested<br>&nbsp;&nbsp;&nbsp; // &lt;title&gt; element to Topics select element<br>&nbsp;&nbsp;&nbsp; for (var i = 0; i &lt; items.length; i++) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; appendToSelect(select, i,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.createTextNode(getElementTextNS("", "title", items[i], 0)));<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; // clear detail display<br>&nbsp;&nbsp;&nbsp; document.getElementById("details").innerHTML = "";<br>}</font></p>
<p><font size="4">// display details retrieved from XML document<br>function showDetail(evt) {<br>&nbsp;&nbsp;&nbsp; evt = (evt) ? evt : ((window.event) ? window.event : null);<br>&nbsp;&nbsp;&nbsp; var item, content, div;<br>&nbsp;&nbsp;&nbsp; if (evt) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var select = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (select &amp;&amp; select.options.length &gt; 1) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // copy &lt;content:encoded&gt; element text for<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // the selected item<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; item = req.responseXML.getElementsByTagName("item")[select.value];<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; content = getElementTextNS("content", "encoded", item, 0);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; div = document.getElementById("details");<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; div.innerHTML = "";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // blast new HTML content into "details" &lt;div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; div.innerHTML = content;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}<br>&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;h1&gt;XMLHttpRequest Object Demo&lt;/h1&gt;<br>&lt;hr /&gt; </font></p>
<p><font size="4">&lt;form&gt;<br>&lt;p&gt;Category:&lt;br /&gt;<br>&lt;select onchange="loadDoc(event)"&gt;<br>&nbsp;&nbsp;&nbsp; &lt;option value=""&gt;Choose One&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp; &lt;option value="songs.xml"&gt;Top 10 Songs&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp; &lt;option value="albums.xml"&gt;Top 10 Albums&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp; &lt;option value="newreleases.xml"&gt;Top 10 New Releases&lt;/option&gt;<br>&nbsp;&nbsp;&nbsp; &lt;option value="justadded.xml"&gt;Top 10 Just Added&lt;/option&gt;<br>&lt;/select&gt;<br>&lt;/p&gt;<br>&lt;p&gt;Items:&lt;br /&gt;<br>&lt;select size="10" id="topics" onchange="showDetail(event)"&gt;<br>&nbsp;&nbsp;&nbsp; &lt;option value=""&gt;Choose a Category First&lt;/option&gt;<br>&lt;/select&gt;<br>&lt;/p&gt;<br>&lt;/form&gt;<br>&lt;div id="details"&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;html&gt;</font></p>]]></description>
</item><item>
<title><![CDATA[xml模板语言xsl应用列]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=guan1200&amp;id=4918</link>
<author>guan1200</author>
<pubDate>2005/4/13 16:59:33</pubDate>
<description><![CDATA[<FONT size=4><SPAN style="FONT-WEIGHT: bold">1</SPAN>.ie6.0 firfox1.0以上使用xsl 在客服端处理,<BR></FONT>
<P><FONT size=4>（有关xsl应用的其他信息，请参阅用xsl作为模板语言。）&nbsp; <BR><BR>在java中创建xml文档字符串的xml工具类:&nbsp;&nbsp;</FONT> </P><FONT size=4>public class XmlUtil {<BR><BR>&nbsp;&nbsp; &nbsp;public static void main(String[] args) {<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.print(XmlUtil.beginDocument("join"));<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;System.out.println(XmlUtil.endDocument("join"));<BR>&nbsp;&nbsp; &nbsp;}<BR><BR>&nbsp;&nbsp; &nbsp;/**<BR>&nbsp;&nbsp; &nbsp; * @param stylesheet<BR>&nbsp;&nbsp; &nbsp; * @param root<BR>&nbsp;&nbsp; &nbsp; * @return<BR>&nbsp;&nbsp; &nbsp; */<BR>&nbsp;&nbsp; &nbsp;public static String beginDocument(String stylesheet, String root) {<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;StringBuffer xml = new StringBuffer(<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;?xml-stylesheet type=\"text/xsl\" href=\"");<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return xml<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;.append(stylesheet)<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;.append(<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"\"?&gt;\n\n&lt;!-- edited with (http://www.myige.com) by guan xiang huang (Hong.co) --&gt;\n\n&lt;")<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;.append(root).append("&gt;\n").toString();<BR>&nbsp;&nbsp; &nbsp;}<BR><BR>&nbsp;&nbsp; &nbsp;/**<BR>&nbsp;&nbsp; &nbsp; * @param root<BR>&nbsp;&nbsp; &nbsp; * @return<BR>&nbsp;&nbsp; &nbsp; */<BR>&nbsp;&nbsp; &nbsp;public static String beginDocument(String root) {<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;StringBuffer xml = new StringBuffer(<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n");<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return xml<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;.append(<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;"\n&lt;!-- edited with (http://www.myige.com) by guan xiang huang (Hong.co) --&gt;\n\n&lt;")<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;.append(root).append("&gt;\n").toString();<BR>&nbsp;&nbsp; &nbsp;}<BR><BR>&nbsp;&nbsp; &nbsp;/**<BR>&nbsp;&nbsp; &nbsp; * @param root<BR>&nbsp;&nbsp; &nbsp; * @return<BR>&nbsp;&nbsp; &nbsp; */<BR>&nbsp;&nbsp; &nbsp;public static String endDocument(String root) {<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;StringBuffer xml = new StringBuffer();<BR>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;return xml.append("&lt;/").append(root).append("&gt;").toString();<BR>&nbsp;&nbsp; &nbsp;}<BR>}<BR>在servlet中使用<BR>response.setContentType("text/xml;chartset=UTF-8");<BR>StringBuffer xml = new StringBuffer(XmlUtil.beginDocument("login","login.xsl"));<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String url = request.getHeader("referer");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xml.append("\t&lt;code&gt;").append(request.getSession().getId()).append(<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "&lt;/code&gt;\n\t&lt;url&gt;").append(url).append("&lt;/url&gt;\n");<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xml.append(XmlUtil.endDocument("login"));<BR>response.getWrite( xml),<BR><BR>服务器端 servlet调用解析引擎，从xml文件和静态的xsl样式表中创建html输出。<BR>public void doPost(HttpServletRequest request, HttpServletResponse response)<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; throws ServletException, IOException {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; response.setContentType("text/html;charset=UTF-8");<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; StringBuffer xml = new StringBuffer(XmlUtil.beginDocument("login"));<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; String url = request.getHeader("referer");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xml.append("\t&lt;code&gt;").append(request.getSession().getId()).append(<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; "&lt;/code&gt;\n\t&lt;url&gt;").append(url).append("&lt;/url&gt;\n");<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xml.append(XmlUtil.endDocument("login"));<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TransformerFactory factory = TransformerFactory.newInstance();<BR>//templates 使用templates;可以加快xsl文件处理速度<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Templates templates = factory.newTemplates(new StreamSource(<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; new File(getServletContext().getRealPath("/")<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; + "xsl/login.xsl")));<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Transformer transformer = templates.newTransformer();<BR>//不使用templates；<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //Transformer transformer = factory.newTransformer(new StreamSource(new File(getServletContext().getRealPath("/")+"xsl/login.xsl")));<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; transformer.transform(new StreamSource(new StringReader(xml<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; .toString())), new StreamResult(response.getWriter()));<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } catch (Exception e) {<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e.printStackTrace();<BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp; }<BR></FONT><BR><BR>]]></description>
</item><item>
<title><![CDATA[tomcat下数据源的配置、解释和调用方法]]></title>
<link>http://blogger.org.cn/blog/more.asp?name=guan1200&amp;id=4572</link>
<author>guan1200</author>
<pubDate>2005/4/5 23:42:02</pubDate>
<description><![CDATA[<font size="2"></font><p><font size="4">tomcat下数据源的配置、解释和调用方法</font></p>
<p><font size="4">[所在目录]首页&gt;分类目录&gt;电脑与网络&gt;互联网络：<br>
<a href="http://www.3yee.com/articles/449.aspx">http://www.3yee.com/articles/449.aspx</a><br>
来自：Java学习 jargon - 2004-4-27 23:36:00</font></p>
<p><font size="4"><br>
tomcat的数据库连接池的配置<br>
环境：<br>
1. 数据库：mysql<br>
2. 数据库驱动程序：org.gjt.mm.mysql.Driver<br>
JNDI（Java Naming and Directory Interface）概述：<br>
Tomcat4
（5）提供了一个与Java Enterprise
Edition应用服务相兼容的JNDI--InitialContext实现实例。它的初始数据设置在$
CATALINA_HOME/conf/server.xml文件里，并可能在网页应用环境描述（/WEB-INF/web.xml）里被下列元素引用：<br>
1) &lt;env-entry&gt;--环境入口，设置应用程序如何操作。<br>
2) &lt;resource-ref&gt;--资源参数，一般是数据库驱动程序、JavaMail Session、自定义类工厂等。<br>
3) &lt;resource-env-ref&gt;--在Servlet 2.4里用来简化设置不需认证信息的资源资源如环境参数、resource-ref变量。<br>
InitialContext在网页应用程序初始化时被设置，用来支持网页应用程序组件。所有的入口和资源都放在JNDI命名空间里的java:comp/env段里。点击下列网址以获取更多信息：<br>
1) Java命名和目录接口（Java Naming and Directory Interface）<br>
2) J2EE平台说明（J2EE Platform Specification）<br>
设置JNDI资源<br>
设置JNDI资源要在$CATALINA_HOME/conf/server.xml文件里使用下列标志符：<br>
1) &lt;Environment&gt;--设置域个可变的JNDI InitialContext入口的名字和值（同上面说的&lt;env-entry&gt;等价）。<br>
2) &lt;Resource&gt;--设置应用程序可用的资源的名字和类型（同上面说的&lt;resource-ref&gt;等价）。<br>
3) &lt;ResourceParams&gt;--设置Java资源类工厂的名称或将用的JavaBean属性。<br>
4) &lt;ResourceLink&gt;--给全局JNDI环境（JNDI Context）添加一个链接。<br>
上述这些标志符必须放在&lt;Context&gt;和&lt;/Context&gt;之间（针对专门的网页应用程序）或&lt;DefaultContext&gt;和&lt;/DefaultContext&gt;之间。<br>
此外，设在网页应用环境描述（Web Application Descriptor）（/WEB-INF/web.xml）里的名字和值也在初始环境（Initial Context）里被设置，当被&lt;Environemt&gt;元素值允许时将被重设初始值。<br>
全局变量能在&lt;Server&gt;子元素的&lt;GlobalNamingResources&gt;里设置。<br>
数据库连接池概述：<br>
数据库连接是一种关键的有限的昂贵的资源，这一点在多用户的网页应用程序中体现得尤为突出。对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性，影响到程序的性能指标。数据库连接池正是针对这个问题提出来的。<br>
数据库连接池负责分配、管理和释放数据库连接，它允许应用程序重复使用一个现有的数据库连接，而再不是重新建立一个；释放空闲时间超过最大空闲时间的数据库连接来避免因为没有释放数据库连接而引起的数据库连接遗漏。这项技术能明显提高对数据库操作的性能。<br>
数
据库连接池在初始化时将创建一定数量的数据库连接放到连接池中，这些数据库连接的数量是由最小数据库连接数来设定的。无论这些数据库连接是否被使用，连接
池都将一直保证至少拥有这么多的连接数量。连接池的最大数据库连接数量限定了这个连接池能占有的最大连接数，当应用程序向连接池请求的连接数超过最大连接
数量时，这些请求将被加入到等待队列中。数据库连接池的最小连接数和最大连接数的设置要考虑到下列几个因素：<br>
1) 最小连接数是连接池一直保持的数据库连接，所以如果应用程序对数据库连接的使用量不大，将会有大量的数据库连接资源被浪费；<br>
2) 最大连接数是连接池能申请的最大连接数，如果数据库连接请求超过此数，后面的数据库连接请求将被加入到等待队列中，这会影响之后的数据库操作。<br>
3) 如果最小连接数与最大连接数相差太大，那么最先的连接请求将会获利，之后超过最小连接数量的连接请求等价于建立一个新的数据库连接。不过，这些大于最小连接数的数据库连接在使用完不会马上被释放，它将被放到连接池中等待重复使用或是空闲超时后被释放。<br>
配置Tomcat数据库连接池的前提：<br>
1. 必须装有Java运行环境；<br>
2. mysql；<br>
在$CATALINA_HOME/conf/server.xml里设置数据库连接池：<br>
下面是配置的代码，必须放在&lt;Host&gt;和&lt;/Host&gt;之间。<br>
&lt;Context path="/test" docBase="test" debug="0" reloadable="true" crossContext="true"&gt;<br>
&lt;Resource name="jdbc/connectDB" auth="Container" type="javax.sql.DataSource"/&gt;<br>
&lt;ResourceParams name="jdbc/connectDB"&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;maxActive&lt;/name&gt;<br>
&nbsp; &lt;!-- Maximum number of DB connections in pool.Set to 0 for no limit. --&gt;<br>
&nbsp; &lt;value&gt;100&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;maxIdle&lt;/name&gt;<br>
&nbsp; &lt;!-- Maximum number of idle DB connections to retain in pool.Set to 0 for no limit. --&gt;<br>
&nbsp; &lt;value&gt;30&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;maxWait&lt;/name&gt;<br>
&nbsp;
&lt;!-- Maximum time to wait for a DB connection to become available in
ms.An exception is thrown if this timeout is exceeded.Set to -1 to wait
indefinitely. --&gt;<br>
&nbsp; &lt;value&gt;10000&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;removeAbandoned&lt;/name&gt;<br>
&nbsp; &lt;!-- Abandoned DB connections are removed and recycled --&gt;<br>
&nbsp; &lt;value&gt;true&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;removeAbandonedTimeout&lt;/name&gt;<br>
&nbsp;
&lt;!-- Use the removeAbandonedTimeout parameter to set the number of
seconds a DB connection has been idle before it is considered
abandoned.&nbsp; --&gt;<br>
&nbsp; &lt;value&gt;60&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;logAbandoned&lt;/name&gt;<br>
&nbsp; &lt;!-- Log a stack trace of the code which abandoned --&gt;<br>
&nbsp; &lt;value&gt;false&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;factory&lt;/name&gt;<br>
&nbsp; &lt;!-DBCP Basic Datasource Factory --&gt;<br>
&nbsp; &lt;value&gt;org.apache.commons.dbcp.BasicDataSourceFactory&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;username&lt;/name&gt;<br>
&nbsp; &lt;!-- Database User Name --&gt;<br>
&nbsp; &lt;value&gt;root&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;password&lt;/name&gt;<br>
&nbsp; &lt;!-- User Password --&gt;<br>
&nbsp; &lt;value&gt;&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;driverClassName&lt;/name&gt;<br>
&nbsp; &lt;!-- Database Driver Class Name --&gt;<br>
&nbsp; &lt;value&gt;org.gjt.mm.mysql.Driver&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&nbsp;&lt;parameter&gt;<br>
&nbsp; &lt;name&gt;url&lt;/name&gt;<br>
&nbsp; &lt;!-- Database Address --&gt;<br>
&nbsp; &lt;value&gt;jdbc:mysql://localhost/test</font><font size="4">?user=root&amp;password=abcd1001&amp;useUnicode=true&amp;characterEncoding=8859_1&lt;/value&gt;<br>
&nbsp;&lt;/parameter&gt;<br>
&lt;/ResourceParams&gt;<br>
&lt;/Context&gt;<br>
下面是一些参数的说明：<br>
&lt;Context path="/test" docBase="test" debug="0" reloadable="true" crossContext="true"&gt;<br>
其中：<br>
1) path&nbsp; 指定路径，这里设定的是$CATALINA_HOME/webapps下的test目录；<br>
2) docBase 文件根目录。<br>
3) reloader&nbsp; 当网页被更新时是否重新编译。<br>
4) maxActive 连接池的最大数据库连接数。设为0表示无限制。<br>
5) maxIdle&nbsp; 数据库连接的最大空闲时间。超过此空闲时间，数据库连接将被标记为不可用，然后被释放。设为0表示无限制。<br>
6) maxWait 最大建立连接等待时间。如果超过此时间将接到异常。设为－1表示无限制。<br>
7) removeAbandoned 回收被遗弃的（一般是忘了释放的）数据库连接到连接池中。<br>
8) removeAbandonedTimeout 数据库连接过多长时间不用将被视为被遗弃而收回连接池中。<br>
9) logAbandoned 将被遗弃的数据库连接的回收记入日志。<br>
10) driverClassName JDBC驱动程序。<br>
11) url&nbsp;&nbsp; 数据库连接字符串<br>
在$CATALINA_HOME/webapps/test/WEB-INF/web.xml里设置被引用的资源：<br>
下面是配置代码，必须放在&lt;web-app&gt;和&lt;/web-app&gt;里。<br>
&lt;!-- Database Config start --&gt;<br>
&lt;resource-ref&gt;<br>
&lt;description&gt;connectDB test&lt;/description&gt;<br>
&lt;res-ref-name&gt;jdbc/connectDB&lt;/res-ref-name&gt;<br>
&lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;<br>
&lt;res-auth&gt;Container&lt;/res-auth&gt;<br>
&lt;/resource-ref&gt;<br>
&lt;!-- Database Config end --&gt;<br>
下面是一下参数的必要说明：<br>
1) description&nbsp; 对被引用的资源的描述。<br>
2) res-ref-name&nbsp; 资源名称。见上面的&lt;ResourceParams name="jdbc/connectDB"&gt;<br>
3) res-type&nbsp; 资源类型。见上面的&lt;Resource name="jdbc/connectDB" auth="Container" type="javax.sql.DataSource"/&gt;<br>
为了方便做解释直接在JSP中使用资源：<br>
这是在$CATALINA_HOME/webapps/test下的某级子目录里的jsp网页文件部分代码：<br>
&lt;%@ page contentType="text/html;charset=GBK"%&gt;<br>
&lt;%@ page errorPage="error.jsp"%&gt;<br>
&lt;%@ page import="javax.naming.*"%&gt;<br>
&lt;%@ page import="javax.sql.*"%&gt;<br>
&lt;%@ page import="java.sql.*"%&gt;<br>
&lt;html&gt;<br>
&nbsp;&lt;head&gt;<br>
&nbsp;&lt;/head&gt;<br>
&nbsp;&lt;body&gt;<br>
&nbsp; &lt;%</font></p>
<p><font size="4">&nbsp;&nbsp; ………………<br>
&nbsp;&nbsp; ………………</font></p>
<p><font size="4">&nbsp;&nbsp; // 数据库操作<br>
&nbsp;&nbsp; Context ctx=null;<br>
&nbsp;&nbsp; Connection cnn=null;<br>
&nbsp;&nbsp; Statement stmt=null;<br>
&nbsp;&nbsp; ResultSet rs=null;<br>
&nbsp;&nbsp; try<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; ctx=new InitialContext();<br>
&nbsp;&nbsp;&nbsp; if(ctx==null)<br>
&nbsp;&nbsp;&nbsp;&nbsp; throw new Exception("没有匹配的环境");<br>
&nbsp;&nbsp;&nbsp; DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/connectDB");<br>
&nbsp;&nbsp;&nbsp; if(ds==null)<br>
&nbsp;&nbsp;&nbsp;&nbsp; throw new Exception("没有匹配数据库");<br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; cnn=ds.getConnection();<br>
&nbsp;&nbsp;&nbsp; stmt=cnn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);<br>
&nbsp;&nbsp;&nbsp; rs=stmt.executeQuery("select * from table1");</font></p>
<p><font size="4">&nbsp;&nbsp;&nbsp; ………………<br>
&nbsp;&nbsp;&nbsp; ………………</font></p>
<p><font size="4">&nbsp;&nbsp; }<br>
&nbsp;&nbsp; finally<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; if(rs!=null)<br>
&nbsp;&nbsp;&nbsp;&nbsp; rs.close();<br>
&nbsp;&nbsp;&nbsp; if(stmt!=null)<br>
&nbsp;&nbsp;&nbsp;&nbsp; stmt.close();<br>
&nbsp;&nbsp;&nbsp; if(cnn!=null)<br>
&nbsp;&nbsp;&nbsp;&nbsp; cnn.close();<br>
&nbsp;&nbsp;&nbsp; if(ctx!=null)<br>
&nbsp;&nbsp;&nbsp;&nbsp; ctx.close();<br>
&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; %&gt;<br>
&nbsp;&lt;/body&gt;<br>
&lt;/html&gt;<br>
代码说明：<br>
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/connectDB");<br>
上面这句应用了刚才设的资源。<br>
资
源使用完要释放，尤其是Context资源，见try-catch-finally部分的finally代码段，这是一种好的习惯。资源释放时如果释放了
上级资源，下级资源将先被释放。如：释放了ctx，那么资源释放顺序将是rs，stmt，cnn，ctx。换句话说，如果释放了ctx，那么rs，
stmt和cnn都将不可用了。<br>
这里的释放资源只是将数据库连接返回连接池中，并不是把资源真正释放掉，见数据库连接池概述。</font><br></p>]]></description>
</item>
</channel>
</rss>