﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-J度空间</title><link>http://www.blogjava.net/jdo/</link><description /><language>zh-cn</language><lastBuildDate>Thu, 07 May 2026 06:40:22 GMT</lastBuildDate><pubDate>Thu, 07 May 2026 06:40:22 GMT</pubDate><ttl>60</ttl><item><title>Java数字、货币值和百分数等的格式化处理</title><link>http://www.blogjava.net/jdo/articles/168621.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Tue, 18 Dec 2007 16:15:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/168621.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/168621.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/168621.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/168621.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/168621.html</trackback:ping><description><![CDATA[如果我们用下列语句输出一个数 <br /><div class="postText"><p><br />---------------------------------------- <br /><br />System.out.println(123456.789); <br /><br />---------------------------------------- <br /><br />将会在Console看到输出 <br /><br />---------------------------------------- <br /><br />123456.789 <br /><br />---------------------------------------- <br /><br />那么如何得到“123，456.789”这种格式化的输出呢？ <br /><br />这里就需要用到java.text.Format这个类。 <br /><br />不仅是数字，它还提供了货币值和百分数的格式化输出，例如0.58的百分数输出形式是58%。 <br /><br />要获得本地的默认格式，可以用下列方法获得： <br /><br />NumberFormat.getNumberInstance() <br />NumberFormat.getCurrencyInstance() <br />NumberFormat.getOpercentInstance() <br /><br />而要获得某个国家或地区的具体格式，可以使用参数Local.XXX。例如，Local.GERMANY，Local.UK。 <br /><br />范例： <br /><br />--------------------------------------------------------------- <br /><br />import java.text.NumberFormat;<br />import java.util.Locale; <br /><br />public class FormatTest{ <br />    public static void main(String args[]){ <br /><br />        //不使用格式化输出数 <br />          double d = 10000.0/3.0; <br />        System.out.println("无格式化输出：" + d); <br /><br />        //使用本地默认格式输出数 <br />          NumberFormat numberFormat = NumberFormat.getNumberInstanc(); <br />        //numberFormat.setMaximumFractionDigits(4); <br />        //numberFormat.setMinimumIntegerDigits(6); <br />        String numberString = numberFormat.format(d); <br />        System.out.println("本地默认格式输出数：" + numberString); <br /><br />       //使用本地默认格式输出货币值 <br />         NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(); <br />       System.out.println("本地默认格式输出货币值：" + currencyFormat.format(d)); <br /><br />       //使用本地默认格式输出百分数 <br />         NumberFormat percentFormat = NumberFormat.getPercentInstance(); <br />       System.out.println("本地默认格式输出百分数：" + percentFormat.format(d)); <br /><br />      //在不同的国家各地区数字表示的格式也有区别。例如德国 <br />          //使用德国的格式化输出数 <br />            NumberFormat numberFormatG = NumberFormat.getNumberInstance(Local.GERMANY); <br />          System.out.println("德国数字输出形式：" + numberFormatG.format(d)); <br /><br />         //使用德国货币输出形式 <br />           NumberFormat currencyFormatG = NumberFormat.getCurrencyInstance(Local.GERMANY); <br />         System.out.println("德国货币输出形式：" + currencyFormatG.format(d)); <br /><br />         //使用美国货币输出形式 <br />           NumberFormat currencyFormatA = NumberFormat.getCurrencyInstance(Local.US); <br />         System.out.println("美国货币输出形式：" + currencyFormatG.format(d)); <br />        <br />         //使用德国百分数输出形式 <br />           NumberFormat percentFormatG = NumberFormat.getPercentInstance(Local.GERMANY); <br />         System.out.println("德国百分数输出形式：" + percentFormatG .format(d)); <br /><br />         System.exit(0);<br />     }<br /> }<br /> <br />--------------------------------------------------------------------------------- <br /><br />程序输出 <br /><br />--------------------------------------- <br /><br />&lt;!--[if !vml]--&gt;&lt;!--[endif]--&gt; <br /><br />--------------------------------------- <br /><br />由于欧元符号无法在此Console输出，所以显示？ <br /><br />可以指定显示的最多（或最少）整数位和小数位。如 <br /><br />--------------------------------------- <br /><br />double d = 10000.0/3.0; <br />NumberFormat numberFormat = NumberFormat.getNumberInstance(); <br />numberFormat.setMaximumFractionDigits(4); <br />numberFormat.setMinimumIntegerDigits(6); <br />String numberString = numberFormat.format(d); <br />System.out.println(numberString);<br /> <br />--------------------------------------- <br /><br />输出： <br /><br />--------------------------------------- <br /><br />003，333.3333 <br /><br />--------------------------------------- <br /><br />整数位不够的补零，小数截去部分四舍五入。 <br /><br />也可以利用NumberFormat的一个子类DecimalFormat来指定输出格式。 <br /><br />--------------------------------------- <br /><br />DecimalFormat decimalFormat = new DecimalFormat("######.0000"); <br />String s = decimalFormat.format(d); <br /><br />--------------------------------------- <br /><br />和前面一样，显示6个整数位和4个小数位。 <br /><br />下面对格式化的数字进行解析。 <br /><br />--------------------------------------- <br /><br />import java.util.Locale; <br />import java.text.NumberFormat;<br />import java.text.ParseException; <br /><br />public class ParseFormat{ <br />    public static void main(String args[]){ <br /><br />        //本地格式的解析 <br />          NumberFormat numberFormat1 = NumberFormat.getNumberInstance(); <br />       Number numb1 = null; <br /><br />       try <br />      { <br />           numb1 = numberFormat1.parse("33,333.33"); <br />       } <br />       catch(ParseException e1) <br />      { <br />           System.err.println(e1); <br />      } <br />      System.out.println(number1); <br /><br />      //以德国格式解析 <br />        NumberFormat numberFormat2 = NumberFormat.getNumberInstance(Locale.GERMANY); <br />        Number numb2 = null; <br /> <br />        try <br />       { <br />            numb2 = numberFormat2.parse("33,333.33"); <br />       } <br />       catch(ParseException e2) <br />       { <br />            System.err.println(e2);<br />       } <br />       System.out.println(number2); <br /><br />       System.exit(0); <br />    }<br />}<br /> <br />--------------------------------- <br /><br />程序输出： <br /><br />--------------------------------- <br /><br />33333.33 33.333<br /> <br />--------------------------------<br /> <br />同样一种格式33,333.33，有人将之理解为33333.33，也有人认为它是33.333，软件国际化的重要性可见一斑。 </p></div><img src ="http://www.blogjava.net/jdo/aggbug/168621.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-12-19 00:15 <a href="http://www.blogjava.net/jdo/articles/168621.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BMP文件格式分析</title><link>http://www.blogjava.net/jdo/articles/146989.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Fri, 21 Sep 2007 02:09:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/146989.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/146989.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/146989.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/146989.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/146989.html</trackback:ping><description><![CDATA[
		<p align="center">
				<font size="-0">本来不想写这篇东西，因为介绍BMP文件结构的资料太多了，都有些滥了。但刚写完BMP的读写模块，又不想不留下点什么，所以就写了，全当是学习笔记吧。自己以后查资料时也方便一些，也许对某些初哥还会有点用^_^</font>
				<br />
		</p>
		<blockquote>
				<strong>
						<font color="#ff0000">
								<p align="center">简介</p>
						</font>
				</strong>
		</blockquote>
		<p>
				<font size="3">BMP(<strong>B</strong>it<strong>m</strong>a<strong>p</strong>-File)
图形文件是Windows采用的图形文件格式，在Windows环境下运行的所有图象处理软件都支持BMP图象文件格式。Windows系统内部各图像绘
制操作都是以BMP为基础的。Windows 3.0以前的BMP图文件格式与显示设备有关，因此把这种BMP图象文件格式称为设备相关位图DDB(<strong>d</strong>evice-<strong>d</strong>ependent <strong>b</strong>itmap)文件格式。Windows 3.0以后的BMP图象文件与显示设备无关，因此把这种BMP图象文件格式称为设备无关位图DIB(<strong>d</strong>evice-<strong>i</strong>ndependent <strong>b</strong>itmap)
格式（注：Windows
3.0以后，在系统中仍然存在DDB位图，象BitBlt()这种函数就是基于DDB位图的，只不过如果你想将图像以BMP格式保存到磁盘文件中时，微软
极力推荐你以DIB格式保存），目的是为了让Windows能够在任何类型的显示设备上显示所存储的图象。BMP位图文件默认的文件扩展名是BMP或者
bmp（有时它也会以.DIB或.RLE作扩展名）。 </font>
		</p>
		<blockquote>
				<strong>
						<font color="#ff0000">
								<p>6.1.2 文件结构</p>
						</font>
				</strong>
		</blockquote>
		<p align="center">
				<font size="3">位图文件可看成由4个部分组成：位图文件头(bitmap-file header)、位图信息头(bitmap-information header)、彩色表(color table)和定义位图的字节阵列，它具有如下所示的形式。 </font>
		</p>
		<div align="center">
				<center>
						<table style="margin-left: auto; margin-right: auto;" bordercolordark="#000000" bordercolorlight="#cc6600" border="1" cellspacing="2" width="510">
								<tbody>
										<tr>
												<td width="232">
														<p align="center">
																<font size="3">位图文件的组成</font>
														</p>
												</td>
												<td width="157">
														<p align="center">
																<font size="-0">结构名称</font>
														</p>
												</td>
												<td width="103">
														<p align="center">
																<font size="-0">符号</font>
														</p>
												</td>
										</tr>
										<tr>
												<td width="232">
														<font size="-0">位图文件头(bitmap-file header)</font>
												</td>
												<td width="157">
														<font size="-0">BITMAPFILEHEADER</font>
												</td>
												<td width="103">
														<font size="-0">bmfh</font>
												</td>
										</tr>
										<tr>
												<td width="232">
														<font size="-0">位图信息头(bitmap-information header)</font>
												</td>
												<td width="157">
														<font size="-0">BITMAPINFOHEADER</font>
												</td>
												<td width="103">
														<font size="-0">bmih</font>
												</td>
										</tr>
										<tr>
												<td width="232">
														<font size="-0">彩色表(color table)</font>
												</td>
												<td width="157">
														<font size="-0">RGBQUAD</font>
												</td>
												<td width="103">
														<font size="-0">aColors[]</font>
												</td>
										</tr>
										<tr>
												<td width="232">
														<font size="-0">图象数据阵列字节</font>
												</td>
												<td width="157">
														<font size="-0">BYTE</font>
												</td>
												<td width="103">
														<font size="-0">aBitmapBits[]</font>
												</td>
										</tr>
								</tbody>
						</table>
				</center>
		</div>
		<p>
				<font size="3">位图文件结构可综合在表6-01中。 </font>
		</p>
		<blockquote>
				<strong>
						<p align="center">
								<font size="3">表01 位图文件结构内容摘要</font>
						</p>
				</strong>
				<font size="3">
				</font>
		</blockquote>
		<div align="center">
				<center>
						<table style="margin-left: auto; margin-right: auto;" bordercolordark="#000000" bordercolorlight="#cc6600" border="1" cellpadding="7" cellspacing="2" width="585">
								<tbody>
										<tr>
												<td width="18">　</td>
												<td width="43">
														<p align="center">
																<strong>
																		<font size="-0">偏移量</font>
																</strong>
														</p>
												</td>
												<td width="96">
														<p align="center">
																<strong>
																		<font size="-0">域的名称</font>
																</strong>
														</p>
												</td>
												<td width="58">
														<p align="center">
																<strong>
																		<font size="-0">大小</font>
																</strong>
														</p>
												</td>
												<td width="287">
														<p align="center">
																<strong>
																		<font size="-0">内容</font>
																</strong>
														</p>
												</td>
										</tr>
										<tr>
												<td width="27">
														<font size="-0">　</font>
														<p>
																<font size="-0">　</font>
														</p>
														<p>
																<font size="-0">　</font>
														</p>
														<p>
																<font size="-0">图象文件</font>
														</p>
														<p>
																<font size="-0">头</font>
														</p>
												</td>
												<td width="43">
														<font size="-0">0000h</font>
												</td>
												<td width="80">
														<font size="-0">文件标识</font>
												</td>
												<td width="58">
														<font size="-0">2 bytes</font>
												</td>
												<td width="287">
														<font size="-0">两字节的内容用来识别位图的类型：</font>
														<p>
																<font size="-0">‘BM’ ： Windows 3.1x, 95, NT, …</font>
														</p>
														<p>
																<font size="-0">‘BA’ ：OS/2 Bitmap Array</font>
														</p>
														<p>
																<font size="-0">‘CI’ ：OS/2 Color Icon</font>
														</p>
														<p>
																<font size="-0">‘CP’ ：OS/2 Color Pointer</font>
														</p>
														<p>
																<font size="-0">‘IC’ ： OS/2 Icon</font>
														</p>
														<p>
																<font size="-0">‘PT’ ：OS/2 Pointer</font>
														</p>
														<p>
																<font size="-0">注：因为OS/2系统并没有被普及开，所以在编程时，你只需判断第一个标识“BM”就行。</font>
														</p>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">0002h</font>
												</td>
												<td width="80">
														<font size="-0">File Size</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">用字节表示的整个文件的大小</font>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">0006h</font>
												</td>
												<td width="80">
														<font size="-0">Reserved</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">保留，必须设置为0</font>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">000Ah</font>
												</td>
												<td width="80">
														<font size="-0">Bitmap Data Offset</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">从文件开始到位图数据开始之间的数据(bitmap data)之间的偏移量</font>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">000Eh</font>
												</td>
												<td width="80">
														<font size="-0">Bitmap Header Size</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">位图信息头(Bitmap Info Header)的长度，用来描述位图的颜色、压缩方法等。下面的长度表示：</font>
														<p>
																<font size="-0">28h - Windows 3.1x, 95, NT, …</font>
														</p>
														<p>
																<font size="-0">0Ch - OS/2 1.x</font>
														</p>
														<p>
																<font size="-0">F0h - OS/2 2.x</font>
														</p>
														<p>
																<font size="-0">注：
在Windows95、98、2000等操作系统中，位图信息头的长度并不一定是28h，因为微软已经制定出了新的BMP文件格式，其中的信息头结构变化
比较大，长度加长。所以最好不要直接使用常数28h，而是应该从具体的文件中读取这个值。这样才能确保程序的兼容性。</font>
														</p>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">0012h</font>
												</td>
												<td width="80">
														<font size="-0">Width</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">位图的宽度，以象素为单位</font>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">0016h</font>
												</td>
												<td width="80">
														<font size="-0">Height</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">位图的高度，以象素为单位</font>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">001Ah</font>
												</td>
												<td width="80">
														<font size="-0">Planes</font>
												</td>
												<td width="58">
														<font size="-0">1 word</font>
												</td>
												<td width="287">
														<font size="-0">位图的位面数（注：该值将总是1）</font>
												</td>
										</tr>
										<tr>
												<td width="27">
														<br />
														<font size="-0">图象</font>
														<p>
																<font size="-0">信息</font>
														</p>
														<p>
																<font size="-0">头</font>
														</p>
														<p>
																<font size="-0">　</font>
														</p>
														<p>　</p>
												</td>
												<td width="43">
														<font size="-0">001Ch</font>
												</td>
												<td width="80">
														<font size="-0">Bits Per Pixel</font>
												</td>
												<td width="58">
														<font size="-0">1 word</font>
												</td>
												<td width="287">
														<font size="-0">每个象素的位数</font>
														<p>
																<font size="-0">1 - 单色位图（实际上可有两种颜色，缺省情况下是黑色和白色。你可以自己定义这两种颜色）</font>
														</p>
														<p>
																<font size="-0">4 - 16 色位图</font>
														</p>
														<p>
																<font size="-0">8 - 256 色位图</font>
														</p>
														<p>
																<font size="-0">16 - 16bit 高彩色位图</font>
														</p>
														<p>
																<font size="-0">24 - 24bit 真彩色位图</font>
														</p>
														<p>
																<font size="-0">32 - 32bit 增强型真彩色位图</font>
														</p>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">001Eh</font>
												</td>
												<td width="80">
														<font size="-0">Compression</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">压缩说明：</font>
														<p>
																<font size="-0">0 - 不压缩 (使用BI_RGB表示)</font>
														</p>
														<p>
																<font size="-0">1 - RLE 8-使用8位RLE压缩方式(用BI_RLE8表示)</font>
														</p>
														<p>
																<font size="-0">2 - RLE 4-使用4位RLE压缩方式(用BI_RLE4表示)</font>
														</p>
														<p>
																<font size="-0">3 - Bitfields-位域存放方式(用BI_BITFIELDS表示)</font>
														</p>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">0022h</font>
												</td>
												<td width="80">
														<font size="-0">Bitmap Data Size</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">用字节数表示的位图数据的大小。该数必须是4的倍数</font>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">0026h</font>
												</td>
												<td width="80">
														<font size="-0">HResolution</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">用象素/米表示的水平分辨率</font>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">002Ah</font>
												</td>
												<td width="80">
														<font size="-0">VResolution</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">用象素/米表示的垂直分辨率</font>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">002Eh</font>
												</td>
												<td width="80">
														<font size="-0">Colors</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">位图使用的颜色数。如8-比特/象素表示为100h或者 256.</font>
												</td>
										</tr>
										<tr>
												<td width="27">　</td>
												<td width="43">
														<font size="-0">0032h</font>
												</td>
												<td width="80">
														<font size="-0">Important Colors</font>
												</td>
												<td width="58">
														<font size="-0">1 dword</font>
												</td>
												<td width="287">
														<font size="-0">指定重要的颜色数。当该域的值等于颜色数时（或者等于0时），表示所有颜色都一样重要</font>
												</td>
										</tr>
										<tr>
												<td width="27">
														<font size="-0">调色板数据</font>
												</td>
												<td width="43">
														<font size="-0">根据BMP版本的不同而不同</font>
												</td>
												<td width="80">
														<font size="-0">Palette</font>
												</td>
												<td width="58">
														<font size="-0">N * 4 byte</font>
												</td>
												<td width="287">
														<font size="-0">调色板规范。对于调色板中的每个表项，这4个字节用下述方法来描述RGB的值：</font>
														<!--msthemelist-->
														<table border="0" cellpadding="0" cellspacing="0" width="100%">
																<!--msthemelist-->
																<tbody>
																		<tr>
																				<td valign="baseline" width="42">
																						<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
																				</td>
																				<td valign="top" width="100%">1字节用于蓝色分量<!--msthemelist--></td>
																		</tr>
																		<!--msthemelist-->
																		<tr>
																				<td valign="baseline" width="42">
																						<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
																				</td>
																				<td valign="top" width="100%">1字节用于绿色分量<!--msthemelist--></td>
																		</tr>
																		<!--msthemelist-->
																		<tr>
																				<td valign="baseline" width="42">
																						<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
																				</td>
																				<td valign="top" width="100%">1字节用于红色分量<!--msthemelist--></td>
																		</tr>
																		<!--msthemelist-->
																		<tr>
																				<td valign="baseline" width="42">
																						<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
																				</td>
																				<td valign="top" width="100%">1字节用于填充符(设置为0)<!--msthemelist--></td>
																		</tr>
																		<!--msthemelist-->
																</tbody>
														</table>
												</td>
										</tr>
										<tr>
												<td width="27">
														<font size="-0">图象数据</font>
												</td>
												<td width="43">
														<font size="-0">根据BMP版本及调色板尺寸的不同而不同</font>
												</td>
												<td width="80">
														<font size="-0">Bitmap Data</font>
												</td>
												<td width="58">
														<font size="-0">xxx bytes</font>
												</td>
												<td width="287">
														<font size="-0">该域的大小取决于压缩方法及图像的尺寸和图像的位深度，它包含所有的位图数据字节，这些数据可能是彩色调色板的索引号，也可能是实际的RGB值，这将根据图像信息头中的位深度值来决定。</font>
												</td>
										</tr>
								</tbody>
						</table>
				</center>
		</div>
		<br />
		<br />
		<br />
		<br />
		<blockquote>
				<strong>
						<font color="#ff0000">
								<p align="center">构件详解</p>
						</font>
				</strong>
		</blockquote>
		<font color="#7f007f">
				<strong>
						<p>
								<font size="3">1. 位图文件头</font>
						</p>
						<p>
								<font size="3">位图文件头包含有关于文件类型、文件大小、存放位置等信息，在Windows 3.0以上版本的位图文件中用BITMAPFILEHEADER结构来定义：</font>
						</p>
						<p>
								<font size="-0">typedef struct tagBITMAPFILEHEADER { /* bmfh */</font>
						</p>
						<blockquote>
								<font size="-0">UINT bfType;</font>
								<br />
								<font size="-0">DWORD bfSize;</font>
								<br />
								<font size="-0">UINT bfReserved1;</font>
								<br />
								<font size="-0">UINT bfReserved2;</font>
								<br />
								<font size="-0">DWORD bfOffBits;</font>
								<br />
						</blockquote>
						<font size="-0">} BITMAPFILEHEADER;</font>
						<p> </p>
						<p>
								<font size="-0">其中：</font>
								<br />  </p>
						<table border="0" cellspacing="0" width="557">
								<tbody>
										<tr>
												<td width="22%">
														<blockquote>
																<font size="-0">
																		<p>bfType</p>
																</font>
														</blockquote>
												</td>
												<td width="78%">
														<blockquote>
																<font size="-0">
																		<p>说明文件的类型.（该值必需是0x4D42，也就是字符'BM'。我们不需要判断OS/2的位图标识，这么做现在来看似乎已经没有什么意义了，而且如果要支持OS/2的位图，程序将变得很繁琐。所以，在此只建议你检察'BM'标识） </p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="22%">
														<blockquote>
																<font size="-0">
																		<p>bfSize</p>
																</font>
														</blockquote>
												</td>
												<td width="78%">
														<blockquote>
																<font size="-0">
																		<p>说明文件的大小，用字节为单位</p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="22%">
														<blockquote>
																<font size="-0">
																		<p>bfReserved1</p>
																</font>
														</blockquote>
												</td>
												<td width="78%">
														<blockquote>
																<font size="-0">
																		<p>保留，必须设置为0</p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="22%">
														<blockquote>
																<font size="-0">
																		<p>bfReserved2</p>
																</font>
														</blockquote>
												</td>
												<td width="78%">
														<blockquote>
																<font size="-0">
																		<p>保留，必须设置为0</p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="22%">
														<blockquote>
																<font size="-0">
																		<p>bfOffBits</p>
																</font>
														</blockquote>
												</td>
												<td width="78%">
														<blockquote>
																<font size="-0">
																		<p>说明从文件头开始到实际的图象数据之间的字节的偏移量。这个参数是非常有用的，因为位图信息头和调色板的长度会根据不同情况而变化，所以你可以用这个偏移值迅速的从文件中读取到位数据。</p>
																</font>
														</blockquote>
												</td>
										</tr>
								</tbody>
						</table>
						<p>
								<font color="#7f007f" size="-0">
										<strong>2. 位图信息头</strong>
								</font>
						</p>
						<p>
								<font size="-0">位
图信息用BITMAPINFO结构来定义，它由位图信息头(bitmap-information header)和彩色表(color
table)组成，前者用BITMAPINFOHEADER结构定义，后者用RGBQUAD结构定义。BITMAPINFO结构具有如下形式：</font>
						</p>
						<p>
								<font size="-0">typedef struct tagBITMAPINFO { /* bmi */</font>
						</p>
						<blockquote>
								<font size="-0">BITMAPINFOHEADER bmiHeader;</font>
								<br />
								<font size="-0">RGBQUAD bmiColors[1];</font>
								<br />
						</blockquote>
						<font size="-0">} BITMAPINFO;</font>
						<p> </p>
						<p>
								<font size="-0">其中：</font>
								<br />  </p>
						<table border="0" cellspacing="0" width="557">
								<tbody>
										<tr>
												<td width="22%">
														<blockquote>
																<font size="-0">
																		<p>bmiHeader</p>
																</font>
														</blockquote>
												</td>
												<td width="78%">
														<blockquote>
																<font size="-0">
																		<p>说明BITMAPINFOHEADER结构，其中包含了有关位图的尺寸及位格式等信息</p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="22%">
														<blockquote>
																<font size="-0">
																		<p>bmiColors</p>
																</font>
														</blockquote>
												</td>
												<td width="78%">
														<blockquote>
																<font size="-0">
																		<p>说明彩色表RGBQUAD结构的阵列，其中包含索引图像的真实RGB值。</p>
																</font>
														</blockquote>
												</td>
										</tr>
								</tbody>
						</table>
						<p>
								<font size="-0">BITMAPINFOHEADER结构包含有位图文件的大小、压缩类型和颜色格式，其结构定义为：</font>
						</p>
						<p>
								<font size="-0">typedef struct tagBITMAPINFOHEADER { /* bmih */</font>
						</p>
						<blockquote>
								<font size="-0">DWORD biSize;</font>
								<br />
								<font size="-0">LONG biWidth;</font>
								<br />
								<font size="-0">LONG biHeight;</font>
								<br />
								<font size="-0">WORD biPlanes;</font>
								<br />
								<font size="-0">WORD biBitCount;</font>
								<br />
								<font size="-0">DWORD biCompression;</font>
								<br />
								<font size="-0">DWORD biSizeImage;</font>
								<br />
								<font size="-0">LONG biXPelsPerMeter;</font>
								<br />
								<font size="-0">LONG biYPelsPerMeter;</font>
								<br />
								<font size="-0">DWORD biClrUsed;</font>
								<br />
								<font size="-0">DWORD biClrImportant;</font>
								<br />
						</blockquote>
						<font size="-0">} BITMAPINFOHEADER;</font>
						<p> </p>
						<p>
								<font size="-0">其中：</font>
								<br />  </p>
						<table border="0" cellspacing="0" width="565">
								<tbody>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biSize</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<blockquote>
																<font size="-0">
																		<p>说
明BITMAPINFOHEADER结构所需要的字数。注：这个值并不一定是BITMAPINFOHEADER结构的尺寸，它也可能是sizeof
(BITMAPV4HEADER)的值，或是sizeof(BITMAPV5HEADER)的值。这要根据该位图文件的格式版本来决定，不过，就现在的情
况来看，绝大多数的BMP图像都是BITMAPINFOHEADER结构的（可能是后两者太新的缘故吧:-）。</p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biWidth</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<blockquote>
																<font size="-0">
																		<p>说明图象的宽度，以象素为单位</p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biHeight</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<blockquote>
																<font size="-0">
																		<p>说
明图象的高度，以象素为单位。注：这个值除了用于描述图像的高度之外，它还有另一个用处，就是指明该图像是倒向的位图，还是正向的位图。如果该值是一个正
数，说明图像是倒向的，如果该值是一个负数，则说明图像是正向的。大多数的BMP文件都是倒向的位图，也就是时，高度值是一个正数。（注：当高度值是一个
负数时（正向图像），图像将不能被压缩（也就是说biCompression成员将不能是BI_RLE8或BI_RLE4）。</p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biPlanes</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<blockquote>
																<font size="-0">
																		<p>为目标设备说明位面数，其值将总是被设为1</p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biBitCount</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<blockquote>
																<font size="-0">
																		<p>说明比特数/象素，其值为1、4、8、16、24、或32</p>
																</font>
														</blockquote>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biCompression</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<font size="-0">说明图象数据压缩的类型。其值可以是下述值之一：</font>
														<br />
														<!--msthemelist-->
														<table border="0" cellpadding="0" cellspacing="0" width="100%">
																<!--msthemelist-->
																<tbody>
																		<tr>
																				<td valign="baseline" width="42">
																						<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
																				</td>
																				<td valign="top" width="100%">BI_RGB：没有压缩； <br /><!--msthemelist--></td>
																		</tr>
																		<!--msthemelist-->
																		<tr>
																				<td valign="baseline" width="42">
																						<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
																				</td>
																				<td valign="top" width="100%">BI_RLE8：每个象素8比特的RLE压缩编码，压缩格式由2字节组成(重复象素计数和颜色索引)； <br /><!--msthemelist--></td>
																		</tr>
																		<!--msthemelist-->
																		<tr>
																				<td valign="baseline" width="42">
																						<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
																				</td>
																				<td valign="top" width="100%">BI_RLE4：每个象素4比特的RLE压缩编码，压缩格式由2字节组成 <br /><!--msthemelist--></td>
																		</tr>
																		<!--msthemelist-->
																		<tr>
																				<td valign="baseline" width="42">
																						<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
																				</td>
																				<td valign="top" width="100%">BI_BITFIELDS：每个象素的比特由指定的掩码决定。<br /><!--msthemelist--></td>
																		</tr>
																		<!--msthemelist-->
																</tbody>
														</table>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biSizeImage</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<font size="-0">说明图象的大小，以字节为单位。当用BI_RGB格式时，可设置为0</font>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biXPelsPerMeter</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<font size="-0">说明水平分辨率，用象素/米表示</font>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biYPelsPerMeter</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<font size="-0">说明垂直分辨率，用象素/米表示</font>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biClrUsed</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<font size="-0">说明位图实际使用的彩色表中的颜色索引数（设为0的话，则说明使用所有调色板项）</font>
												</td>
										</tr>
										<tr>
												<td width="147">
														<blockquote>
																<font size="-0">
																		<p>biClrImportant</p>
																</font>
														</blockquote>
												</td>
												<td width="414">
														<blockquote>
																<font size="-0">
																		<p>说明对图象显示有重要影响的颜色索引的数目，如果是0，表示都重要。</p>
																</font>
														</blockquote>
												</td>
										</tr>
								</tbody>
						</table>
						<p>
								<font size="-0">现就BITMAPINFOHEADER结构作如下说明：</font>
						</p>
						<p>
								<strong>
										<font size="-0">(1) 彩色表的定位</font>
								</strong>
						</p>
						<p>
								<font size="-0">应用程序可使用存储在biSize成员中的信息来查找在BITMAPINFO结构中的彩色表，如下所示：</font>
						</p>
						<p>
								<font size="-0">pColor = ((LPSTR) pBitmapInfo + (WORD) (pBitmapInfo-&gt;bmiHeader.biSize))</font>
						</p>
						<p>
								<strong>
										<font size="-0">(2) biBitCount</font>
								</strong>
						</p>
						<p>
								<font size="-0">
										<strong>biBitCount=1 </strong>表示位图最多有两种颜色，缺省情况下是黑色和白色，你也可以自己定义这两种颜色。图像信息头装调色板中将有两个调色板项，称为索引0和索引1。图象数据阵列中的每一位表示一个象素。如果一个位是0，显示时就使用索引0的RGB值，如果位是1，则使用索引1的RGB值。</font>
						</p>
						<p>
								<font size="-0">
										<strong>biBitCount=4 </strong>表
示位图最多有16种颜色。每个象素用4位表示，并用这4位作为彩色表的表项来查找该象素的颜色。例如，如果位图中的第一个字节为0x1F，它表示有两个象
素，第一象素的颜色就在彩色表的第2表项中查找，而第二个象素的颜色就在彩色表的第16表项中查找。此时，调色板中缺省情况下会有16个RGB项。对应于
索引0到索引15。</font>
						</p>
						<p>
								<font size="-0">
										<strong>biBitCount=8 </strong>表示位图最多有256种颜色。每个象素用8位表示，并用这8位作为彩色表的表项来查找该象素的颜色。例如，如果位图中的第一个字节为0x1F，这个象素的颜色就在彩色表的第32表项中查找。此时，缺省情况下，调色板中会有256个RGB项，对应于索引0到索引255。</font>
						</p>
						<p>
								<font size="-0">
										<strong>biBitCount=16 </strong>表示位图最多有2<sup>16</sup>种
颜色。每个色素用16位（2个字节）表示。这种格式叫作高彩色，或叫增强型16位色，或64K色。它的情况比较复杂，当biCompression成员的
值是BI_RGB时，它没有调色板。16位中，最低的5位表示蓝色分量，中间的5位表示绿色分量，高的5位表示红色分量，一共占用了15位，最高的一位保
留，设为0。这种格式也被称作555
16位位图。如果biCompression成员的值是BI_BITFIELDS，那么情况就复杂了，首先是原来调色板的位置被三个DWORD变量占据，
称为红、绿、蓝掩码。分别用于描述红、绿、蓝分量在16位中所占的位置。在Windows
95（或98）中，系统可接受两种格式的位域：555和565，在555格式下，红、绿、蓝的掩码分别是：0x7C00、0x03E0、0x001F，而
在565格式下，它们则分别为：0xF800、0x07E0、0x001F。你在读取一个像素之后，可以分别用掩码“与”上像素值，从而提取出想要的颜色
分量（当然还要再经过适当的左右移操作）。在NT系统中，则没有格式限制，只不过要求掩码之间不能有重叠。（注：这种格式的图像使用起来是比较麻烦的，不
过因为它的显示效果接近于真彩，而图像数据又比真彩图像小的多，所以，它更多的被用于游戏软件）。</font>
						</p>
						<p>
								<font size="-0">
										<strong>biBitCount=24 </strong>表示位图最多有2<sup>24</sup>种颜色。这种位图没有调色板（bmiColors成员尺寸为0），在位数组中，每3个字节代表一个象素，分别对应于颜色R、G、B。</font>
						</p>
						<p>
								<font size="-0">
										<strong>biBitCount=32 </strong>表示位图最多有2<sup>32</sup>种
颜色。这种位图的结构与16位位图结构非常类似，当biCompression成员的值是BI_RGB时，它也没有调色板，32位中有24位用于存放
RGB值，顺序是：最高位—保留，红8位、绿8位、蓝8位。这种格式也被成为888 32位图。如果
biCompression成员的值是BI_BITFIELDS时，原来调色板的位置将被三个DWORD变量占据，成为红、绿、蓝掩码，分别用于描述红、
绿、蓝分量在32位中所占的位置。在Windows 95(or
98)中，系统只接受888格式，也就是说三个掩码的值将只能是：0xFF0000、0xFF00、0xFF。而在NT系统中，你只要注意使掩码之间不产
生重叠就行。（注：这种图像格式比较规整，因为它是DWORD对齐的，所以在内存中进行图像处理时可进行汇编级的代码优化（简单））。</font>
						</p>
						<p>
								<strong>
										<font size="-0">(3) ClrUsed</font>
								</strong>
						</p>
						<p>
								<font size="-0">BITMAPINFOHEADER
结构中的成员ClrUsed指定实际使用的颜色数目。如果ClrUsed设置成0，位图使用的颜色数目就等于biBitCount成员中的数目。请注意，
如果ClrUsed的值不是可用颜色的最大值或不是0，则在编程时应该注意调色板尺寸的计算，比如在4位位图中，调色板的缺省尺寸应该是
16＊sizeof(RGBQUAD)，但是，如果ClrUsed的值不是16或者不是0，那么调色板的尺寸就应该是ClrUsed＊sizeof
(RGBQUAD)。</font>
						</p>
						<p>
								<strong>
										<font size="-0">(4) 图象数据压缩</font>
								</strong>
						</p>
						<p>
								<font size="-0">
										<strong>① BI_RLE8：</strong>每个象素为8比特的RLE压缩编码，可使用编码方式和绝对方式中的任何一种进行压缩，这两种方式可在同一幅图中的任何地方使用。</font>
						</p>
						<p>
								<font size="-0">
										<strong>编码方式</strong>：由2个字节组成，第一个字节指定使用相同颜色的象素数目，第二个字节指定使用的颜色索引。此外，这个字节对中的第一个字节可设置为0，联合使用第二个字节的值表示：</font>
								<br />
						</p>
						<!--msthemelist-->
						<table border="0" cellpadding="0" cellspacing="0" width="100%">
								<!--msthemelist-->
								<tbody>
										<tr>
												<td valign="baseline" width="42">
														<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
												</td>
												<td valign="top" width="100%">第二个字节的值为0：行的结束。 <br /><!--msthemelist--></td>
										</tr>
										<!--msthemelist-->
										<tr>
												<td valign="baseline" width="42">
														<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
												</td>
												<td valign="top" width="100%">第二个字节的值为1：图象结束。 <br /><!--msthemelist--></td>
										</tr>
										<!--msthemelist-->
										<tr>
												<td valign="baseline" width="42">
														<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
												</td>
												<td valign="top" width="100%">第二个字节的值为2：其后的两个字节表示下一个象素从当前开始的水平和垂直位置的偏移量。 <br /><!--msthemelist--></td>
										</tr>
										<!--msthemelist-->
								</tbody>
						</table>
						<p>
								<font size="-0">
										<strong>绝对方式</strong>：
第一个字节设置为0，而第二个字节设置为0x03～0xFF之间的一个值。在这种方式中，第二个字节表示跟在这个字节后面的字节数，每个字节包含单个象素
的颜色索引。压缩数据格式需要字边界(word boundary)对齐。下面的例子是用16进制表示的8-位压缩图象数据：</font>
						</p>
						<p align="center">
								<font size="-0">03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01 02 78 00 00 09 1E 00 01</font>
								<br />
								<font size="-0">这些压缩数据可解释为 ：</font>
						</p>
						<div align="center">
								<center>
										<table style="margin-left: auto; margin-right: auto;" bordercolordark="#000000" bordercolorlight="#cc6600" border="1" cellspacing="2" width="443">
												<tbody>
														<tr>
																<td width="143">
																		<p align="center">
																				<font size="-0">压缩数据 </font>
																		</p>
																</td>
																<td width="288">
																		<p align="center">
																				<font size="-0">扩展数据</font>
																		</p>
																</td>
														</tr>
														<tr>
																<td width="143">
																		<font size="-0">03 04</font>
																</td>
																<td width="288">
																		<font size="-0">04 04 04 </font>
																</td>
														</tr>
														<tr>
																<td width="143">
																		<font size="-0">05 06</font>
																</td>
																<td width="288">
																		<font size="-0">06 06 06 06 06 </font>
																</td>
														</tr>
														<tr>
																<td width="143">
																		<font size="-0">00 03 45 56 67 00</font>
																</td>
																<td width="288">
																		<font size="-0">45 56 67 </font>
																</td>
														</tr>
														<tr>
																<td width="143">
																		<font size="-0">02 78</font>
																</td>
																<td width="288">
																		<font size="-0">78 78 </font>
																</td>
														</tr>
														<tr>
																<td width="143">
																		<font size="-0">00 02 05 01</font>
																</td>
																<td width="288">
																		<font size="-0">从当前位置右移5个位置后向下移一行</font>
																</td>
														</tr>
														<tr>
																<td width="143">
																		<font size="-0">02 78</font>
																</td>
																<td width="288">
																		<font size="-0">78 78 </font>
																</td>
														</tr>
														<tr>
																<td width="143">
																		<font size="-0">00 00</font>
																</td>
																<td width="288">
																		<font size="-0">行结束</font>
																</td>
														</tr>
														<tr>
																<td width="143">
																		<font size="-0">09 1E</font>
																</td>
																<td width="288">
																		<font size="-0">1E 1E 1E 1E 1E 1E 1E 1E 1E </font>
																</td>
														</tr>
														<tr>
																<td width="143">
																		<font size="-0">00 01</font>
																</td>
																<td width="288">
																		<font size="-0">RLE编码图象结束 </font>
																</td>
														</tr>
												</tbody>
										</table>
								</center>
						</div>
						<strong>
								<p>
										<font size="3">② BI_RLE4：</font>
								</p>
								<p>
										<font size="3">编码方式：由2个字节组成，第一个字节指定象素数目，第二个字节包含两种颜色索引，一个在高4位，另一个在低4位。第一个象素使用高4位的颜色索引，第二个使用低4位的颜色索引，第3个使用高4位的颜色索引，依此类推。</font>
								</p>
								<p>
										<font size="-0">绝对方式：这个字节对中的第一个字节设置为0，第二个字节包含有颜色索引数，其后续字节包含有颜色索引，颜色索引存放在该字节的高、低4位中，一个颜色索引对应一个象素。此外，BI_RLE4也同样联合使用第二个字节中的值表示：</font>
										<br />
								</p>
								<!--msthemelist-->
								<table border="0" cellpadding="0" cellspacing="0" width="100%">
										<!--msthemelist-->
										<tbody>
												<tr>
														<td valign="baseline" width="42">
																<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
														</td>
														<td valign="top" width="100%">第二个字节的值为0：行的结束。 <br /><!--msthemelist--></td>
												</tr>
												<!--msthemelist-->
												<tr>
														<td valign="baseline" width="42">
																<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
														</td>
														<td valign="top" width="100%">第二个字节的值为1：图象结束。 <br /><!--msthemelist--></td>
												</tr>
												<!--msthemelist-->
												<tr>
														<td valign="baseline" width="42">
																<img src="http://asp.6to23.com/iseesoft/devdoc/imgdoc/urbbul1a.gif" alt="" height="20" hspace="11" width="20" />
														</td>
														<td valign="top" width="100%">第二个字节的值为2：其后的两个字节表示下一个象素从当前开始的水平和垂直位置的偏移量。 <br /><!--msthemelist--></td>
												</tr>
												<!--msthemelist-->
										</tbody>
								</table>
								<p>
										<font size="-0">下面的例子是用16进制数表示的4-位压缩图象数据：</font>
								</p>
								<p>
										<font size="-0">03 04 05 06 00 06 45 56 67 00 04 78 00 02 05 01 04 78 00 00 09 1E 00 01</font>
								</p>
								<p align="center">
										<font size="-0">这些压缩数据可解释为 ：</font>
								</p>
								<div align="center">
										<center>
												<table style="margin-left: auto; margin-right: auto;" bordercolordark="#000000" bordercolorlight="#cc6600" border="1" cellspacing="2" width="417">
														<tbody>
																<tr>
																		<td width="141">
																				<p align="center">
																						<font size="-0">压缩数据</font>
																				</p>
																		</td>
																		<td width="264">
																				<p align="center">
																						<font size="-0">扩展数据</font>
																				</p>
																		</td>
																</tr>
																<tr>
																		<td width="141">
																				<font size="-0">03 04</font>
																		</td>
																		<td width="264">
																				<font size="-0">0 4 0</font>
																		</td>
																</tr>
																<tr>
																		<td width="141">
																				<font size="-0">05 06</font>
																		</td>
																		<td width="264">
																				<font size="-0">0 6 0 6 0 </font>
																		</td>
																</tr>
																<tr>
																		<td width="141">
																				<font size="-0">00 06 45 56 67 00</font>
																		</td>
																		<td width="264">
																				<font size="-0">4 5 5 6 6 7 </font>
																		</td>
																</tr>
																<tr>
																		<td width="141">
																				<font size="-0">04 78</font>
																		</td>
																		<td width="264">
																				<font size="-0">7 8 7 8 </font>
																		</td>
																</tr>
																<tr>
																		<td width="141">
																				<font size="-0">00 02 05 01</font>
																		</td>
																		<td width="264">
																				<font size="-0">从当前位置右移5个位置后向下移一行</font>
																		</td>
																</tr>
																<tr>
																		<td width="141">
																				<font size="-0">04 78</font>
																		</td>
																		<td width="264">
																				<font size="-0">7 8 7 8 </font>
																		</td>
																</tr>
																<tr>
																		<td width="141">
																				<font size="-0">00 00</font>
																		</td>
																		<td width="264">
																				<font size="-0">行结束</font>
																		</td>
																</tr>
																<tr>
																		<td width="141">
																				<font size="-0">09 1E</font>
																		</td>
																		<td width="264">
																				<font size="-0">1 E 1 E 1 E 1 E 1 </font>
																		</td>
																</tr>
																<tr>
																		<td width="141">
																				<font size="-0">00 01</font>
																		</td>
																		<td width="264">
																				<font size="-0">RLE图象结束 </font>
																		</td>
																</tr>
														</tbody>
												</table>
										</center>
								</div>
								<font color="#7f007f">
										<strong>
												<p>
														<font size="3">3. 彩色表</font>
												</p>
												<p>
														<font size="3">彩
色表包含的元素与位图所具有的颜色数相同，象素的颜色用RGBQUAD结构来定义。对于24-位真彩色图象就不使用彩色表（同样也包括16位、和32位位
图），因为位图中的RGB值就代表了每个象素的颜色。彩色表中的颜色按颜色的重要性排序，这可以辅助显示驱动程序为不能显示足够多颜色数的显示设备显示彩
色图象。RGBQUAD结构描述由R、G、B相对强度组成的颜色，定义如下：</font>
												</p>
												<p>
														<font size="-0">typedef struct tagRGBQUAD { /* rgbq */</font>
												</p>
												<blockquote>
														<font size="-0">BYTE rgbBlue;</font>
														<br />
														<font size="-0">BYTE rgbGreen;</font>
														<br />
														<font size="-0">BYTE rgbRed;</font>
														<br />
														<font size="-0">BYTE rgbReserved;</font>
														<br />
												</blockquote>
												<font size="-0">} RGBQUAD;</font>
												<p> </p>
												<p>
														<font size="-0">其中：</font>
														<br />  </p>
												<table border="0" cellspacing="0" width="557">
														<tbody>
																<tr>
																		<td width="22%">
																				<blockquote>
																						<font size="-0">
																								<p>rgbBlue</p>
																						</font>
																				</blockquote>
																		</td>
																		<td width="78%">
																				<blockquote>
																						<font size="-0">
																								<p>指定蓝色强度</p>
																						</font>
																				</blockquote>
																		</td>
																</tr>
																<tr>
																		<td width="22%">
																				<blockquote>
																						<font size="-0">
																								<p>rgbGreen</p>
																						</font>
																				</blockquote>
																		</td>
																		<td width="78%">
																				<blockquote>
																						<font size="-0">
																								<p>指定绿色强度</p>
																						</font>
																				</blockquote>
																		</td>
																</tr>
																<tr>
																		<td width="22%">
																				<blockquote>
																						<font size="-0">
																								<p>rgbRed</p>
																						</font>
																				</blockquote>
																		</td>
																		<td width="78%">
																				<blockquote>
																						<font size="-0">
																								<p>指定红色强度</p>
																						</font>
																				</blockquote>
																		</td>
																</tr>
																<tr>
																		<td width="22%">
																				<blockquote>
																						<font size="-0">
																								<p>rgbReserved</p>
																						</font>
																				</blockquote>
																		</td>
																		<td width="78%">
																				<blockquote>
																						<font size="-0">
																								<p>保留，设置为0</p>
																						</font>
																				</blockquote>
																		</td>
																</tr>
														</tbody>
												</table>
												<p>
														<font color="#7f007f" size="-0">
																<strong>4. 位图数据</strong>
														</font>
												</p>
												<p align="center">
														<font size="-0">紧
跟在彩色表之后的是图象数据字节阵列。图象的每一扫描行由表示图象象素的连续的字节组成，每一行的字节数取决于图象的颜色数目和用象素表示的图象宽度。扫
描行是由底向上存储的，这就是说，阵列中的第一个字节表示位图左下角的象素，而最后一个字节表示位图右上角的象素。（只针对与倒向DIB，如果是正向
DIB，则扫描行是由顶向下存储的），倒向DIB的原点在图像的左下角，而正向DIB的原点在图像的左上角。同时，每一扫描行的字节数必需是4的整倍数，
也就是DWORD对齐的。如果你想确保图像的扫描行DWORD对齐，可使用下面的代码：<br /><br />(((width*biBitCount)+31)&gt;&gt;5)&lt;&lt;2<br /><br /></font>
												</p>
												<p>
														<font color="#7f007f" size="-0">
																<strong>5. 参考书目</strong>
														</font>
												</p>
												<p align="left">
														<font size="-0">《图象文件格式(上、下)—Windows编程》<br />《图像文件格式大全》<br />《Programming Windows by Charles Petzold》<br /></font>
												</p>
												<p>
														<font color="#7f007f" size="-0">
																<strong>6. 相关站点</strong>
														</font>
												</p>
												<p align="left">
														<font size="-0">各种格式：http://www.wotsit.org/<br />各种格式：http://www.csdn.net/<br />位图格式：http://www.cica.indiana.edu/graphics/image_specs/bmp.format.txt<br /><br />〈完〉<br />YZ 2000-8-13 13:11<br /></font>
												</p> </strong>
								</font>
								<font size="3">
								</font>
						</strong>
						<font size="3">每个象素为4比特的RLE压缩编码，同样也可使用编码方式和绝对方式中的任何一种进行压缩，这两种方式也可在同一幅图中的任何地方使用。这两种方式是： </font>
				</strong>
		</font>
<img src ="http://www.blogjava.net/jdo/aggbug/146989.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-09-21 10:09 <a href="http://www.blogjava.net/jdo/articles/146989.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DOMtab的基本使用方法以及下载地址和完整演示</title><link>http://www.blogjava.net/jdo/articles/140690.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Tue, 28 Aug 2007 14:45:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/140690.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/140690.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/140690.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/140690.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/140690.html</trackback:ping><description><![CDATA[
		<div class="entry">
				<p>
						<strong>一.什么是DOMtab</strong>
						<br />
DOMtab是一个用javascipt制作的通用可扩展的tab切换显示隐藏内容快的web控件。</p>
				<p>
						<strong>二.怎么使用DOMtab</strong>
						<br />
1.在页面的
</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;head&gt;&lt;/head&gt;</li>
						</ol>
				</div>
				<p>区域加上</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;script type="text/javascript" src="domtab.js"&gt;&lt;/script&gt;</li>
						</ol>
				</div>
				<p>2.在页面主体的
</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;body&gt;&lt;/body&gt;</li>
						</ol>
				</div>
				<p>部分加上</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;div class="domtab"&gt;</li>
								<li> &lt;ul class="domtabs"&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t1"&gt;Test 1&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t2"&gt;Test 2&lt;/a&gt;&lt;/li&gt; [idea] [idea] </li>
								<li>[... and so on ...]</li>
								<li> &lt;/ul&gt;</li>
								<li> &lt;div&gt;</li>
								<li> &lt;h2&gt;&lt;a name="t1" id="t1"&gt;Proof 1&lt;/a&gt;&lt;/h2&gt;</li>
								<li> &lt;p&gt;Test to prove that more than one menu is possible&lt;/p&gt;</li>
								<li> &lt;p&gt;&lt;a href="#top"&gt;back to menu&lt;/a&gt;&lt;/p&gt;</li>
								<li> &lt;/div&gt;</li>
								<li> &lt;div&gt;</li>
								<li> &lt;h2&gt;&lt;a name="t2" id="t2"&gt;Proof 2&lt;/a&gt;&lt;/h2&gt;</li>
								<li> &lt;p&gt;Test to prove that more than one menu is possible&lt;/p&gt;</li>
								<li> &lt;p&gt;&lt;a href="#top"&gt;back to menu&lt;/a&gt;&lt;/p&gt;</li>
								<li> &lt;/div&gt;</li>
								<li>[... and so on ...]</li>
								<li>&lt;/div&gt;</li>
						</ol>
				</div>
				<p>
						<br />
然后定义各个class的样式就可以了，你也可以加class定义样式，但是代码的结构不能变化<br />
3.更改javascript中控件的属性<br />
tabClass:’domtab’, //目标区域的class名称<br />
listClass:’domtabs’, // 列表菜单的class名称<br />
activeClass:’active’, // 菜单激活状态下的class名称<br />
contentElements:’div’, // 循环内容区域的元素名称<br />
backToLinks:/#top/, // 设置返回顶部的参数<br />
printID:’domtabprintview’, // 显示所有区域内容的id名称<br />
showAllLinkText:’show all content’, // 显示所有区域的文字名称</p>
				<p>
						<strong>三.增加向前向后按钮</strong>
				</p>
				<p>1.在区域的起始class上多增加一个doprevnext</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;div class="domtab doprevnext"&gt;</li>
								<li> &lt;ul class="domtabs"&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t1"&gt;Test 1&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t2"&gt;Test 2&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t3"&gt;Test 3&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li&gt;&lt;a href="#t4"&gt;Test 4&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;/ul&gt;</li>
								<li> [... ad nauseam...]</li>
								<li>&lt;/div&gt;</li>
						</ol>
				</div>
				<p>2.在页面里面加上下列代码</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;ul class="prevnext"&gt;</li>
								<li> &lt;li class="prev"&gt;&lt;a href="#"&gt;previous&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;li class="next"&gt;&lt;a href="#"&gt;next&lt;/a&gt;&lt;/li&gt;</li>
								<li> &lt;/ul&gt;</li>
						</ol>
				</div>
				<p>3.javascript里面的属性定义</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">prevNextIndicator:'doprevnext', // 目标容器的class名称</li>
								<li>prevNextClass:'prevnext', // class名称</li>
								<li>prevLabel:'previous', // 上一页的文字</li>
								<li>nextLabel:'next', // 下一页的文字</li>
								<li>prevClass:'prev', // 上一页的class</li>
								<li>nextClass:'next', // 下一页的class</li>
						</ol>
				</div>
				<p>
						<strong>四.DOMtab中的样式控制</strong>
						<br />
你可以强制的控制某一个元素的样式譬如显示和隐藏等等</p>
				<div class="hl-surround">
						<ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)">
								<li class="hl-firstline">&lt;script type="text/javascript"&gt;</li>
								<li> document.write('&lt;style type="text/css"&gt;'); </li>
								<li> document.write('div.domtab div{display:none;}&lt;');</li>
								<li> document.write('/s'+'tyle&gt;'); </li>
								<li>&lt;/script&gt;</li>
						</ol>
				</div>
				<p>
						<strong>五.下载以及演示</strong>
						<br />
						<a href="http://onlinetools.org/tools/domtabdata/domtab.zip" title="http://onlinetools.org/tools/domtabdata/domtab.zip" target="_blank">下载DOMtab version 3.1415927</a>
						<br />
						<a href="http://onlinetools.org/tools/domtabdata/" title="http://onlinetools.org/tools/domtabdata/" target="_blank">DOMtab演示</a>
				</p>
		</div>
<img src ="http://www.blogjava.net/jdo/aggbug/140690.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-28 22:45 <a href="http://www.blogjava.net/jdo/articles/140690.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用DIV+Javascript实现标签功能</title><link>http://www.blogjava.net/jdo/articles/140411.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Tue, 28 Aug 2007 04:47:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/140411.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/140411.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/140411.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/140411.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/140411.html</trackback:ping><description><![CDATA[
		<div>
				<div class="code_title">　　现在很多网站都用到了标签的切换功能，新浪、迅雷等网站都有，应该说用很很泛滥了。其实
标签功能是Windows程序中的一种功能，在Delphi或VB等Windows程序开的环境中，很容易就能创建各种漂亮而又功能强大的标签功能，但在
Web开发中，就没有这种便利了。</div>
		</div>
		<div>　　只需要销加改动，标签的数量可以自由添加，而无需要为标签添加ID，实际上这个功能除了用到Div、Javascript之后，很重要的是要用到CSS样式。</div>
		<div> </div>
		<div align="center">
				<img alt="" src="http://www.conis.cn/UPLOAD/Lesson/Web/Lesson1/001.gif" />
		</div>
		<div align="center"> </div>
		<div align="center">图1</div>
		<div align="left">
				<br />　
　首先我们要确定我们要做什么，我们要做成一个带三个标签的区域(图1)，点击标签标签列表的其中一个标签，内容区域会根据当前点击的标签显示不同的内
容。按照我们一般的做法是每一个标签对应一个内容区域，给每个内容区域增加一个id属性，然后为每一个标签添加一个属性，就像这样：</div>
		<div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="label1"</span><span style="color: rgb(255, 0, 0);"> onmousemove</span><span style="color: rgb(0, 0, 255);">="dosomething()"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">label1</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="label2"</span><span style="color: rgb(255, 0, 0);"> onmousemove</span><span style="color: rgb(0, 0, 255);">="dosomething()"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">label2</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="label2"</span><span style="color: rgb(255, 0, 0);"> onmousemove</span><span style="color: rgb(0, 0, 255);">="dosomething()"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">label2</span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="content1"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">第一个label的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="content2"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">第一个labe2的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="content2"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">第一个labe2的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">     <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">  </span></div></div></div>
		<div>    
你可能没有意识到这种办法会有什么问题，当一个页面有非常多的标签块的话，我们将不得不面临一个问题，那就是id的命名问题，我们将要为每一个内容区域命
名，这样不仅增加了代码量，也增加了javascript编写的难度，我们不可能为每一个标签块写一堆javascript，就算我将
javascript写成一个函数或者一个类，我们也会而临另一个问题，就是调用的时候会有一大堆的参数，因为你需要将这个id传送过去。并且，很容易因
为人为的疏忽造成错误。</div>
		<div>　　下面，来看看我是如何实现这个功能的吧，可能不是最好的方法，如果你有更好的方法，希望你能告诉我，让我们一起进步。</div>
		<div>    　首先，我们要做的是写好基本的html代码，代码如下：</div>
		<div>
				<div class="code_title">
						<div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">meta </span><span style="color: rgb(255, 0, 0);">http-equiv</span><span style="color: rgb(0, 0, 255);">="Content-Type"</span><span style="color: rgb(255, 0, 0);"> content</span><span style="color: rgb(0, 0, 255);">="text/html; charset=gb2312"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">head</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />     <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ul </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="Label"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);">我们将第一个标签的背景色设置红色，因为默认显示的是第一个标签的内容</span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">li </span><span style="color: rgb(255, 0, 0);">class</span><span style="color: rgb(0, 0, 255);">="CurrentLabel"</span><span style="color: rgb(255, 0, 0);"> style</span><span style="color: rgb(0, 0, 255);">="background-color: red"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">标签1</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">标签2</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">标签3</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">li</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">ul</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="Container"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">这时里是标签1对应的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />    </span><span style="color: rgb(0, 128, 0);">&lt;!--</span><span style="color: rgb(0, 128, 0);">因为默认是不显示的，所以要将display属性设置为none</span><span style="color: rgb(0, 128, 0);">--&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">="display: none"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">这时里是标签2对应的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">div </span><span style="color: rgb(255, 0, 0);">style</span><span style="color: rgb(0, 0, 255);">="display: none"</span><span style="color: rgb(255, 0, 0);"> class</span><span style="color: rgb(0, 0, 255);">="Content3"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">这时里是标签3对应的内容</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">div</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">html</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span></div></div><span>   </span></div>
				</div>
		</div>
		<div>    写好基本html代码后，我们还需要做一项重要的工作，那就是css样式，因为li如果没有css样式控制，标签就会以列表的形式出现，基本的CSS样式代码如下：</div>
		<div>
				<div class="code_title"> </div>
				<div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(128, 0, 0);">&lt;style type="text/css"&gt;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /> #Label li    <br /><img id="_44_317_Open_Image" onclick="this.style.display='none'; document.getElementById('_44_317_Open_Text').style.display='none'; document.getElementById('_44_317_Closed_Image').style.display='inline'; document.getElementById('_44_317_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="_44_317_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_44_317_Closed_Text').style.display='none'; document.getElementById('_44_317_Open_Image').style.display='inline'; document.getElementById('_44_317_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top" /> </span><span id="_44_317_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">{...}</span><span id="_44_317_Open_Text"><span style="color: rgb(0, 0, 0);">{</span><span style="color: rgb(255, 0, 0);">    <br /><img id="_52_153_Open_Image" onclick="this.style.display='none'; document.getElementById('_52_153_Open_Text').style.display='none'; document.getElementById('_52_153_Closed_Image').style.display='inline'; document.getElementById('_52_153_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_52_153_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_52_153_Closed_Text').style.display='none'; document.getElementById('_52_153_Open_Image').style.display='inline'; document.getElementById('_52_153_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span id="_52_153_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">/**/</span><span id="_52_153_Open_Text"><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);">设置ID为Label的元素下所有li元素样式，主要是要设置float:left这个属性，这样才能将li元素排成一排；同时设置了list-style:none这个属性，目的是防止li元素出现实心圆点</span><span style="color: rgb(0, 128, 0);">*/</span></span><span style="color: rgb(255, 0, 0);">   <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  margin-left</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);"> 1px</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  padding</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);"> 3px</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  width</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);"> 40px</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  background-color</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">#94A5F8</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  float</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">left</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  list-style</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">none</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  cursor</span><span style="color: rgb(0, 0, 0);">:</span><span style="color: rgb(0, 0, 255);">pointer</span><span style="color: rgb(0, 0, 0);">;</span><span style="color: rgb(255, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> </span><span style="color: rgb(0, 0, 0);">}</span></span><span style="color: rgb(128, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" />&lt;/style&gt;    </span></div></div><span>   </span></div>
		</div>
		<div>　
　下面，我们将要进行最重要的一环了，就是javascript，看到你里，你可能会问，为什么标签li元素没有事件呢？如何实现标签的切换呢，这是因为
我考虑了另一个问题，如果我们需要为每一个标签添加一个事件的话，确实是一件很麻烦的事情，而且当标签块多了的时候，就会增加代码量，所以我考虑使用动态
添加属性的方式为每一个标签添加属性。<div class="code_title"> <div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> LabelAddEvent()    <br /><img id="_30_630_Open_Image" onclick="this.style.display='none'; document.getElementById('_30_630_Open_Text').style.display='none'; document.getElementById('_30_630_Closed_Image').style.display='inline'; document.getElementById('_30_630_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="_30_630_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_30_630_Closed_Text').style.display='none'; document.getElementById('_30_630_Open_Image').style.display='inline'; document.getElementById('_30_630_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top" /> </span><span id="_30_630_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_30_630_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> labels </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Label</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).childNodes;        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取ID为Label无素下的所有子节点，childNodes是DOM的一个属性    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">对所有子节点进行循环，增加onmouseover事件，也可以根据需要添加onclick事件    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> iLoop </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; iLoop </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> labels.length; iLoop </span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">)    <br /><img id="_263_623_Open_Image" onclick="this.style.display='none'; document.getElementById('_263_623_Open_Text').style.display='none'; document.getElementById('_263_623_Closed_Image').style.display='inline'; document.getElementById('_263_623_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_263_623_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_263_623_Closed_Text').style.display='none'; document.getElementById('_263_623_Open_Image').style.display='inline'; document.getElementById('_263_623_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span id="_263_623_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_263_623_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> label </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> labels[iLoop];    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">LI</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> label.nodeName)   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">只处理LI的DOM节点，目的是为了兼容Firefox，因为Firefox会把空格与换行与当成一个节点处理    </span><span style="color: rgb(0, 128, 0);"><br /><img id="_398_615_Open_Image" onclick="this.style.display='none'; document.getElementById('_398_615_Open_Text').style.display='none'; document.getElementById('_398_615_Closed_Image').style.display='inline'; document.getElementById('_398_615_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_398_615_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_398_615_Closed_Text').style.display='none'; document.getElementById('_398_615_Open_Image').style.display='inline'; document.getElementById('_398_615_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">   </span><span id="_398_615_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_398_615_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />    label.value </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> iLoop;        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">为每一个标签的value赋上当前的索引，当点击标签的时候不用循环标签就知道是哪一个标签了    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">    label.onmouseover </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">()    <br /><img id="_530_605_Open_Image" onclick="this.style.display='none'; document.getElementById('_530_605_Open_Text').style.display='none'; document.getElementById('_530_605_Closed_Image').style.display='inline'; document.getElementById('_530_605_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_530_605_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_530_605_Closed_Text').style.display='none'; document.getElementById('_530_605_Open_Image').style.display='inline'; document.getElementById('_530_605_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span><span id="_530_605_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_530_605_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />     ChangeLabel(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">);          </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">调用ChangeLabel函数，并把当前对象传过去    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">    }</span></span><span style="color: rgb(0, 0, 0);">;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />   }</span></span><span style="color: rgb(0, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span></span><span style="color: rgb(0, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> }</span></span><span style="color: rgb(0, 0, 0);">    </span></div></div></div></div></div>
		<div>　　然后，我们在html页的最后面，调用LabelAddEvent这个函数，即可以为所有标签添加函数了，是不是很简洁，当我们有很多标签块的时候，就不必要为每个标签块添加事件了，下面我们来看看ChangeLabel这个函数：<br /> <div class="bar"> <div style="border: 0.5pt solid windowtext; padding: 4px 5.4pt; background: rgb(230, 230, 230) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 95%;"><div><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> ChangeLabel(oCur)    <br /><img id="_32_638_Open_Image" onclick="this.style.display='none'; document.getElementById('_32_638_Open_Text').style.display='none'; document.getElementById('_32_638_Closed_Image').style.display='inline'; document.getElementById('_32_638_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="_32_638_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_32_638_Closed_Text').style.display='none'; document.getElementById('_32_638_Open_Image').style.display='inline'; document.getElementById('_32_638_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" align="top" /> </span><span id="_32_638_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_32_638_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取所有的内容元素子节点    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> containers </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Container</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).childNodes;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />　</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取所有的标签    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">  </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> labels </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Label</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).childNodes;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />  </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> iLoop </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; iLoop </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> containers.length; iLoop </span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">)    <br /><img id="_274_631_Open_Image" onclick="this.style.display='none'; document.getElementById('_274_631_Open_Text').style.display='none'; document.getElementById('_274_631_Closed_Image').style.display='inline'; document.getElementById('_274_631_Closed_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="_274_631_Closed_Image" style="display: none;" onclick="this.style.display='none'; document.getElementById('_274_631_Closed_Text').style.display='none'; document.getElementById('_274_631_Open_Image').style.display='inline'; document.getElementById('_274_631_Open_Text').style.display='inline';" alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" align="top" />  </span><span id="_274_631_Closed_Text" style="border: 1px solid rgb(128, 128, 128); display: none; background-color: rgb(255, 255, 255);">...</span><span id="_274_631_Open_Text"><span style="color: rgb(0, 0, 0);">{    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> container </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> containers[iLoop];       <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> label </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> labels[iLoop];    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">根据索引是否为li元素的value值来判断是否为当前标签    </span><span style="color: rgb(0, 128, 0);"><br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" /></span><span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> current </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> iLoop </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> oCur.value;      <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">DIV</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> container.nodeName) container.style.display </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> current </span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">block</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">none</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" align="top" />   </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">LI</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);"> label.nodeName) label.style.backgroundColor </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> current </span><span style="color: rgb(0, 0, 0);">?</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">red</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> : </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">#94A5F8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />  }</span></span><span style="color: rgb(0, 0, 0);">    <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> }</span></span><span style="color: rgb(0, 0, 0);">  <br /><img alt="" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" align="top" /></span></div></div></div><p class="alt">　
　主要代码就是这么多了，是不是很简洁呢？当有很多个标签块的候，你就会发现这个方法的优势了，事实下，我们还可以简单修改一下javascript代
码，实现多个标签块在一个页面中的功能，接下来我准备结合Xml及Xslt写一个根据xml配置的多标签块的教程，如果你觉得有什么更好的方法可以实现，
请你与我联系，让我们共同进步。</p></div>
		<div>  <div style="border: 1px dotted rgb(102, 102, 102); padding: 10px; color: red; background-color: rgb(243, 243, 243);">  版权所有©Conis，复制或者转载请保留此信息，任何人未经许可，不得擅自将本文发布作为商业用途。<br />  更多内容更多精彩请您访问<a href="http://www.conis.cn/" target="_blank"><font color="#095c83">http://www.conis.cn</font></a></div></div>
<img src ="http://www.blogjava.net/jdo/aggbug/140411.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-28 12:47 <a href="http://www.blogjava.net/jdo/articles/140411.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>tomcat下中文的彻底解决</title><link>http://www.blogjava.net/jdo/articles/139346.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Sat, 25 Aug 2007 16:03:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/139346.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/139346.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/139346.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/139346.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/139346.html</trackback:ping><description><![CDATA[这些天开发一个项目，服务器是tomcat,操作系统是xp,采用的是MVC架构，模式是采用Facade模式，总是出现乱码，自己也解决了好多天，同事也帮忙解决，也参考了网上众多网友的文章和意见，总算是搞定。但是好记性不如烂笔杆，所以特意记下，以防止自己遗忘，同时也给那些遇到同样问题的人提供一个好的参考途径：<br />(一)    JSP页面上是中文，但是看的是后是乱码：<br />解决的办法就是在JSP页面的编码的地方&lt;%@ page language="java" contentType="text/html;charset=GBK" %&gt;，因为Jsp转成Java文件时的编码问题，默认的话有的服务器是ISO-8859-1，如果一个JSP中直接输入了中文，Jsp把它当作ISO8859-1来处理是肯定有问题的，这一点，我们可以通过查看Jasper所生成的Java中间文件来确认<br />(二)    当用Request对象获取客户提交的汉字代码的时候，会出现乱码：<br />解决的办法是：要配置一个filter,也就是一个Servelet的过滤器，代码如下：<br />import java.io.IOException;<br />import javax.servlet.Filter;<br />import javax.servlet.FilterChain;<br />import javax.servlet.FilterConfig;<br />import javax.servlet.ServletException;<br />import javax.servlet.ServletRequest;<br />import javax.servlet.ServletResponse;<br />import javax.servlet.UnavailableException;<br /><br />/**<br /> * Example filter that sets the character encoding to be used in parsing the<br /> * incoming request<br /> */<br />public class SetCharacterEncodingFilter implements Filter {<br /><br />    /**<br />     * Take this filter out of service.<br />     */<br />    public void destroy() {<br />    }<br />    /**<br />     * Select and set (if specified) the character encoding to be used to<br />     * interpret request parameters for this request.<br />     */<br />    public void doFilter(ServletRequest request, ServletResponse response,<br />    FilterChain chain)throws IOException, ServletException {<br /><br />    request.setCharacterEncoding("GBK");<br /><br />    // 传递控制到下一个过滤器<br />    chain.doFilter(request, response);<br />    }<br /><br />    public void init(FilterConfig filterConfig) throws ServletException {<br />    }<br />}<br />配置web.xml<br />&lt;filter&gt;<br />&lt;filter-name&gt;Set Character Encoding&lt;/filter-name&gt;<br />&lt;filter-class&gt;SetCharacterEncodingFilter&lt;/filter-class&gt;<br />&lt;/filter&gt;<br />&lt;filter-mapping&gt;<br />&lt;filter-name&gt;Set Character Encoding&lt;/filter-name&gt;<br />&lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br />&lt;/filter-mapping&gt;<br />如果你的还是出现这种情况的话你就往下看看是不是你出现了第四中情况，你的Form提交的数据是不是用get提交的，一般来说用post提交的话是没有问题的，如果是的话，你就看看第四中解决的办法。<br />还有就是对含有汉字字符的信息进行处理，处理的代码是：<br />package dbJavaBean;<br /><br />public class CodingConvert<br />{   <br /> public CodingConvert()<br /> {<br />  //<br /> }<br /> public String toGb(String uniStr){<br />     String gbStr = "";<br />     if(uniStr == null){<br />   uniStr = "";<br />     }<br />     try{<br />   byte[] tempByte = uniStr.getBytes("ISO8859_1");<br />   gbStr = new String(tempByte,"GB2312");<br />     }<br />  catch(Exception ex){<br />    }<br />     return gbStr;<br /> }<br />   <br /> public String toUni(String gbStr){<br />     String uniStr = "";<br />     if(gbStr == null){<br />   gbStr = "";<br />     }<br />     try{<br />   byte[] tempByte = gbStr.getBytes("GB2312");<br />   uniStr = new String(tempByte,"ISO8859_1");<br />     }catch(Exception ex){<br />    }<br />    return uniStr;<br /> }<br />}<br />你也可以在直接的转换，首先你将获取的字符串用ISO-8859-1进行编码，然后将这个编码存放到一个字节数组中，然后将这个数组转化成字符串对象就可以了，例如：<br />String str=request.getParameter(“girl”);<br />Byte B[]=str.getBytes(“ISO-8859-1”);<br />Str=new String(B);<br />通过上述转换的话，提交的任何信息都能正确的显示。<br />(三)    在Formget请求在服务端用request. getParameter(“name”)时返回的是乱码；按tomcat的做法设置Filter也没有用或者用request.setCharacterEncoding("GBK");也不管用问题是出在处理参数传递的方法上：如果在servlet中用doGet(HttpServletRequest request, HttpServletResponse response)方法进行处理的话前面即使是写了：<br />request.setCharacterEncoding("GBK");<br />response.setContentType("text/html;charset=GBK");<br />也是不起作用的，返回的中文还是乱码！！！如果把这个函数改成doPost(HttpServletRequest request, HttpServletResponse response)一切就OK了。<br />同样，在用两个JSP页面处理表单输入之所以能显示中文是因为用的是post方法传递的，改成get方法依旧不行。<br />由此可见在servlet中用doGet()方法或是在JSP中用get方法进行处理要注意。这毕竟涉及到要通过浏览器传递参数信息，很有可能引起常用字符集的冲突或是不匹配。<br />解决的办法是：<br />1) 打开tomcat的server.xml文件，找到区块，加入如下一行： <br />URIEncoding=”GBK” <br />完整的应如下： <br />&lt;Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"/&gt; <br /><br />2)重启tomcat,一切OK。<br />需要加入的原因大家可以去研究 $TOMCAT_HOME/webapps/tomcat-docs/config/http.html下的这个文件就可以知道原因了。需要注意的是：这个地方如果你要是用UTF-8的时候在传递的过程中在Tomcat中也是要出现乱码的情况，如果不行的话就换别的字符集。<br /><br />(四)    JSP页面上有中文，按钮上面也有中文，但是通过服务器查看页面的时候出现乱码：<br />     解决的办法是：首先在JSP文件中不应该直接包含本地化的消息文本，而是应该通过&lt;bean:message&gt;标签从Resource Bundle中获得文本。应该把你的中文文本放到Application.properties文件中，这个文件放在WEB-INF/classes/*下，例如我在页面里有姓名，年龄两个label,我首先就是要建一个Application.properties，里面的内容应该是name=”姓名” age=”年龄”,然后我把这个文件放到WEB-INF/classes/properties/下，接下来根据Application.properties文件，对他进行编码转化，创建一个中文资源文件，假定名字是Application_cn.properties。在JDK中提供了native2ascii命令，他能够实现字符编码的转换。在DOS环境中找到你放置Application.properties的这个文件的目录，在DOS环境中执行一下命令，将生成按GBK编码的中文资源文件Application_cn.properties：native2ascii ?encoding gbk Application.properties Application_cn.properties执行以上命令以后将生成如下内容的Application_cn.properties文件：name=\u59d3\u540d age=\u5e74\u9f84,在Struts-config.xml中配置：&lt;message-resources parameter="properties.Application_cn"/&gt;。到这一步，基本上完成了一大半，接着你就要在JSP页面上写&lt;%@ page language="java" contentType="text/html;charset=GBK" %&gt;,到名字的那个label是要写&lt;bean:message key=”name”&gt;,这样的化在页面上出现的时候就会出现中文的姓名，年龄这个也是一样，按钮上汉字的处理也是同样的。<br />(五)    写入到数据库是乱码：<br />解决的方法：要配置一个filter,也就是一个Servelet的过滤器，代码如同第二种时候一样。<br />如果你是通过JDBC直接链接数据库的时候，配置的代码如下：jdbc:mysql://localhost:3306/workshopdb?useUnicode=true&amp;characterEncoding=GBK，这样保证到数据库中的代码是不是乱码。<br />如果你是通过数据源链接的化你不能按照这样的写法了，首先你就要写在配置文件中，在tomcat 5.0.19中配置数据源的地方是在C:\Tomcat 5.0\conf\Catalina\localhost这个下面，我建立的工程是workshop，放置的目录是webapp下面,workshop.xml的配置文件如下：<br />&lt;!-- insert this Context element into server.xml --&gt;<br /><br />&lt;Context path="/workshop" docBase="workshop" debug="0"<br />reloadable="true" &gt;<br /><br />  &lt;Resource name="jdbc/WorkshopDB"<br />               auth="Container"<br />               type="javax.sql.DataSource" /&gt;<br /><br />  &lt;ResourceParams name="jdbc/WorkshopDB"&gt;<br />    &lt;parameter&gt;<br />      &lt;name&gt;factory&lt;/name&gt;<br />      &lt;value&gt;org.apache.commons.dbcp.BasicDataSourceFactory&lt;/value&gt;<br />    &lt;/parameter&gt;<br />    &lt;parameter&gt;<br />      &lt;name&gt;maxActive&lt;/name&gt;<br />      &lt;value&gt;100&lt;/value&gt;<br />    &lt;/parameter&gt;<br />    &lt;parameter&gt;<br />      &lt;name&gt;maxIdle&lt;/name&gt;<br />      &lt;value&gt;30&lt;/value&gt;<br />    &lt;/parameter&gt;<br /><br />    <br />    &lt;parameter&gt;<br />      &lt;name&gt;maxWait&lt;/name&gt;<br />      &lt;value&gt;10000&lt;/value&gt;<br />    &lt;/parameter&gt;<br /><br />      &lt;parameter&gt;<br />     &lt;name&gt;username&lt;/name&gt;<br />     &lt;value&gt;root&lt;/value&gt;<br />    &lt;/parameter&gt;<br />    &lt;parameter&gt;<br />     &lt;name&gt;password&lt;/name&gt;<br />     &lt;value&gt;&lt;/value&gt;<br />    &lt;/parameter&gt;<br /><br />    &lt;!-- Class name for mm.mysql JDBC driver --&gt;<br />    &lt;parameter&gt;<br />       &lt;name&gt;driverClassName&lt;/name&gt;<br />       &lt;value&gt;com.mysql.jdbc.Driver&lt;/value&gt;<br />&lt;/parameter&gt;<br />   &lt;parameter&gt;<br />      &lt;name&gt;url&lt;/name&gt;<br /> &lt;value&gt;&lt;![CDATA[jdbc:mysql://localhost:3306/workshopdb?useUnicode=true&amp;characterEncoding=GBK]]&gt;&lt;/value&gt;<br />    &lt;/parameter&gt;<br />  &lt;/ResourceParams&gt;<br /><br />&lt;/Context&gt;<br />粗体的地方要特别的注意，和JDBC直接链接的时候是有区别的，如果你是配置正确的化，当你输入中文的时候到数据库中就是中文了，有一点要注意的是你在显示数据的页面也是要用&lt;%@ page language="java" contentType="text/html;charset=GBK" %&gt;这行代码的。需要注意的是有的前台的人员在写代码的是后用Dreamver写的，写了一个Form的时候把他改成了一个jsp，这样有一个地方要注意了，那就是在Dreamver中Action的提交方式是request的，你需要把他该过来，因为在jsp的提交的过程中紧紧就是POST和GET两种方式，但是这两种方式提交的代码在编码方面还是有很大不同的，这个在后面的地方进行说明。3<br /><br />以上就是我在开发系统中解决中文的问题，不知道能不能解决大家的问题，时间匆忙，没有及时完善，文笔也不是很好，有些地方估计是词不达意。大家可以给我意见，希望能共同进步。<br /><img src ="http://www.blogjava.net/jdo/aggbug/139346.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-26 00:03 <a href="http://www.blogjava.net/jdo/articles/139346.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA cookies用法</title><link>http://www.blogjava.net/jdo/articles/138181.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Mon, 20 Aug 2007 08:38:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/138181.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/138181.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/138181.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/138181.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/138181.html</trackback:ping><description><![CDATA[
		<div style="margin-left: 0px;" class="postTitle">
				<a href="http://blog.csdn.net/fegor/archive/2007/05/02/1594748.aspx">
				</a> 涉及login.jsp和login_do.jsp</div>
		<br />1.先在login_do.jsp里面获取cookies代码如下<br />代码是加在登录成功的下面<br />Cookie cookie1=new Cookie("login_name",name);<br />                           键           值<br />Cookie cookie2=new Cookie("login_pass",pass)<br />值是从后面获取的<br />这个键是  login.jsp里面要用到的，name是从login_do.jsp里面<br />读取的<br />cookie1.setMaxAge(60*60*24);设置cookie的有效时间，单位是秒<br />这里是保存一天<br />response.addCookie(cookie1);<br />response.addCookie(cookie2);<br /> 把捕获来的cookies加到响应里，这步必不可少<br />response.sendRedirect("index.jsp");<br /> //登录成功转发的页面<br />2.在login.jsp里面加代码<br />Cookie[] cookie=request.getCookies();<br />String name="",pass="";<br />for(int i=0;i&lt;cookie.length;i++){<br /> if(cookie[i].getName.equals("login_name"))<br />  name=cookie[i].getValue();<br /> if(cookie[i].getName.equals("login_pass"))<br />  pass=cookie[i].getValue();<br />}<br />在表单的变量那里加上这个就可以了<br />&lt;input name="name" value="&lt;%=name %&gt;" type="text" id="name"&gt;<br />&lt;input name="pwd" value="&lt;%=pwd %&gt;" type="password" id="pwd2"&gt;<img src ="http://www.blogjava.net/jdo/aggbug/138181.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-20 16:38 <a href="http://www.blogjava.net/jdo/articles/138181.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HttpServletRequest.getRequestURI()和HttpServletRequest.getRequestURL()区别是什么?　</title><link>http://www.blogjava.net/jdo/articles/138098.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Mon, 20 Aug 2007 05:04:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/138098.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/138098.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/138098.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/138098.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/138098.html</trackback:ping><description><![CDATA[　<br />　　request.getRequestURI() 返回值类似：/xuejava/requestdemo.jsp<br />　　<br />　　request.getRequestURL() 返回值类似：<a href="http://localhost:8080/xuejava/requestdemo.jsp">http://localhost:8080/xuejava/requestdemo.jsp</a> <p> </p><p>附：</p>request.getContextPath() = /hboys<br />request.getLocalAddr() = 127.0.0.1<br />request.getPathInfo() = null<br />request.getPathTranslated() = null<br />request.getRemoteAddr() = 127.0.0.1<br />request.getRequestURI() = /hboys/<br />request.getScheme() = http<br />request.getServerName() = 127.0.0.1<br />request.getServletPath() = /index.jsp<br />request.getClass() = class org.apache.catalina.connector.RequestFacade<br />request.getHeaderNames() = <a href="mailto:org.apache.tomcat.util.http.NamesEnumerator@1ad0839">org.apache.tomcat.util.http.NamesEnumerator@1ad0839</a><br />request.getLocale() = zh_CN<br />request.getLocales() = <a href="mailto:org.apache.catalina.util.Enumerator@f6f1b6">org.apache.catalina.util.Enumerator@f6f1b6</a><br />request.getParameterMap() = {}<br />request.getRequestURL() = <a href="http://127.0.0.1:8081/hboys/">http://127.0.0.1:8081/hboys/</a><br />request.getUserPrincipal() = null<br />request.getParameterNames() = <a href="mailto:java.util.Hashtable$EmptyEnumerator@1629e71">java.util.Hashtable$EmptyEnumerator@1629e71</a><br />request.getRealPath("newsPub") = D:\workspace\hboys\WebRoot\newsPub<img src ="http://www.blogjava.net/jdo/aggbug/138098.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-20 13:04 <a href="http://www.blogjava.net/jdo/articles/138098.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Hibernate应用系列之六批量处理篇</title><link>http://www.blogjava.net/jdo/articles/137712.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Fri, 17 Aug 2007 15:12:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/137712.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/137712.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/137712.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/137712.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/137712.html</trackback:ping><description><![CDATA[
		<a target="_blank" title="Hibernate应用系列之六批量处理篇" href="http://tech.it168.com/j/e/2006-09-25/200609251710239.shtml">http://tech.it168.com/j/e/2006-09-25/200609251710239.shtml</a>
<img src ="http://www.blogjava.net/jdo/aggbug/137712.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-17 23:12 <a href="http://www.blogjava.net/jdo/articles/137712.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript操作Select标记中options集合</title><link>http://www.blogjava.net/jdo/articles/137341.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Thu, 16 Aug 2007 09:24:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/137341.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/137341.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/137341.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/137341.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/137341.html</trackback:ping><description><![CDATA[先来看看options集合的这几个方法：<br />options.add(option)方法向集合里添加一项option对象；<br />options.remove(index)方法移除options集合中的指定项；<br />options(index)或options.item(index)可以通过索引获取options集合的指定项；<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">    var</span><span style="color: rgb(0, 0, 0);"> selectTag </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">select标记</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> OPTONLENGTH </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">10</span><span style="color: rgb(0, 0, 0);">; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">每次填充option数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> colls </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> [];       </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">对select标记options的引用</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);"><br />    window.onload </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);">(){<br />        selectTag </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SelectBox</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">); </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取select标记        </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        colls </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> selectTag.options; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取引用</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">initSelectBox();    //自初始化select.options</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    };<br />    <br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">使用随机数填充select.options</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> initSelectBox(){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> random </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> ;<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> optionItem </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> item </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />        <br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(colls.length </span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">&amp;&amp;</span><span style="color: rgb(0, 0, 0);"> isClearOption()){<br />             clearOptions(colls);<br />        }<br /><br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">OPTONLENGTH;i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">){<br />             <br />            random </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Math.floor(Math.random()</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">9000</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1000</span><span style="color: rgb(0, 0, 0);">;<br />            item </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Option(random,random);    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">通过Option()构造函数创建option对象        </span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">            selectTag.options.add(item); </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">添加到options集合中</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        }    <br />        <br />        watchState();<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">添加新option项前是否清空当前options</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> isClearOption(){<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">chkClear</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).checked;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">清空options集合</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> clearOptions(colls){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> length </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> colls.length;<br />        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">(</span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> i</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">length</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;i</span><span style="color: rgb(0, 0, 0);">--</span><span style="color: rgb(0, 0, 0);">){<br />            colls.remove(i);<br />        }<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">添加一项新option</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> addOption(){<br />        colls.add(createOption());<br />        lastOptionOnFocus(colls.length</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />        watchState();<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">创建一个option对象</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> createOption(){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> random </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Math.floor(Math.random()</span><span style="color: rgb(0, 0, 0);">*</span><span style="color: rgb(0, 0, 0);">9000</span><span style="color: rgb(0, 0, 0);">)</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">1000</span><span style="color: rgb(0, 0, 0);">;<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Option(random,random);<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">删除options集合中指定的一项option</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> removeOption(index){        <br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(index </span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">){<br />            colls.remove(index);<br />            lastOptionOnFocus(colls.length</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />        }<br />        watchState();<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取当前选定的option索引</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> getSelectedIndex(){<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> selectTag.selectedIndex;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取options集合的总数</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> getOptionLength(){<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> colls.length;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取当前选定的option文本</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> getCurrentOptionValue(index){<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(index </span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> colls(index).value;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">获取当前选定的option值</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> getCurrentOptionText(index){<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(index </span><span style="color: rgb(0, 0, 0);">&gt;=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">)<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> colls(index).text;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">使用options集合中最后一项获取焦点</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> lastOptionOnFocus(index){<br />        selectTag.selectedIndex </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> index;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">显示当select标记状态</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">function</span><span style="color: rgb(0, 0, 0);"> watchState(){<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> divWatch </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> document.getElementById(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">divWatch</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        </span><span style="color: rgb(0, 0, 255);">var</span><span style="color: rgb(0, 0, 0);"> innerHtml</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">;<br />        innerHtml  </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">option总数:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> getOptionLength();<br />        innerHtml </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;br/&gt;当前项索引:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> getSelectedIndex();<br />        innerHtml </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;br/&gt;当前项文本:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> getCurrentOptionText(getSelectedIndex());<br />        innerHtml </span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&lt;br/&gt;当前项值:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> getCurrentOptionValue(getSelectedIndex());<br />        divWatch.innerHTML </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> innerHtml;<br />        divWatch.align </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">justify</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />    }</span></div><br /><img src ="http://www.blogjava.net/jdo/aggbug/137341.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-16 17:24 <a href="http://www.blogjava.net/jdo/articles/137341.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java路径问题最终解决方案</title><link>http://www.blogjava.net/jdo/articles/136791.html</link><dc:creator>蓝色幽默</dc:creator><author>蓝色幽默</author><pubDate>Tue, 14 Aug 2007 15:15:00 GMT</pubDate><guid>http://www.blogjava.net/jdo/articles/136791.html</guid><wfw:comment>http://www.blogjava.net/jdo/comments/136791.html</wfw:comment><comments>http://www.blogjava.net/jdo/articles/136791.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jdo/comments/commentRss/136791.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jdo/services/trackbacks/136791.html</trackback:ping><description><![CDATA[
		<div>
				<strong>
						<font size="6">前言</font>
				</strong>
		</div>
		<div style="text-indent: 24pt;">Java的路径问题，非常难搞。最近的工作涉及到创建和读取文件的工作，这里我就给大家彻底得解决Java路径问题。</div>
		<div style="text-indent: 24pt;">我
编写了一个方法，比ClassLoader.getResource(String
相对路径)方法的能力更强。它可以接受“../”这样的参数，允许我们用相对路径来定位classpath外面的资源。这样，我们就可以使用相对于
classpath的路径，定位所有位置的资源！</div>
		<div style="text-indent: 24pt;"> </div>
		<div>
				<strong>
						<font size="6">Java路径</font>
				</strong>
		</div>
		<div style="text-indent: 24pt;">Java中使用的路径，分为两种：绝对路径和相对路径。具体而言，又分为四种：</div>
		<div>
				<strong>
						<font size="4">一、URI形式的绝对资源路径</font>
				</strong>
		</div>
		<div>如：file:/D:/java/eclipse32/workspace/jbpmtest3/bin/aaa.b</div>
		<div style="text-indent: 24pt;">URL是URI的特例。URL的前缀/协议，必须是Java认识的。URL可以打开资源，而URI则不行。</div>
		<div style="text-indent: 24pt;">URL和URI对象可以互相转换，使用各自的toURI(),toURL()方法即可！</div>
		<div> </div>
		<div>
				<strong>
						<font size="4">二、本地系统的绝对路径</font>
				</strong>
		</div>
		<div>D:/java/eclipse32/workspace/jbpmtest3/bin/aaa.b</div>
		<div style="text-indent: 24pt;">Java.io包中的类，需要使用这种形式的参数。</div>
		<div style="text-indent: 24pt;">但是，它们一般也提供了URI类型的参数，而URI类型的参数，接受的是URI样式的String。因此，通过URI转换，还是可以把URI样式的绝对路径用在java.io包中的类中。</div>
		<div> </div>
		<div>
				<strong>
						<font size="4">三、相对于classpath的相对路径</font>
				</strong>
		</div>
		<div>如：相对于</div>
		<div>file:/D:/java/eclipse32/workspace/jbpmtest3/bin/这个路径的相对路径。其中，bin是本项目的classpath。所有的Java源文件编译后的.class文件复制到这个目录中。</div>
		<div> </div>
		<div> </div>
		<div>
				<strong>
						<font size="4">四、相对于当前用户目录的相对路径</font>
				</strong>
		</div>
		<div>就是相对于System.getProperty("user.dir")返回的路径。</div>
		<div style="text-indent: 24pt;">对于一般项目，这是项目的根路径。对于JavaEE服务器，这可能是服务器的某个路径。这个并没有统一的规范！</div>
		<div style="text-indent: 24pt;">所以，绝对不要使用“相对于当前用户目录的相对路径”。然而：</div>
		<div>
				<strong>
						<span style="color: windowtext;">默认情况下，java.io 包中的类总是根据当前用户目录来分析相对路径名。此目录由系统属性 user.dir 指定，通常是 Java 虚拟机的调用目录。</span>
				</strong>
		</div>
		<div style="text-indent: 24.75pt;">
				<span style="color: windowtext;">这就是说，在使用java.io包中的类时，最好不要使用相对路径。否则，虽然在J2SE应用程序中可能还算正常，但是到了J2EE程序中，一定会出问题！而且这个路径，在不同的服务器中都是不同的！</span>
		</div>
		<div> </div>
		<div>
				<strong>
						<font size="6">相对路径最佳实践</font>
				</strong>
		</div>
		<div>
				<strong>
						<font size="5">推荐使用相对于当前classpath的相对路径</font>
				</strong>
		</div>
		<div style="text-indent: 24pt;">因此，我们在使用相对路径时，应当使用相对于当前classpath的相对路径。</div>
		<div style="text-indent: 24pt;">ClassLoader类的getResource(String name),<code><strong>getResourceAsStream</strong>(String name)等方法，使用相对于当前项目的classpath的相对路径来查找资源。</code></div>
		<div style="text-indent: 24pt;">读取属性文件常用到的ResourceBundle类的getBundle(String path)也是如此。</div>
		<div style="text-indent: 24pt;">通
过查看ClassLoader类及其相关类的源代码，我发现，它实际上还是使用了URI形式的绝对路径。通过得到当前classpath的URI形式的绝
对路径，构建了相对路径的URI形式的绝对路径。（这个实际上是猜想，因为JDK内部调用了SUN的源代码，而这些代码不属于JDK，不是开源的。）</div>
		<div> </div>
		<div>
				<strong>
						<font size="5">相对路径本质上还是绝对路径</font>
				</strong>
		</div>
		<div style="text-indent: 24pt;">
				<strong>
						<span style="font-size: 15pt;">因此，归根结底，</span>
				</strong>
				<strong>
						<span style="font-size: 15pt;">Java</span>
				</strong>
				<strong>
						<span style="font-size: 15pt;">本质上只能使用绝对路径来寻找资源。所有的相对路径寻找资源的方法，都不过是一些便利方法。不过是</span>
				</strong>
				<strong>
						<span style="font-size: 15pt;">API</span>
				</strong>
				<strong>
						<span style="font-size: 15pt;">在底层帮助我们构建了绝对路径，从而找到资源的！</span>
				</strong>
		</div>
		<div> </div>
		<div>
				<strong>
						<font size="5">得到classpath和当前类的绝对路径的一些方法</font>
				</strong>
		</div>
		<div>
				<span>    </span>下面是一些得到classpath和当前类的绝对路径的一些方法。你可能需要使用其中的一些方法来得到你需要的资源的绝对路径。</div>
		<div>
				<strong>1</strong>
				<strong>，FileTest.class.getResource("")</strong>
		</div>
		<div style="text-indent: 24pt;">得到的是当前类FileTest.class文件的URI目录。不包括自己！</div>
		<div style="text-indent: 24pt;">如：<span style="font-size: 10pt;">file:/D:/java/eclipse32/workspace/jbpmtest3/bin/com/test/</span></div>
		<div>
				<strong>2</strong>
				<strong>，FileTest.<span>class.getResource("/")</span></strong>
		</div>
		<div style="text-indent: 24pt;">得到的是当前的classpath的绝对URI路径。</div>
		<div style="text-indent: 24pt;">如：<span style="font-size: 10pt;">file:/D:/java/eclipse32/workspace/jbpmtest3/bin/</span></div>
		<div>
				<strong>
						<span style="font-size: 10pt;">3</span>
				</strong>
				<strong>
						<span style="font-size: 10pt;">，Thread.currentThread().getContextClassLoader().getResource("")</span>
				</strong>
		</div>
		<div style="text-indent: 21pt;">
				<span style="font-size: 10pt;">得到的也是当前ClassPath的绝对URI路径。</span>
		</div>
		<div style="text-indent: 24pt;">如：<span style="font-size: 10pt;">file:/D:/java/eclipse32/workspace/jbpmtest3/bin/</span></div>
		<div>
				<strong>
						<span style="font-size: 10pt;">4</span>
				</strong>
				<strong>
						<span style="font-size: 10pt;">，FileTest.<span>class.getClassLoader().getResource("")</span></span>
				</strong>
		</div>
		<div style="text-indent: 21pt;">
				<span style="font-size: 10pt;">得到的也是当前ClassPath的绝对URI路径。</span>
		</div>
		<div style="text-indent: 24pt;">如：<span style="font-size: 10pt;">file:/D:/java/eclipse32/workspace/jbpmtest3/bin/</span></div>
		<div>
				<strong>5</strong>
				<strong>，ClassLoader.getSystemResource("")</strong>
		</div>
		<div style="text-indent: 21pt;">
				<span style="font-size: 10pt;">得到的也是当前ClassPath的绝对URI路径。</span>
		</div>
		<div style="text-indent: 24pt;">如：<span style="font-size: 10pt;">file:/D:/java/eclipse32/workspace/jbpmtest3/bin/</span></div>
		<div>
				<strong>
						<span>    </span>
				</strong>
		</div>
		<div style="text-indent: 24pt;">
				<strong>我推荐使用</strong>
				<strong>
						<span style="font-size: 10pt;">Thread.currentThread().getContextClassLoader().getResource("")</span>
				</strong>
				<strong>
						<span style="font-size: 10pt;">来得到当前的classpath的绝对路径的URI表示法。</span>
				</strong>
		</div>
		<div>
				<strong> </strong>
		</div>
		<div>
				<strong>
						<font size="5">Web应用程序中资源的寻址</font>
				</strong>
		</div>
		<div>
				<span>    </span>上文中说过，当前用户目录，即相对于System.getProperty("user.dir")返回的路径。</div>
		<div style="text-indent: 24pt;">对于JavaEE服务器，这可能是服务器的某个路径，这个并没有统一的规范！</div>
		<div style="text-indent: 24pt;">而不是我们发布的Web应用程序的根目录！</div>
		<div style="text-indent: 24pt;">这样，在Web应用程序中，我们绝对不能使用相对于当前用户目录的相对路径。</div>
		<div style="text-indent: 24pt;">在Web应用程序中，我们一般通过ServletContext.getRealPath("/")方法得到Web应用程序的根目录的绝对路径。</div>
		<div style="text-indent: 24pt;">这样，我们只需要提供相对于Web应用程序根目录的路径，就可以构建出定位资源的绝对路径。</div>
		<div style="text-indent: 24pt;">这是我们开发Web应用程序时一般所采取的策略。</div>
		<div> </div>
		<div>
				<strong>
						<font size="6">通用的相对路径解决办法</font>
				</strong>
		</div>
		<div style="text-indent: 24pt;">Java中各种相对路径非常多，不容易使用，非常容易出错。因此，我编写了一个便利方法，帮助更容易的解决相对路径问题。</div>
		<div> </div>
		<div>
				<strong>
						<font size="5">Web应用程序中使用JavaSE运行的资源寻址问题</font>
				</strong>
		</div>
		<div style="text-indent: 24pt;">在JavaSE程序中，我们一般使用classpath来作为存放资源的目的地。但是，在Web应用程序中，我们一般使用classpath外面的WEB-INF及其子目录作为资源文件的存放地。</div>
		<div style="text-indent: 24pt;">在Web应用程序中，我们一般通过ServletContext.getRealPath("/")方法得到Web应用程序的根目录的绝对路径。这样，我们只需要提供相对于Web应用程序根目录的路径，就可以构建出定位资源的绝对路径。</div>
		<div style="text-indent: 24pt;">Web应用程序，可以作为Web应用程序进行发布和运行。但是，我们也常常会以JavaSE的方式来运行Web应用程序的某个类的main方法。或者，使用JUnit测试。这都需要使用JavaSE的方式来运行。</div>
		<div style="text-indent: 24pt;">这样，我们就无法使用ServletContext.getRealPath("/")方法得到Web应用程序的根目录的绝对路径。</div>
		<div style="text-indent: 24pt;">而JDK提供的ClassLoader类，</div>
		<div style="text-indent: 24pt;">它的getResource(String name),<code><strong>getResourceAsStream</strong>(String name)等方法，使用相对于当前项目的classpath的相对路径来查找资源。</code></div>
		<div style="text-indent: 24pt;">读取属性文件常用到的ResourceBundle类的getBundle(String path)也是如此。</div>
		<div style="text-indent: 24pt;">它们都只能使用相对路径来读取classpath下的资源，无法定位到classpath外面的资源。</div>
		<div>
				<strong>
						<font size="4">Classpath外配置文件读取问题</font>
				</strong>
		</div>
		<div style="text-indent: 24pt;">如，我们使用测试驱动开发的方法，开发Spring、Hibernate、iBatis等使用配置文件的Web应用程序，就会遇到问题。</div>
		<div style="text-indent: 24pt;">尽管Spring自己提供了FileSystem（也就是相对于user,dir目录）来读取Web配置文件的方法，但是终究不是很方便。而且与Web程序中的代码使用方式不一致！</div>
		<div>至于Hibernate，iBatis就更麻烦了！只有把配置文件移到classpath下，否则根本不可能使用测试驱动开发！</div>
		<div> </div>
		<div>
				<span>    </span>这怎么办？</div>
		<div> </div>
		<div>
				<strong>
						<font size="6">通用的相对路径解决办法</font>
				</strong>
		</div>
		<div style="text-indent: 24pt;">面对这个问题，我决定编写一个助手类<span style="background: silver none repeat scroll 0% 50%; font-size: 10pt; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">ClassLoaderUtil</span>，提供一个便利方法[<strong>public</strong><strong>static</strong>
URL getExtendResource(String
relativePath)]。在Web应用程序等一切Java程序中，需要定位classpath外的资源时，都使用这个助手类的便利方法，而不使用
Web应用程序特有的ServletContext.getRealPath("/")方法来定位资源。</div>
		<div> </div>
		<div>
				<strong>
						<font size="4">利用classpath的绝对路径，定位所有资源</font>
				</strong>
		</div>
		<div style="text-indent: 24pt;">这个便利方法的实现原理，就是“利用classpath的绝对路径，定位所有资源”。</div>
		<div style="text-indent: 24pt;">ClassLoader类的getResource("")方法能够得到当前classpath的绝对路径，这是所有Java程序都拥有的能力，具有最大的适应性！</div>
		<div style="text-indent: 24pt;">而目前的JDK提供的ClassLoader类的getResource(String 相对路径)方法，只能接受一般的相对路径。这样，使用ClassLoader类的getResource(String 相对路径)方法就只能定位到classpath下的资源。</div>
		<div style="text-indent: 24.1pt;">
				<strong>如果，它能够接受“../</strong>
				<strong>”这样的参数，允许我们用相对路径来定位classpath</strong>
				<strong>外面的资源，那么我们就可以定位位置的资源！</strong>
		</div>
		<div style="text-indent: 24pt;">当然，我无法修改ClassLoader类的这个方法，于是，我编写了一个助手类ClassLoaderUtil类，提供了[<strong>public</strong><strong>static</strong> URL getExtendResource(String relativePath)]这个方法。它能够接受带有“../”符号的相对路径，实现了自由寻找资源的功能。</div>
		<div> </div>
		<div>
				<strong>
						<font size="6">通过相对classpath路径实现自由寻找资源的助手类的源代码：<br /></font>
				</strong>
				<br />
				<div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;">
						<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->
						<span style="color: rgb(0, 0, 255);">package</span>
						<span style="color: rgb(0, 0, 0);"> com.commonStrut.utils;<br /><br /></span>
						<span style="color: rgb(0, 0, 255);">import</span>
						<span style="color: rgb(0, 0, 0);"> java.io.IOException;<br /></span>
						<span style="color: rgb(0, 0, 255);">import</span>
						<span style="color: rgb(0, 0, 0);"> java.io.InputStream;<br /></span>
						<span style="color: rgb(0, 0, 255);">import</span>
						<span style="color: rgb(0, 0, 0);"> java.net.MalformedURLException;<br /></span>
						<span style="color: rgb(0, 0, 255);">import</span>
						<span style="color: rgb(0, 0, 0);"> java.net.URL;<br /></span>
						<span style="color: rgb(0, 0, 255);">import</span>
						<span style="color: rgb(0, 0, 0);"> java.util.Properties;<br /><br /></span>
						<span style="color: rgb(0, 0, 255);">import</span>
						<span style="color: rgb(0, 0, 0);"> org.apache.commons.logging.Log;<br /></span>
						<span style="color: rgb(0, 0, 255);">import</span>
						<span style="color: rgb(0, 0, 0);"> org.apache.commons.logging.LogFactory;<br /><br /></span>
						<span style="color: rgb(0, 128, 0);">/**</span>
						<span style="color: rgb(0, 128, 0);">
								<br /> *  用来加载类，ClassPath下的资源文件，属性文件等。<br /> *  getExtendResource(StringrelativePath)方法，可以使用../符号来加载ClassPath外部的资源。<br /> *  <br /> * </span>
						<span style="color: rgb(128, 128, 128);">@author</span>  <span style="color: rgb(0, 128, 0);">蓝色幽默 整理                    <br /> </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil {<br />    <br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> Log log </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> LogFactory.getLog(ClassLoaderUtil.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * Thread.currentThread().getContextClassLoader().getResource("")<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * 加载Java类。 使用全限定类名<br />     * <br />     * @paramclassName<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    @SuppressWarnings(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">unchecked</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)<br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> Class loadClass(String className) {<br />        </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> getClassLoader().loadClass(className);<br />        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (ClassNotFoundException e) {<br />            </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> RuntimeException(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> class not found ' </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> className </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ' </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, e);<br />        }<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * 得到类加载器<br />     * <br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> ClassLoader getClassLoader() {<br /><br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">.getClassLoader();<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * 提供相对于classpath的资源路径，返回文件的输入流<br />     * <br />     * @paramrelativePath必须传递资源的相对路径。是相对于classpath的路径。如果需要查找classpath外部的资源，需要使用../来查找<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"> 文件输入流<br />     * @throwsIOException<br />     * @throwsMalformedURLException<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> InputStream getStream(String relativePath) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> MalformedURLException, IOException {<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">relativePath.contains(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ../ </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)) {<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> getClassLoader().getResourceAsStream(relativePath);<br /><br />        } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil.getStreamByExtendResource(relativePath);<br />        }<br /><br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * <br />     * @paramurl<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     * @throwsIOException<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> InputStream getStream(URL url) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> IOException {<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (url </span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">) {<br /><br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> url.openStream();<br /><br />        } </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"> {<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />        }<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * <br />     * @paramrelativePath必须传递资源的相对路径。是相对于classpath的路径。如果需要查找classpath外部的资源，需要使用../来查找<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     * @throwsMalformedURLException<br />     * @throwsIOException<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> InputStream getStreamByExtendResource(String relativePath) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> MalformedURLException,<br />            IOException {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil.getStream(ClassLoaderUtil.getExtendResource(relativePath));<br /><br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * 提供相对于classpath的资源路径，返回属性对象，它是一个散列表<br />     * <br />     * @paramresource<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> Properties getProperties(String resource) {<br />        Properties properties </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Properties();<br />        </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br />            properties.load(getStream(resource));<br />        } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);"> (IOException e) {<br />            </span><span style="color: rgb(0, 0, 255);">throw</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> RuntimeException(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> couldn't load properties file ' </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> resource </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ' </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, e);<br />        }<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> properties;<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * 得到本Class所在的ClassLoader的Classpat的绝对路径。 URL形式的<br />     * <br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> String getAbsolutePathOfClassLoaderClassPath() {<br /><br />        ClassLoaderUtil.log.info(ClassLoaderUtil.getClassLoader().getResource(</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">).toString());<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil.getClassLoader().getResource(</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">).toString();<br /><br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * <br />     * @paramrelativePath 必须传递资源的相对路径。是相对于classpath的路径。如果需要查找classpath外部的资源，需要使用../来查找<br />     * @return资源的绝对URL<br />     * @throwsMalformedURLException<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> URL getExtendResource(String relativePath) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> MalformedURLException {<br /><br />        ClassLoaderUtil.log.info(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> 传入的相对路径： </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> relativePath);<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> ClassLoaderUtil.log.info(Integer.valueOf(relativePath.indexOf("../")))<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> ;</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 0);">!</span><span style="color: rgb(0, 0, 0);">relativePath.contains(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ../ </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)) {<br />            </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil.getResource(relativePath);<br /><br />        }<br />        String classPathAbsolutePath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil.getAbsolutePathOfClassLoaderClassPath();<br />        </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (relativePath.substring(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">).equals(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> / </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)) {<br />            relativePath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> relativePath.substring(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />        }<br />        ClassLoaderUtil.log.info(Integer.valueOf(relativePath.lastIndexOf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ../ </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)));<br /><br />        String wildcardString </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> relativePath.substring(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, relativePath.lastIndexOf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ../ </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">);<br />        relativePath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> relativePath.substring(relativePath.lastIndexOf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ../ </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">3</span><span style="color: rgb(0, 0, 0);">);<br />        </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> containSum </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil.containSum(wildcardString, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> ../ </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />        classPathAbsolutePath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil.cutLastString(classPathAbsolutePath, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> / </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, containSum);<br />        String resourceAbsolutePath </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> classPathAbsolutePath </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> relativePath;<br />        ClassLoaderUtil.log.info(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> 绝对路径： </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> resourceAbsolutePath);<br />        URL resourceAbsoluteURL </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> URL(resourceAbsolutePath);<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> resourceAbsoluteURL;<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * <br />     * @paramsource<br />     * @paramdest<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> containSum(String source, String dest) {<br />        </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> containSum </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;<br />        </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> destLength </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> dest.length();<br />        </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);"> (source.contains(dest)) {<br />            containSum </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> containSum </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">;<br />            source </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> source.substring(destLength);<br /><br />        }<br /><br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> containSum;<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * <br />     * @paramsource<br />     * @paramdest<br />     * @paramnum<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> String cutLastString(String source, String dest, </span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> num) {<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> String cutSource=null;</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> (</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);"> i </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">; i </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> num; i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">) {<br />            source </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> source.substring(</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">, source.lastIndexOf(dest, source.length() </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">) </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br /><br />        }<br /><br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> source;<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * <br />     * @paramresource<br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> URL getResource(String resource) {<br />        ClassLoaderUtil.log.info(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> 传入的相对于classpath的路径： </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> resource);<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> ClassLoaderUtil.getClassLoader().getResource(resource);<br />    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />     * @paramargs<br />     * @throwsMalformedURLException<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> main(String[] args) </span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);"> MalformedURLException {<br /><br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> ClassLoaderUtil.getExtendResource("../spring/dao.xml");<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> ClassLoaderUtil.getExtendResource("../../../src/log4j.properties");</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        ClassLoaderUtil.getExtendResource(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> log4j.properties </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><br />        System.out.println(ClassLoaderUtil.getClassLoader().getResource(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> log4j.properties </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).toString());<br /><br />    }<br />}</span></div>
				<br />
				<div>
						<strong>
								<font size="6">后记</font>
						</strong>
				</div>
				<div style="text-indent: 24pt;">ClassLoaderUtil类的public static URL getExtendResource(String relativePath)，虽然很简单，但是确实可以解决大问题。</div>
				<div style="text-indent: 24pt;">不过这个方法还是比较简陋的。我还想在未来有空时，进一步增强它的能力。比如，增加Ant风格的匹配符。用**代表多个目录，*代表多个字符，？代表一个字符。达到Spring那样的能力，一次返回多个资源的URL，进一步方便大家开发。</div>
				<div> </div>
				<div>
						<strong>
								<font size="4">总结：</font>
						</strong>
				</div>
				<div>1，尽量不要使用相对于System.getProperty("user.dir")当前用户目录的相对路径。这是一颗定时炸弹，随时可能要你的命。</div>
				<div>2，尽量使用URI形式的绝对路径资源。它可以很容易的转变为URI,URL，File对象。</div>
				<div>3，
尽量使用相对classpath的相对路径。不要使用绝对路径。使用上面ClassLoaderUtil类的public static URL
getExtendResource(String
relativePath)方法已经能够使用相对于classpath的相对路径定位所有位置的资源。</div>
				<div>4，绝对不要使用硬编码的绝对路径。因为，我们完全可以使用ClassLoader类的getResource("")方法得到当前classpath的绝对路径。</div>
				<div style="text-indent: 24pt;">使用硬编码的绝对路径是完全没有必要的！它一定会让你死的很难看！程序将无法移植！</div>
				<div style="text-indent: 24pt;">如果你一定要指定一个绝对路径，那么使用配置文件，也比硬编码要好得多！</div>
				<div>当然，我还是推荐你使用程序得到classpath的绝对路径来拼资源的绝对路径！</div>
				<br />
		</div>
<img src ="http://www.blogjava.net/jdo/aggbug/136791.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jdo/" target="_blank">蓝色幽默</a> 2007-08-14 23:15 <a href="http://www.blogjava.net/jdo/articles/136791.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>