??xml version="1.0" encoding="utf-8" standalone="yes"?>污视频网站在线免费,欧美巨猛xxxx猛交黑人97人,一级在线观看http://www.aygfsteel.com/jdo/articles/168621.html蓝色q默蓝色q默Tue, 18 Dec 2007 16:15:00 GMThttp://www.aygfsteel.com/jdo/articles/168621.htmlhttp://www.aygfsteel.com/jdo/comments/168621.htmlhttp://www.aygfsteel.com/jdo/articles/168621.html#Feedback0http://www.aygfsteel.com/jdo/comments/commentRss/168621.htmlhttp://www.aygfsteel.com/jdo/services/trackbacks/168621.html


----------------------------------------

System.out.println(123456.789);

----------------------------------------

会在Console看到输出

----------------------------------------

123456.789

----------------------------------------

那么如何得到?23Q?56.789”这U格式化的输出呢Q?

q里需要用到java.text.Formatq个cR?

不仅是数字,它还提供了货币值和癑ֈ数的格式化输出,例如0.58的百分数输出形式?8%?

要获得本地的默认格式Q可以用下列Ҏ获得Q?

NumberFormat.getNumberInstance()
NumberFormat.getCurrencyInstance()
NumberFormat.getOpercentInstance()

而要获得某个国家或地区的具体格式Q可以用参数Local.XXX。例如,Local.GERMANYQLocal.UK?

范例Q?

---------------------------------------------------------------

import java.text.NumberFormat;
import java.util.Locale;

public class FormatTest{
    public static void main(String args[]){ 

        //不用格式化输出敊W?br />          double d = 10000.0/3.0;
        System.out.println("无格式化输出Q? + d);

        //使用本地默认格式输出?
          NumberFormat numberFormat = NumberFormat.getNumberInstanc();
        //numberFormat.setMaximumFractionDigits(4); 
        //numberFormat.setMinimumIntegerDigits(6);
        String numberString = numberFormat.format(d);
        System.out.println("本地默认格式输出敎ͼ" + numberString);

       //使用本地默认格式输出货币?
         NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
       System.out.println("本地默认格式输出货币|" + currencyFormat.format(d));

       //使用本地默认格式输出癑ֈ?
         NumberFormat percentFormat = NumberFormat.getPercentInstance();
       System.out.println("本地默认格式输出癑ֈ敎ͼ" + percentFormat.format(d)); 

      //在不同的国家各地区数字表C的格式也有区别。例如d?
          //使用德国的格式化输出?
            NumberFormat numberFormatG = NumberFormat.getNumberInstance(Local.GERMANY);
          System.out.println("德国数字输出形式Q? + numberFormatG.format(d));

         //使用德国货币输出形式
           NumberFormat currencyFormatG = NumberFormat.getCurrencyInstance(Local.GERMANY);
         System.out.println("德国货币输出形式Q? + currencyFormatG.format(d));

         //使用国货币输出形式
           NumberFormat currencyFormatA = NumberFormat.getCurrencyInstance(Local.US);
         System.out.println("国货币输出形式Q? + currencyFormatG.format(d)); 
       
         //使用德国癑ֈ数输出Ş式?br />           NumberFormat percentFormatG = NumberFormat.getPercentInstance(Local.GERMANY);
         System.out.println("德国癑ֈ数输出Ş式:" + percentFormatG .format(d));

         System.exit(0);
     }
 }
 
---------------------------------------------------------------------------------

E序输出

---------------------------------------

<!--[if !vml]--><!--[endif]-->

---------------------------------------

׃Ƨ元W号无法在此Console输出Q所以显C?

可以指定昄的最多(或最)整数位和数位。如

---------------------------------------

double d = 10000.0/3.0;
NumberFormat numberFormat = NumberFormat.getNumberInstance();
numberFormat.setMaximumFractionDigits(4);
numberFormat.setMinimumIntegerDigits(6);
String numberString = numberFormat.format(d);
System.out.println(numberString);
 
---------------------------------------

输出Q?

---------------------------------------

003Q?33.3333

---------------------------------------

整数位不够的补零Q小数截去部分四舍五入?

也可以利用NumberFormat的一个子cDecimalFormat来指定输出格式?

---------------------------------------

DecimalFormat decimalFormat = new DecimalFormat("######.0000");
String s = decimalFormat.format(d);

---------------------------------------

和前面一P昄6个整C?个小C?

下面Ҏ式化的数字进行解析?

---------------------------------------

import java.util.Locale;
import java.text.NumberFormat;
import java.text.ParseException;

public class ParseFormat{
    public static void main(String args[]){

        //本地格式的解?
          NumberFormat numberFormat1 = NumberFormat.getNumberInstance(); 
       Number numb1 = null;

       try
      {
           numb1 = numberFormat1.parse("33,333.33");
       }
       catch(ParseException e1)
      {
           System.err.println(e1);
      }
      System.out.println(number1);

      //以d国格式解析?br />        NumberFormat numberFormat2 = NumberFormat.getNumberInstance(Locale.GERMANY);
        Number numb2 = null; 
 
        try
       {
            numb2 = numberFormat2.parse("33,333.33");
       }
       catch(ParseException e2)
       {
            System.err.println(e2);
       }
       System.out.println(number2);

       System.exit(0);
    }
}
 
---------------------------------

E序输出Q?

---------------------------------

33333.33 33.333
 
--------------------------------
 
同样一U格?3,333.33Q有人将之理解ؓ33333.33Q也有h认ؓ它是33.333QY件国际化的重要性可见一斑?



蓝色q默 2007-12-19 00:15 发表评论
]]>
BMP文g格式分析http://www.aygfsteel.com/jdo/articles/146989.html蓝色q默蓝色q默Fri, 21 Sep 2007 02:09:00 GMThttp://www.aygfsteel.com/jdo/articles/146989.htmlhttp://www.aygfsteel.com/jdo/comments/146989.htmlhttp://www.aygfsteel.com/jdo/articles/146989.html#Feedback1http://www.aygfsteel.com/jdo/comments/commentRss/146989.htmlhttp://www.aygfsteel.com/jdo/services/trackbacks/146989.html 本来不想写这东西,因ؓ介绍BMP文gl构的资料太多了Q都有些滥了。但刚写完BMP的读写模块,又不想不留下点什么,所以就写了Q全当是学习W记吧。自׃后查资料时也方便一些,也许Ҏ些初哥还会有点用^_^

?/p>

BMP(Bitmap-File) 囑Ş文g是Windows采用的图形文件格式,在Windows环境下运行的所有图象处理Y仉支持BMP图象文g格式。Windowspȝ内部各图像绘 制操作都是以BMP为基的。Windows 3.0以前的BMP图文件格式与昄讑֤有关Q因此把q种BMP图象文g格式UCؓ讑֤相关位图DDB(device-dependent bitmap)文g格式。Windows 3.0以后的BMP图象文g与显C备无养I因此把这UBMP图象文g格式UCؓ讑֤无关位图DIB(device-independent bitmap) 格式Q注QWindows 3.0以后Q在pȝ中仍然存在DDB位图Q象BitBlt()q种函数是ZDDB位图的,只不q如果你惛_囑փ以BMP格式保存到磁盘文件中Ӟ微Y 极力推荐你以DIB格式保存Q,目的是ؓ了让Windows能够在Q何类型的昄讑֤上显C所存储的图象。BMP位图文g默认的文件扩展名是BMP或? bmpQ有时它也会?DIB?RLE作扩展名Q?

6.1.2 文gl构

位图文g可看成由4个部分组成:位图文g?bitmap-file header)、位图信息头(bitmap-information header)、彩色表(color table)和定义位囄字节阵列Q它h如下所C的形式?

位图文g的组?/font>

l构名称

W号

位图文g?bitmap-file header) BITMAPFILEHEADER bmfh
位图信息?bitmap-information header) BITMAPINFOHEADER bmih
彩色?color table) RGBQUAD aColors[]
图象数据阵列字节 BYTE aBitmapBits[]

位图文gl构可综合在?-01中?

?1 位图文gl构内容摘要

 

偏移?/font>

域的名称

大小

内容

 

 

 

图象文g

?/font>

0000h 文g标识 2 bytes 两字节的内容用来识别位图的类型:

‘BM?Q?Windows 3.1x, 95, NT, ?/font>

‘BA?QOS/2 Bitmap Array

‘CI?QOS/2 Color Icon

‘CP?QOS/2 Color Pointer

‘IC?Q?OS/2 Icon

‘PT?QOS/2 Pointer

注:因ؓOS/2pȝq没有被普及开Q所以在~程Ӟ你只需判断W一个标识“BM”就行?/font>

  0002h File Size 1 dword 用字节表C的整个文g的大?/font>
  0006h Reserved 1 dword 保留Q必设|ؓ0
  000Ah Bitmap Data Offset 1 dword 从文件开始到位图数据开始之间的数据(bitmap data)之间的偏U量
  000Eh Bitmap Header Size 1 dword 位图信息?Bitmap Info Header)的长度,用来描述位图的颜艌Ӏ压~方法等。下面的长度表示Q?/font>

28h - Windows 3.1x, 95, NT, ?/font>

0Ch - OS/2 1.x

F0h - OS/2 2.x

注: 在Windows95?8?000{操作系l中Q位图信息头的长度ƈ不一定是28hQ因为微软已l制定出了新的BMP文g格式Q其中的信息头结构变? 比较大,长度加长。所以最好不要直接用常?8hQ而是应该从具体的文g中读取这个倹{这h能确保程序的兼容性?/font>

  0012h Width 1 dword 位图的宽度,以象素ؓ单位
  0016h Height 1 dword 位图的高度,以象素ؓ单位
  001Ah Planes 1 word 位图的位面数Q注Q该值将L1Q?/font>

图象

信息

?/font>

 

 

001Ch Bits Per Pixel 1 word 每个象素的位?/font>

1 - 单色位图Q实际上可有两种颜色Q缺省情况下是黑色和白色。你可以自己定义q两U颜Ԍ

4 - 16 色位?/font>

8 - 256 色位?/font>

16 - 16bit 高彩色位?/font>

24 - 24bit 真彩色位?/font>

32 - 32bit 增强型真彩色位图

  001Eh Compression 1 dword 压羃说明Q?/font>

0 - 不压~?(使用BI_RGB表示)

1 - RLE 8-使用8位RLE压羃方式(用BI_RLE8表示)

2 - RLE 4-使用4位RLE压羃方式(用BI_RLE4表示)

3 - Bitfields-位域存放方式(用BI_BITFIELDS表示)

  0022h Bitmap Data Size 1 dword 用字节数表示的位图数据的大小。该数必L4的倍数
  0026h HResolution 1 dword 用象?cC的水^分L?/font>
  002Ah VResolution 1 dword 用象?cC的垂直分L?/font>
  002Eh Colors 1 dword 位图使用的颜色数。如8-比特/象素表示?00h或?256.
  0032h Important Colors 1 dword 指定重要的颜色数。当该域的值等于颜色数Ӟ或者等?ӞQ表C所有颜色都一样重?/font>
调色板数?/font> ҎBMP版本的不同而不?/font> Palette N * 4 byte 调色板规范。对于调色板中的每个表项Q这4个字节用下述Ҏ来描qRGB的|
1字节用于蓝色分量
1字节用于l色分量
1字节用于U色分量
1字节用于填充W?讄?)
图象数据 ҎBMP版本及调色板寸的不同而不?/font> Bitmap Data xxx bytes 该域的大取决于压羃Ҏ及图像的寸和图像的位深度,它包含所有的位图数据字节Q这些数据可能是彩色调色板的索引P也可能是实际的RGB|q将Ҏ囑փ信息头中的位深度值来军_?/font>




构g详解

1. 位图文g?/font>

位图文g头包含有关于文gcd、文件大、存放位|等信息Q在Windows 3.0以上版本的位图文件中用BITMAPFILEHEADERl构来定义:

typedef struct tagBITMAPFILEHEADER { /* bmfh */

UINT bfType;
DWORD bfSize;
UINT bfReserved1;
UINT bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER;

 

其中Q?/font>
 

bfType

说明文g的类?Q该值必需?x4D42Q也是字符'BM'。我们不需要判断OS/2的位图标识,q么做现在来看似乎已l没有什么意义了Q而且如果要支持OS/2的位图,E序变得很J琐。所以,在此只徏议你?BM'标识Q?/p>

bfSize

说明文g的大,用字节ؓ单位

bfReserved1

保留Q必设|ؓ0

bfReserved2

保留Q必设|ؓ0

bfOffBits

说明从文件头开始到实际的图象数据之间的字节的偏U量。这个参数是非常有用的,因ؓ位图信息头和调色板的长度会根据不同情况而变化,所以你可以用这个偏UdD速的从文件中dC数据?/p>

2. 位图信息?/strong>

? 图信息用BITMAPINFOl构来定义,它由位图信息?bitmap-information header)和彩色表(color table)l成Q前者用BITMAPINFOHEADERl构定义Q后者用RGBQUADl构定义。BITMAPINFOl构h如下形式Q?/font>

typedef struct tagBITMAPINFO { /* bmi */

BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO;

 

其中Q?/font>
 

bmiHeader

说明BITMAPINFOHEADERl构Q其中包含了有关位图的尺寸及位格式等信息

bmiColors

说明彩色表RGBQUADl构的阵列,其中包含索引囑փ的真实RGB倹{?/p>

BITMAPINFOHEADERl构包含有位图文件的大小、压~类型和颜色格式Q其l构定义为:

typedef struct tagBITMAPINFOHEADER { /* bmih */

DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;

 

其中Q?/font>
 

biSize

? 明BITMAPINFOHEADERl构所需要的字数。注Q这个值ƈ不一定是BITMAPINFOHEADERl构的尺寸,它也可能是sizeof (BITMAPV4HEADER)的|或是sizeof(BITMAPV5HEADER)的倹{这要根据该位图文g的格式版本来军_Q不q,q在的? 冉|看,l大多数的BMP囑փ都是BITMAPINFOHEADERl构的(可能是后两者太新的~故?-Q?/p>

biWidth

说明图象的宽度,以象素ؓ单位

biHeight

? 明图象的高度Q以象素为单位。注Q这个值除了用于描q图像的高度之外Q它q有另一个用处,是指明该图像是倒向的位图,q是正向的位图。如果该值是一个正 敎ͼ说明囑փ是倒向的,如果该值是一个负敎ͼ则说明图像是正向的。大多数的BMP文g都是倒向的位图,也就是时Q高度值是一个正数。(注:当高度值是一? 负数Ӟ正向囑փQ,囑փ不能被压羃Q也是说biCompression成员不能是BI_RLE8或BI_RLE4Q?/p>

biPlanes

为目标设备说明位面数Q其值将L被设?

biBitCount

说明比特?象素Q其gؓ1???6?4、或32

biCompression

说明图象数据压羃的类型。其值可以是下述g一Q?/font>
BI_RGBQ没有压~;
BI_RLE8Q每个象?比特的RLE压羃~码Q压~格式由2字节l成(重复象素计数和颜色烦?Q?
BI_RLE4Q每个象?比特的RLE压羃~码Q压~格式由2字节l成
BI_BITFIELDSQ每个象素的比特由指定的掩码军_?br />

biSizeImage

说明图象的大,以字节ؓ单位。当用BI_RGB格式Ӟ可设|ؓ0

biXPelsPerMeter

说明水^分L率,用象?cC?/font>

biYPelsPerMeter

说明垂直分L率,用象?cC?/font>

biClrUsed

说明位图实际使用的彩色表中的颜色索引敎ͼ设ؓ0的话Q则说明使用所有调色板)

biClrImportant

说明对图象显C有重要影响的颜色烦引的数目Q如果是0Q表C都重要?/p>

现就BITMAPINFOHEADERl构作如下说明:

(1) 彩色表的定位

应用E序可用存储在biSize成员中的信息来查扑֜BITMAPINFOl构中的彩色表,如下所C:

pColor = ((LPSTR) pBitmapInfo + (WORD) (pBitmapInfo->bmiHeader.biSize))

(2) biBitCount

biBitCount=1 表示位图最多有两种颜色Q缺省情况下是黑色和白色Q你也可以自己定义这两种颜色。图像信息头装调色板中将有两个调色板,UCؓ索引0和烦?。图象数据阵列中的每一位表CZ个象素。如果一个位?Q显C时׃用烦?的RGB|如果位是1Q则使用索引1的RGB倹{?/font>

biBitCount=4 ? CZ图最多有16U颜艌Ӏ每个象素用4位表C,q用q?位作为彩色表的表Ҏ查找该象素的颜色。例如,如果位图中的W一个字节ؓ0x1FQ它表示有两个象 素,W一象素的颜色就在彩色表的第2表项中查找,而第二个象素的颜色就在彩色表的第16表项中查找。此Ӟ调色板中~省情况下会?6个RGBV对应于 索引0到烦?5?/font>

biBitCount=8 表示位图最多有256U颜艌Ӏ每个象素用8位表C,q用q?位作为彩色表的表Ҏ查找该象素的颜色。例如,如果位图中的W一个字节ؓ0x1FQ这个象素的颜色在彩色表的W?2表项中查找。此Ӟ~省情况下,调色板中会有256个RGB,对应于烦?到烦?55?/font>

biBitCount=16 表示位图最多有216U? 颜色。每个色素用16位(2个字节)表示。这U格式叫作高彩色Q或叫增强型16位色Q或64K艌Ӏ它的情冉|较复杂,当biCompression成员? 值是BI_RGBӞ它没有调色板?6位中Q最低的5位表C色分量,中间?位表C绿色分量,高的5位表C红色分量,一共占用了15位,最高的一位保 留,设ؓ0。这U格式也被称?55 16位位图。如果biCompression成员的值是BI_BITFIELDSQ那么情况就复杂了,首先是原来调色板的位|被三个DWORD变量占据Q? UCؓU、绿、蓝掩码。分别用于描q红、绿、蓝分量?6位中所占的位置。在Windows 95Q或98Q中Q系l可接受两种格式的位域:555?65Q在555格式下,U、绿、蓝的掩码分别是Q?x7C00?x03E0?x001FQ? ?65格式下,它们则分别ؓQ?xF800?x07E0?x001F。你在读取一个像素之后,可以分别用掩码“与”上像素|从而提取出惌的颜? 分量Q当然还要再l过适当的左右移操作Q。在NTpȝ中,则没有格式限Ӟ只不q要求掩码之间不能有重叠。(注:q种格式的图像用v来是比较ȝ的,? q因为它的显C效果接q于真彩Q而图像数据又比真彩图像小的多Q所以,它更多的被用于游戏YӞ?/font>

biBitCount=24 表示位图最多有224U颜艌Ӏ这U位图没有调色板QbmiColors成员寸?Q,在位数组中,?个字节代表一个象素,分别对应于颜色R、G、B?/font>

biBitCount=32 表示位图最多有232U? 颜色。这U位囄l构?6位位囄构非常类|当biCompression成员的值是BI_RGBӞ它也没有调色板,32位中?4位用于存? RGB|序是:最高位—保留,U?位、绿8位、蓝8位。这U格式也被成?88 32位图。如? biCompression成员的值是BI_BITFIELDSӞ原来调色板的位置被三个DWORD变量占据Q成为红、绿、蓝掩码Q分别用于描q红? lѝ蓝分量?2位中所占的位置。在Windows 95(or 98)中,pȝ只接?88格式Q也是说三个掩码的值将只能是:0xFF0000?xFF00?xFF。而在NTpȝ中,你只要注意掩码之间不 生重叠就行。(注:q种囑փ格式比较规整Q因为它是DWORD寚w的,所以在内存中进行图像处理时可进行汇~的代码优化(单)Q?/font>

(3) ClrUsed

BITMAPINFOHEADER l构中的成员ClrUsed指定实际使用的颜色数目。如果ClrUsed讄?Q位图用的颜色数目q于biBitCount成员中的数目。请注意Q? 如果ClrUsed的g是可用颜色的最大值或不是0Q则在编E时应该注意调色板尺寸的计算Q比如在4位位图中Q调色板的缺省尺寸应该是 16Qsizeof(RGBQUAD)Q但是,如果ClrUsed的g?6或者不?Q那么调色板的尺寸就应该是ClrUsedQsizeof (RGBQUAD)?/font>

(4) 图象数据压羃

?BI_RLE8Q?/strong>每个象素?比特的RLE压羃~码Q可使用~码方式和绝Ҏ式中的Q何一U进行压~,q两U方式可在同一q图中的M地方使用?/font>

~码方式Q由2个字节组成,W一个字节指定用相同颜色的象素数目Q第二个字节指定使用的颜色烦引。此外,q个字节对中的第一个字节可讄?Q联合用第二个字节的DC:

W二个字节的gؓ0Q行的结束?
W二个字节的gؓ1Q图象结束?
W二个字节的gؓ2Q其后的两个字节表示下一个象素从当前开始的水^和垂直位|的偏移量?

l对方式Q? W一个字节设|ؓ0Q而第二个字节讄?x03?xFF之间的一个倹{在q种方式中,W二个字节表C在这个字节后面的字节敎ͼ每个字节包含单个象素 的颜色烦引。压~数据格式需要字边界(word boundary)寚w。下面的例子是用16q制表示?-位压~图象数据:

03 04 05 06 00 03 45 56 67 00 02 78 00 02 05 01 02 78 00 00 09 1E 00 01
q些压羃数据可解释ؓ Q?/font>

压羃数据 

扩展数据

03 04 04 04 04 
05 06 06 06 06 06 06 
00 03 45 56 67 00 45 56 67 
02 78 78 78 
00 02 05 01 从当前位|右U?个位|后向下UM?/font>
02 78 78 78 
00 00 行结?/font>
09 1E 1E 1E 1E 1E 1E 1E 1E 1E 1E 
00 01 RLE~码图象l束 

?BI_RLE4Q?/font>

~码方式Q由2个字节组成,W一个字节指定象素数目,W二个字节包含两U颜色烦引,一个在?位,另一个在?位。第一个象素用高4位的颜色索引Q第二个使用?位的颜色索引Q第3个用高4位的颜色索引Q依此类推?/font>

l对方式Q这个字节对中的W一个字节设|ؓ0Q第二个字节包含有颜色烦引数Q其后箋字节包含有颜色烦引,颜色索引存放在该字节的高、低4位中Q一个颜色烦引对应一个象素。此外,BI_RLE4也同栯合用第二个字节中的DC:

W二个字节的gؓ0Q行的结束?
W二个字节的gؓ1Q图象结束?
W二个字节的gؓ2Q其后的两个字节表示下一个象素从当前开始的水^和垂直位|的偏移量?

下面的例子是?6q制数表C的4-位压~图象数据:

03 04 05 06 00 06 45 56 67 00 04 78 00 02 05 01 04 78 00 00 09 1E 00 01

q些压羃数据可解释ؓ Q?/font>

压羃数据

扩展数据

03 04 0 4 0
05 06 0 6 0 6 0 
00 06 45 56 67 00 4 5 5 6 6 7 
04 78 7 8 7 8 
00 02 05 01 从当前位|右U?个位|后向下UM?/font>
04 78 7 8 7 8 
00 00 行结?/font>
09 1E 1 E 1 E 1 E 1 E 1 
00 01 RLE图象l束 

3. 彩色?/font>

? 色表包含的元素与位图所h的颜色数相同Q象素的颜色用RGBQUADl构来定义。对?4-位真彩色图象׃使用彩色表(同样也包?6位、和32位位 图)Q因Z图中的RGB值就代表了每个象素的颜色。彩色表中的颜色按颜色的重要性排序,q可以辅助显C驱动程序ؓ不能昄_多颜色数的显C备显C彩 色图象。RGBQUADl构描述由R、G、B相对强度l成的颜Ԍ定义如下Q?/font>

typedef struct tagRGBQUAD { /* rgbq */

BYTE rgbBlue;
BYTE rgbGreen;
BYTE rgbRed;
BYTE rgbReserved;
} RGBQUAD;

 

其中Q?/font>
 

rgbBlue

指定蓝色强度

rgbGreen

指定l色强度

rgbRed

指定U色强度

rgbReserved

保留Q设|ؓ0

4. 位图数据

? 跟在彩色表之后的是图象数据字节阵列。图象的每一扫描行由表示图象象素的连l的字节l成Q每一行的字节数取决于图象的颜色数目和用象素表C的图象宽度。扫 描行是由底向上存储的Q这是_阵列中的W一个字节表CZ囑ַ下角的象素,而最后一个字节表CZ囑֏上角的象素。(只针对与倒向DIBQ如果是正向 DIBQ则扫描行是由顶向下存储的)Q倒向DIB的原点在囑փ的左下角Q而正向DIB的原点在囑փ的左上角。同Ӟ每一扫描行的字节数必需?的整倍数Q? 也就是DWORD寚w的。如果你想确保图像的扫描行DWORD寚wQ可使用下面的代码:

(((width*biBitCount)+31)>>5)<<2

5. 参考书?/strong>

《图象文件格?上、下)—Windows~程?br />《图像文件格式大全?br />《Programming Windows by Charles Petzold?br />

6. 相关站点

各种格式Qhttp://www.wotsit.org/
各种格式Qhttp://www.csdn.net/
位图格式Qhttp://www.cica.indiana.edu/graphics/image_specs/bmp.format.txt

〈完?br />YZ 2000-8-13 13:11

 
每个象素?比特的RLE压羃~码Q同样也可用编码方式和l对方式中的M一U进行压~,q两U方式也可在同一q图中的M地方使用。这两种方式是:

蓝色q默 2007-09-21 10:09 发表评论
]]>
DOMtab的基本用方法以及下载地址和完整演C?/title><link>http://www.aygfsteel.com/jdo/articles/140690.html</link><dc:creator>蓝色q默</dc:creator><author>蓝色q默</author><pubDate>Tue, 28 Aug 2007 14:45:00 GMT</pubDate><guid>http://www.aygfsteel.com/jdo/articles/140690.html</guid><wfw:comment>http://www.aygfsteel.com/jdo/comments/140690.html</wfw:comment><comments>http://www.aygfsteel.com/jdo/articles/140690.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jdo/comments/commentRss/140690.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jdo/services/trackbacks/140690.html</trackback:ping><description><![CDATA[ <div id="wmqeeuq" class="entry"> <p> <strong>一.什么是DOMtab</strong> <br /> DOMtab是一个用javascipt制作的通用可扩展的tab切换昄隐藏内容快的web控g?/p> <p> <strong>?怎么使用DOMtab</strong> <br /> 1.在页面的 </p> <div id="wmqeeuq" class="hl-surround"> <ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)"> <li id="wmqeeuq" class="hl-firstline"><head></head></li> </ol> </div> <p>区域加上</p> <div id="wmqeeuq" class="hl-surround"> <ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)"> <li id="wmqeeuq" class="hl-firstline"><script type="text/javascript" src="domtab.js"></script></li> </ol> </div> <p>2.在页面主体的 </p> <div id="wmqeeuq" class="hl-surround"> <ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)"> <li id="wmqeeuq" class="hl-firstline"><body></body></li> </ol> </div> <p>部分加上</p> <div id="wmqeeuq" class="hl-surround"> <ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)"> <li id="wmqeeuq" class="hl-firstline"><div class="domtab"></li> <li> <ul class="domtabs"></li> <li> <li><a href="#t1">Test 1</a></li></li> <li> <li><a href="#t2">Test 2</a></li> [idea] [idea] </li> <li>[... and so on ...]</li> <li> </ul></li> <li> <div></li> <li> <h2><a name="t1" id="t1">Proof 1</a></h2></li> <li> <p>Test to prove that more than one menu is possible</p></li> <li> <p><a href="#top">back to menu</a></p></li> <li> </div></li> <li> <div></li> <li> <h2><a name="t2" id="t2">Proof 2</a></h2></li> <li> <p>Test to prove that more than one menu is possible</p></li> <li> <p><a href="#top">back to menu</a></p></li> <li> </div></li> <li>[... and so on ...]</li> <li></div></li> </ol> </div> <p> <br /> 然后定义各个class的样式就可以了,你也可以加class定义样式Q但是代码的l构不能变化<br /> 3.更改javascript中控件的属?br /> tabClass:’domtab? //目标区域的class名称<br /> listClass:’domtabs? // 列表菜单的class名称<br /> activeClass:’active? // 菜单Ȁzȝ态下的class名称<br /> contentElements:’div? // 循环内容区域的元素名U?br /> backToLinks:/#top/, // 讄q回剙的参?br /> printID:’domtabprintview? // 昄所有区域内容的id名称<br /> showAllLinkText:’show all content? // 昄所有区域的文字名称</p> <p> <strong>?增加向前向后按钮</strong> </p> <p>1.在区域的起始class上多增加一个doprevnext</p> <div id="wmqeeuq" class="hl-surround"> <ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)"> <li id="wmqeeuq" class="hl-firstline"><div class="domtab doprevnext"></li> <li> <ul class="domtabs"></li> <li> <li><a href="#t1">Test 1</a></li></li> <li> <li><a href="#t2">Test 2</a></li></li> <li> <li><a href="#t3">Test 3</a></li></li> <li> <li><a href="#t4">Test 4</a></li></li> <li> </ul></li> <li> [... ad nauseam...]</li> <li></div></li> </ol> </div> <p>2.在页面里面加上下列代?/p> <div id="wmqeeuq" class="hl-surround"> <ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)"> <li id="wmqeeuq" class="hl-firstline"><ul class="prevnext"></li> <li> <li class="prev"><a href="#">previous</a></li></li> <li> <li class="next"><a href="#">next</a></li></li> <li> </ul></li> </ol> </div> <p>3.javascript里面的属性定?/p> <div id="wmqeeuq" class="hl-surround"> <ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)"> <li id="wmqeeuq" 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 id="wmqeeuq" class="hl-surround"> <ol class="hl-main ln-show" title="Double click to hide line number." ondblclick="linenumber(this)"> <li id="wmqeeuq" class="hl-firstline"><script type="text/javascript"></li> <li> document.write('<style type="text/css">'); </li> <li> document.write('div.domtab div{display:none;}<');</li> <li> document.write('/s'+'tyle>'); </li> <li></script></li> </ol> </div> <p> <strong>?下蝲以及演示</strong> <br /> <a title="http://onlinetools.org/tools/domtabdata/domtab.zip" target="_blank">下蝲DOMtab version 3.1415927</a> <br /> <a title="http://onlinetools.org/tools/domtabdata/" target="_blank">DOMtab演示</a> </p> </div> <img src ="http://www.aygfsteel.com/jdo/aggbug/140690.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jdo/" target="_blank">蓝色q默</a> 2007-08-28 22:45 <a href="http://www.aygfsteel.com/jdo/articles/140690.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用DIV+Javascript实现标签功能http://www.aygfsteel.com/jdo/articles/140411.html蓝色q默蓝色q默Tue, 28 Aug 2007 04:47:00 GMThttp://www.aygfsteel.com/jdo/articles/140411.htmlhttp://www.aygfsteel.com/jdo/comments/140411.htmlhttp://www.aygfsteel.com/jdo/articles/140411.html#Feedback1http://www.aygfsteel.com/jdo/comments/commentRss/140411.htmlhttp://www.aygfsteel.com/jdo/services/trackbacks/140411.html
  现在很多|站都用C标签的切换功能,新浪、迅L|站都有Q应该说用很很泛滥了。其? 标签功能是WindowsE序中的一U功能,在Delphi或VB{WindowsE序开的环境中Q很Ҏp创徏各种漂亮而又功能强大的标{֊能,但在 Web开发中Q就没有q种便利了?/div>
  只需要销加改动,标签的数量可以自由添加,而无需要ؓ标签dIDQ实际上q个功能除了用到Div、Javascript之后Q很重要的是要用到CSS样式?/div>
 
 
?

   首先我们要确定我们要做什么,我们要做成一个带三个标签的区??)Q点L{标{ֈ表的其中一个标{,内容区域会根据当前点ȝ标签昄不同的内 宏V按照我们一般的做法是每一个标{֯应一个内容区域,l每个内容区域增加一个id属性,然后为每一个标{添加一个属性,像q样Q?/div>
 
<div>   
 
<div>   
  
<div id="label1" onmousemove="dosomething()">label1<div>   
  
<div id="label2" onmousemove="dosomething()">label2<div>   
  
<div id="label2" onmousemove="dosomething()">label2<div>   
 
</div>   
 
<div>   
  
<div id="content1">W一个label的内?/span></div>   
  
<div id="content2">W一个labe2的内?/span></div>   
  
<div id="content2">W一个labe2的内?/span></div>   
 
<div>     
</div>  
     你可能没有意识到q种办法会有什么问题,当一个页面有非常多的标签块的话,我们不得不面一个问题,那就是id的命名问题,我们要为每一个内容区域命 名,q样不仅增加了代码量Q也增加了javascript~写的难度,我们不可能ؓ每一个标{֝写一堆javascriptQ就我? javascript写成一个函数或者一个类Q我们也会而另一个问题,是调用的时候会有一大堆的参敎ͼ因ؓ你需要将q个id传送过厅Rƈ且,很容易因 Zh为的疏忽造成错误?/div>
  下面Q来看看我是如何实现q个功能的吧Q可能不是最好的ҎQ如果你有更好的ҎQ希望你能告诉我Q让我们一赯步?/div>
     首先Q我们要做的是写好基本的html代码Q代码如下:
 
<html>   
<head>   
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />   
</head>   
     
<body>   
<ul id="Label">   
 
<!--我们第一个标{背景色设|红Ԍ因ؓ默认昄的是W一个标{内容-->   
 
<li class="CurrentLabel" style="background-color: red">标签1</li>   
 
<li>标签2</li>   
 
<li>标签3</li>   
</ul>   
<div id="Container">   
    
<div>q时里是标签1对应的内?/span></div>   
    
<!--因ؓ默认是不昄的,所以要display属性设|ؓnone-->   
    
<div style="display: none">q时里是标签2对应的内?/span></div>   
    
<div style="display: none" class="Content3">q时里是标签3对应的内?/span></div>   
</div>   
</body>   
</html> 
   
    写好基本html代码后,我们q需要做一w要的工作Q那是css样式Q因为li如果没有css样式控制Q标{ְ会以列表的Ş式出玎ͼ基本的CSS样式代码如下Q?/div>
 
 
<style type="text/css">    
 #Label li    
 
{    
  
/*讄ID为Label的元素下所有li元素样式Q主要是要设|float:leftq个属性,q样才能li元素排成一排;同时讄了list-style:noneq个属性,目的是防止li元素出现实心圆点*/   
  margin-left
: 1px;    
  padding
: 3px;    
  width
: 40px;    
  background-color
:#94A5F8;    
  float
:left;    
  list-style
:none;    
  cursor
:pointer;    
 
}
    
</style>    
   
   下面Q我们将要进行最重要的一环了Q就是javascriptQ看C里,你可能会问,Z么标{li元素没有事g呢?如何实现标签的切换呢Q这是因? 我考虑了另一个问题,如果我们需要ؓ每一个标{添加一个事件的话,实是一件很ȝ的事情,而且当标{֝多了的时候,׃增加代码量,所以我考虑使用动? d属性的方式为每一个标{添加属性?div class="code_title"> 
 
function LabelAddEvent()    
 
{    
  
var labels = document.getElementById("Label").childNodes;        //获取ID为Label无素下的所有子节点QchildNodes是DOM的一个属性   ?/span>
  //Ҏ有子节点q行循环Q增加onmouseover事gQ也可以Ҏ需要添加onclick事g    
  for(var iLoop = 0; iLoop < labels.length; iLoop ++)    
  
{    
   
var label = labels[iLoop];    
   
if ("LI" == label.nodeName)   //只处理LI的DOM节点Q目的是Z兼容FirefoxQ因为Firefox会把I格与换行与当成一个节点处理   ?/span>
   {    
    label.value 
= iLoop;        //为每一个标{value赋上当前的烦引,当点L{时候不用@环标{ְ知道是哪一个标{了    
    label.onmouseover = function()    
    
{    
     ChangeLabel(
this);          //调用ChangeLabel函数Qƈ把当前对象传q去    
    }
;    
   }
    
  }
    
 }
    
  然后Q我们在html늚最后面Q调用LabelAddEventq个函数Q即可以为所有标{添加函CQ是不是很简z,当我们有很多标签块的时候,׃必要为每个标{֝d事g了,下面我们来看看ChangeLabelq个函数Q?br /> 
 
function ChangeLabel(oCur)    
 
{    
  
//获取所有的内容元素子节点   ?/span>
  var containers = document.getElementById("Container").childNodes;    
 
//获取所有的标签    
  var labels = document.getElementById("Label").childNodes;    
  
for(var iLoop = 0; iLoop < containers.length; iLoop ++)    
  
{    
   
var container = containers[iLoop];       
   
var label = labels[iLoop];    
   
//Ҏ索引是否为li元素的value值来判断是否为当前标{   ?/span>
   var current = iLoop == oCur.value;      
   
if ("DIV" == container.nodeName) container.style.display = current ? "block" : "none";    
   
if ("LI" == label.nodeName) label.style.backgroundColor = current ? "red" : "#94A5F8";    
  }
    
 }
  

   主要代码是q么多了Q是不是很简z呢Q当有很多个标签块的候,你就会发现这个方法的优势了,事实下,我们q可以简单修改一下javascript? 码,实现多个标签块在一个页面中的功能,接下来我准备l合Xml及Xslt写一个根据xml配置的多标签块的教程Q如果你觉得有什么更好的Ҏ可以实现Q? 请你与我联系Q让我们共同q步?/p>

  
  版权所有©ConisQ复制或者{载请保留此信息,M人未l许可,不得擅自本文发布作为商业用途?br />  更多内容更多_ֽh讉Khttp://www.conis.cn


蓝色q默 2007-08-28 12:47 发表评论
]]>tomcat下中文的d解决http://www.aygfsteel.com/jdo/articles/139346.html蓝色q默蓝色q默Sat, 25 Aug 2007 16:03:00 GMThttp://www.aygfsteel.com/jdo/articles/139346.htmlhttp://www.aygfsteel.com/jdo/comments/139346.htmlhttp://www.aygfsteel.com/jdo/articles/139346.html#Feedback0http://www.aygfsteel.com/jdo/comments/commentRss/139346.htmlhttp://www.aygfsteel.com/jdo/services/trackbacks/139346.html(一)    JSP面上是中文Q但是看的是后是qQ?br />解决的办法就是在JSP面的编码的地方<%@ page language="java" contentType="text/html;charset=GBK" %>Q因为Jsp转成Java文g时的~码问题Q默认的话有的服务器是ISO-8859-1Q如果一个JSP中直接输入了中文QJsp把它当作ISO8859-1来处理是肯定有问题的Q这一点,我们可以通过查看Jasper所生成的Java中间文g来确?br />(?    当用Request对象获取客户提交的汉字代码的时候,会出Cؕ码:
解决的办法是Q要配置一个filter,也就是一个Servelet的过滤器Q代码如下:
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;

/**
 * Example filter that sets the character encoding to be used in parsing the
 * incoming request
 */
public class SetCharacterEncodingFilter implements Filter {

    /**
     * Take this filter out of service.
     */
    public void destroy() {
    }
    /**
     * Select and set (if specified) the character encoding to be used to
     * interpret request parameters for this request.
     */
    public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain chain)throws IOException, ServletException {

    request.setCharacterEncoding("GBK");

    // 传递控制到下一个过滤器
    chain.doFilter(request, response);
    }

    public void init(FilterConfig filterConfig) throws ServletException {
    }
}
配置web.xml
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>SetCharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
如果你的q是出现q种情况的话你就往下看看是不是你出CW四中情况,你的Form提交的数据是不是用get提交的,一般来说用post提交的话是没有问题的Q如果是的话Q你q看第四中解决的办法?br />q有是对含有汉字字W的信息q行处理Q处理的代码是:
package dbJavaBean;

public class CodingConvert
{   
 public CodingConvert()
 {
  //
 }
 public String toGb(String uniStr){
     String gbStr = "";
     if(uniStr == null){
   uniStr = "";
     }
     try{
   byte[] tempByte = uniStr.getBytes("ISO8859_1");
   gbStr = new String(tempByte,"GB2312");
     }
  catch(Exception ex){
    }
     return gbStr;
 }
   
 public String toUni(String gbStr){
     String uniStr = "";
     if(gbStr == null){
   gbStr = "";
     }
     try{
   byte[] tempByte = gbStr.getBytes("GB2312");
   uniStr = new String(tempByte,"ISO8859_1");
     }catch(Exception ex){
    }
    return uniStr;
 }
}
你也可以在直接的转换Q首先你获取的字符串用ISO-8859-1q行~码Q然后将q个~码存放C个字节数l中Q然后将q个数组转化成字W串对象可以了Q例如:
String str=request.getParameter(“girl?;
Byte B[]=str.getBytes(“ISO-8859-1?;
Str=new String(B);
通过上述转换的话Q提交的M信息都能正确的显C?br />(?    在Formgeth在服务端用request. getParameter(“name?时返回的是ؕ码;按tomcat的做法设|Filter也没有用或者用request.setCharacterEncoding("GBK");也不用问题是出在处理参C递的Ҏ上:如果在servlet中用doGet(HttpServletRequest request, HttpServletResponse response)Ҏq行处理的话前面即是写了:
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK");
也是不v作用的,q回的中文还是ؕ码!Q!如果把这个函数改成doPost(HttpServletRequest request, HttpServletResponse response)一切就OK了?br />同样Q在用两个JSP面处理表单输入之所以能昄中文是因为用的是postҎ传递的Q改成getҎ依旧不行?br />由此可见在servlet中用doGet()Ҏ或是在JSP中用getҎq行处理要注意。这毕竟涉及到要通过览器传递参C息,很有可能引v常用字符集的冲突或是不匹配?br />解决的办法是Q?br />1) 打开tomcat的server.xml文gQ找到区块,加入如下一行: 
URIEncoding=”GBK”?br />完整的应如下Q?br /><Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="GBK"/> 

2)重启tomcat,一切OK?br />需要加入的原因大家可以ȝI?TOMCAT_HOME/webapps/tomcat-docs/config/http.html下的q个文g可以知道原因了。需要注意的是:q个地方如果你要是用UTF-8的时候在传递的q程中在Tomcat中也是要出现q的情况,如果不行的话换别的字符集?br />
(?    JSP面上有中文Q按钮上面也有中文,但是通过服务器查看页面的时候出Cؕ码:
     解决的办法是Q首先在JSP文g中不应该直接包含本地化的消息文本Q而是应该通过<bean:message>标签从Resource Bundle中获得文本。应该把你的中文文本攑ֈApplication.properties文g中,q个文g攑֜WEB-INF/classes/*下,例如我在面里有姓名Q年龄两个label,我首先就是要Z个Application.propertiesQ里面的内容应该是name=”姓名” age=”年龄?然后我把q个文g攑ֈWEB-INF/classes/properties/下,接下来根据Application.properties文gQ对他进行编码{化,创徏一个中文资源文Ӟ假定名字是Application_cn.properties。在JDK中提供了native2ascii命oQ他能够实现字符~码的{换。在DOS环境中找C攄Application.properties的这个文件的目录Q在DOS环境中执行一下命令,生成按GBK~码的中文资源文件Application_cn.propertiesQnative2ascii ?encoding gbk Application.properties Application_cn.properties执行以上命o以后生成如下内容的Application_cn.properties文gQname=\u59d3\u540d age=\u5e74\u9f84,在Struts-config.xml中配|:<message-resources parameter="properties.Application_cn"/>。到q一步,基本上完成了一大半Q接着你就要在JSP面上写<%@ page language="java" contentType="text/html;charset=GBK" %>,到名字的那个label是要?lt;bean:message key=”name?gt;,q样的化在页面上出现的时候就会出C文的姓名Q年龄这个也是一P按钮上汉字的处理也是同样的?br />(?    写入到数据库是ؕ码:
解决的方法:要配|一个filter,也就是一个Servelet的过滤器Q代码如同第二种时候一栗?br />如果你是通过JDBC直接链接数据库的时候,配置的代码如下:jdbc:mysql://localhost:3306/workshopdb?useUnicode=true&characterEncoding=GBKQ这样保证到数据库中的代码是不是q?br />如果你是通过数据源链接的化你不能按照q样的写法了Q首先你p写在配置文g中,在tomcat 5.0.19中配|数据源的地Ҏ在C:\Tomcat 5.0\conf\Catalina\localhostq个下面Q我建立的工E是workshopQ放|的目录是webapp下面,workshop.xml的配|文件如下:
<!-- insert this Context element into server.xml -->

<Context path="/workshop" docBase="workshop" debug="0"
reloadable="true" >

  <Resource name="jdbc/WorkshopDB"
               auth="Container"
               type="javax.sql.DataSource" />

  <ResourceParams name="jdbc/WorkshopDB">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>
    <parameter>
      <name>maxActive</name>
      <value>100</value>
    </parameter>
    <parameter>
      <name>maxIdle</name>
      <value>30</value>
    </parameter>

    
    <parameter>
      <name>maxWait</name>
      <value>10000</value>
    </parameter>

      <parameter>
     <name>username</name>
     <value>root</value>
    </parameter>
    <parameter>
     <name>password</name>
     <value></value>
    </parameter>

    <!-- Class name for mm.mysql JDBC driver -->
    <parameter>
       <name>driverClassName</name>
       <value>com.mysql.jdbc.Driver</value>
</parameter>
   <parameter>
      <name>url</name>
 <value><![CDATA[jdbc:mysql://localhost:3306/workshopdb?useUnicode=true&characterEncoding=GBK]]></value>
    </parameter>
  </ResourceParams>

</Context>
_体的地方要特别的注意,和JDBC直接链接的时候是有区别的Q如果你是配|正的化,当你输入中文的时候到数据库中是中文了,有一点要注意的是你在昄数据的页面也是要?lt;%@ page language="java" contentType="text/html;charset=GBK" %>q行代码的。需要注意的是有的前台的人员在写代码的是后用Dreamver写的Q写了一个Form的时候把他改成了一个jspQ这h一个地方要注意了,那就是在Dreamver中Action的提交方式是request的,你需要把他该q来Q因为在jsp的提交的q程中紧紧就是POST和GET两种方式Q但是这两种方式提交的代码在~码斚wq是有很大不同的Q这个在后面的地方进行说明?

以上是我在开发系l中解决中文的问题,不知道能不能解决大家的问题,旉匆忙Q没有及时完善,文笔也不是很好,有些地方估计是词不达意。大家可以给我意见,希望能共同进步?br />

蓝色q默 2007-08-26 00:03 发表评论
]]>
JAVA cookies用法http://www.aygfsteel.com/jdo/articles/138181.html蓝色q默蓝色q默Mon, 20 Aug 2007 08:38:00 GMThttp://www.aygfsteel.com/jdo/articles/138181.htmlhttp://www.aygfsteel.com/jdo/comments/138181.htmlhttp://www.aygfsteel.com/jdo/articles/138181.html#Feedback0http://www.aygfsteel.com/jdo/comments/commentRss/138181.htmlhttp://www.aygfsteel.com/jdo/services/trackbacks/138181.html 涉及login.jsp和login_do.jsp

1.先在login_do.jsp里面获取cookies代码如下
代码是加在登录成功的下面
Cookie cookie1=new Cookie("login_name",name);
                           键         ??br />Cookie cookie2=new Cookie("login_pass",pass)
值是从后面获取的
q个键是  login.jsp里面要用到的Qname是从login_do.jsp里面
d?br />cookie1.setMaxAge(60*60*24);讄cookie的有效时_单位是秒
q里是保存一?br />response.addCookie(cookie1);
response.addCookie(cookie2);
 把捕h的cookies加到响应里,q步必不可少
response.sendRedirect("index.jsp");
 //d成功转发的页?br />2.在login.jsp里面加代?br />Cookie[] cookie=request.getCookies();
String name="",pass="";
for(int i=0;i<cookie.length;i++){
 if(cookie[i].getName.equals("login_name"))
  name=cookie[i].getValue();
 if(cookie[i].getName.equals("login_pass"))
  pass=cookie[i].getValue();
}
在表单的变量那里加上q个可以了
<input name="name" value="<%=name %>" type="text" id="name">
<input name="pwd" value="<%=pwd %>" type="password" id="pwd2">

蓝色q默 2007-08-20 16:38 发表评论
]]>HttpServletRequest.getRequestURI()和HttpServletRequest.getRequestURL()区别是什? http://www.aygfsteel.com/jdo/articles/138098.html蓝色q默蓝色q默Mon, 20 Aug 2007 05:04:00 GMThttp://www.aygfsteel.com/jdo/articles/138098.htmlhttp://www.aygfsteel.com/jdo/comments/138098.htmlhttp://www.aygfsteel.com/jdo/articles/138098.html#Feedback0http://www.aygfsteel.com/jdo/comments/commentRss/138098.htmlhttp://www.aygfsteel.com/jdo/services/trackbacks/138098.html  request.getRequestURI() q回值类|/xuejava/requestdemo.jsp
  
  request.getRequestURL() q回值类|http://localhost:8080/xuejava/requestdemo.jsp 

 

附:

request.getContextPath() = /hboys
request.getLocalAddr() = 127.0.0.1
request.getPathInfo() = null
request.getPathTranslated() = null
request.getRemoteAddr() = 127.0.0.1
request.getRequestURI() = /hboys/
request.getScheme() = http
request.getServerName() = 127.0.0.1
request.getServletPath() = /index.jsp
request.getClass() = class org.apache.catalina.connector.RequestFacade
request.getHeaderNames() = org.apache.tomcat.util.http.NamesEnumerator@1ad0839
request.getLocale() = zh_CN
request.getLocales() = org.apache.catalina.util.Enumerator@f6f1b6
request.getParameterMap() = {}
request.getRequestURL() = http://127.0.0.1:8081/hboys/
request.getUserPrincipal() = null
request.getParameterNames() = java.util.Hashtable$EmptyEnumerator@1629e71
request.getRealPath("newsPub") = D:\workspace\hboys\WebRoot\newsPub

蓝色q默 2007-08-20 13:04 发表评论
]]>
Hibernate应用pd之六扚w处理?/title><link>http://www.aygfsteel.com/jdo/articles/137712.html</link><dc:creator>蓝色q默</dc:creator><author>蓝色q默</author><pubDate>Fri, 17 Aug 2007 15:12:00 GMT</pubDate><guid>http://www.aygfsteel.com/jdo/articles/137712.html</guid><wfw:comment>http://www.aygfsteel.com/jdo/comments/137712.html</wfw:comment><comments>http://www.aygfsteel.com/jdo/articles/137712.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jdo/comments/commentRss/137712.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jdo/services/trackbacks/137712.html</trackback:ping><description><![CDATA[ <a target="_blank" title="Hibernate应用pd之六扚w处理? >http://tech.it168.com/j/e/2006-09-25/200609251710239.shtml</a> <img src ="http://www.aygfsteel.com/jdo/aggbug/137712.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jdo/" target="_blank">蓝色q默</a> 2007-08-17 23:12 <a href="http://www.aygfsteel.com/jdo/articles/137712.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>javascript操作Select标记中options集合http://www.aygfsteel.com/jdo/articles/137341.html蓝色q默蓝色q默Thu, 16 Aug 2007 09:24:00 GMThttp://www.aygfsteel.com/jdo/articles/137341.htmlhttp://www.aygfsteel.com/jdo/comments/137341.htmlhttp://www.aygfsteel.com/jdo/articles/137341.html#Feedback0http://www.aygfsteel.com/jdo/comments/commentRss/137341.htmlhttp://www.aygfsteel.com/jdo/services/trackbacks/137341.htmloptions.add(option)Ҏ向集合里d一option对象Q?br />options.remove(index)ҎU除options集合中的指定;
options(index)或options.item(index)可以通过索引获取options集合的指定项Q?br />
    var selectTag = null//select标记
    var OPTONLENGTH = 10//每次填充option?/span>
    var colls = [];       //对select标记options的引?/span>

    window.onload 
= function(){
        selectTag 
= document.getElementById("SelectBox"); //获取select标记        
        colls = selectTag.options; //获取引用
        //initSelectBox();    //自初始化select.options
    };
    
    
//使用随机数填充select.options
    function initSelectBox(){
        
var random = 0 ;
        
var optionItem = null;
        
var item = null;
        
        
if(colls.length > 0 && isClearOption()){
             clearOptions(colls);
        }

        
for(var i=0;i<OPTONLENGTH;i++){
             
            random 
= Math.floor(Math.random()*9000)+1000;
            item 
= new Option(random,random);    //通过Option()构造函数创建option对象        
            selectTag.options.add(item); //d到options集合?/span>
        }    
        
        watchState();
    }
    
//d新option前是否清空当前options
    function isClearOption(){
        
return document.getElementById("chkClear").checked;
    }
    
//清空options集合
    function clearOptions(colls){
        
var length = colls.length;
        
for(var i=length-1;i>=0;i--){
            colls.remove(i);
        }
    }
    
//d一Ҏoption
    function addOption(){
        colls.add(createOption());
        lastOptionOnFocus(colls.length
-1);
        watchState();
    }
    
//创徏一个option对象
    function createOption(){
        
var random = Math.floor(Math.random()*9000)+1000;
        
return new Option(random,random);
    }
    
//删除options集合中指定的一option
    function removeOption(index){        
        
if(index >= 0){
            colls.remove(index);
            lastOptionOnFocus(colls.length
-1);
        }
        watchState();
    }
    
//获取当前选定的option索引
    function getSelectedIndex(){
        
return selectTag.selectedIndex;
    }
    
//获取options集合的L
    function getOptionLength(){
        
return colls.length;
    }
    
//获取当前选定的option文本
    function getCurrentOptionValue(index){
        
if(index >= 0)
            
return colls(index).value;
    }
    
//获取当前选定的option?/span>
    function getCurrentOptionText(index){
        
if(index >= 0)
            
return colls(index).text;
    }
    
//使用options集合中最后一获取焦?/span>
    function lastOptionOnFocus(index){
        selectTag.selectedIndex 
= index;
    }
    
//昄当select标记状?/span>
    function watchState(){
        
var divWatch = document.getElementById("divWatch");
        
var innerHtml="";
        innerHtml  
= "optionL:" + getOptionLength();
        innerHtml 
+= "<br/>当前烦?" + getSelectedIndex();
        innerHtml 
+= "<br/>当前Ҏ?" + getCurrentOptionText(getSelectedIndex());
        innerHtml 
+= "<br/>当前?" + getCurrentOptionValue(getSelectedIndex());
        divWatch.innerHTML 
= innerHtml;
        divWatch.align 
= "justify";
    }



蓝色q默 2007-08-16 17:24 发表评论
]]>
Java路径问题最l解x?/title><link>http://www.aygfsteel.com/jdo/articles/136791.html</link><dc:creator>蓝色q默</dc:creator><author>蓝色q默</author><pubDate>Tue, 14 Aug 2007 15:15:00 GMT</pubDate><guid>http://www.aygfsteel.com/jdo/articles/136791.html</guid><wfw:comment>http://www.aygfsteel.com/jdo/comments/136791.html</wfw:comment><comments>http://www.aygfsteel.com/jdo/articles/136791.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/jdo/comments/commentRss/136791.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/jdo/services/trackbacks/136791.html</trackback:ping><description><![CDATA[ <div> <strong> <font size="6">前言</font> </strong> </div> <div style="text-indent: 24pt;">Java的\径问题,非常难搞。最q的工作涉及到创建和d文g的工作,q里我就l大家彻底得解决Java路径问题?/div> <div style="text-indent: 24pt;">? ~写了一个方法,比ClassLoader.getResource(String 相对路径)Ҏ的能力更强。它可以接受?./”这L参数Q允许我们用相对路径来定位classpath外面的资源。这P我们可以用相对于 classpath的\径,定位所有位|的资源Q?/div> <div style="text-indent: 24pt;"> </div> <div> <strong> <font size="6">Java路径</font> </strong> </div> <div style="text-indent: 24pt;">Java中用的路径Q分ZU:l对路径和相对\径。具体而言Q又分ؓ四种Q?/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的前~/协议Q必LJava认识的。URL可以打开资源Q而URI则不行?/div> <div style="text-indent: 24pt;">URL和URI对象可以互相转换Q用各自的toURI(),toURL()Ҏ卛_Q?/div> <div> </div> <div> <strong> <font size="4">二、本地系l的l对路径</font> </strong> </div> <div>D:/java/eclipse32/workspace/jbpmtest3/bin/aaa.b</div> <div style="text-indent: 24pt;">Java.io包中的类Q需要用这UŞ式的参数?/div> <div style="text-indent: 24pt;">但是Q它们一般也提供了URIcd的参敎ͼ而URIcd的参敎ͼ接受的是URI样式的String。因此,通过URI转换Q还是可以把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/q个路径的相对\径。其中,bin是本目的classpath。所有的Java源文件编译后?class文g复制到这个目录中?/div> <div> </div> <div> </div> <div> <strong> <font size="4">四、相对于当前用户目录的相对\?/font> </strong> </div> <div>是相对于System.getProperty("user.dir")q回的\径?/div> <div style="text-indent: 24pt;">对于一般项目,q是目的根路径。对于JavaEE服务器,q可能是服务器的某个路径。这个ƈ没有l一的规范!</div> <div style="text-indent: 24pt;">所以,l对不要使用“相对于当前用户目录的相对\径”。然而:</div> <div> <strong> <span style="color: windowtext;">默认情况下,java.io 包中的类LҎ当前用户目录来分析相对\径名。此目录ql属?user.dir 指定Q通常?Java 虚拟机的调用目录?/span> </strong> </div> <div style="text-indent: 24.75pt;"> <span style="color: windowtext;">q就是说Q在使用java.io包中的类Ӟ最好不要用相对\径。否则,虽然在J2SE应用E序中可能还正常,但是CJ2EEE序中,一定会出问题!而且q个路径Q在不同的服务器中都是不同的Q?/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;">因此Q我们在使用相对路径Ӟ应当使用相对于当前classpath的相对\径?/div> <div style="text-indent: 24pt;">ClassLoadercȝgetResource(String name),<code><strong>getResourceAsStream</strong>(String name){方法,使用相对于当前项目的classpath的相对\径来查找资源?/code></div> <div style="text-indent: 24pt;">d属性文件常用到的ResourceBundlecȝgetBundle(String path)也是如此?/div> <div style="text-indent: 24pt;">? q查看ClassLoadercd其相关类的源代码Q我发现Q它实际上还是用了URI形式的绝对\径。通过得到当前classpath的URI形式的绝 对\径,构徏了相对\径的URI形式的绝对\径。(q个实际上是猜想Q因为JDK内部调用了SUN的源代码Q而这些代码不属于JDKQ不是开源的。)</div> <div> </div> <div> <strong> <font size="5">相对路径本质上还是绝对\?/font> </strong> </div> <div style="text-indent: 24pt;"> <strong> <span style="font-size: 15pt;">因此Q归根结底,</span> </strong> <strong> <span style="font-size: 15pt;">Java</span> </strong> <strong> <span style="font-size: 15pt;">本质上只能用绝对\径来L资源。所有的相对路径L资源的方法,都不q是一些便利方法。不q是</span> </strong> <strong> <span style="font-size: 15pt;">API</span> </strong> <strong> <span style="font-size: 15pt;">在底层帮助我们构Zl对路径Q从而找到资源的Q?/span> </strong> </div> <div> </div> <div> <strong> <font size="5">得到classpath和当前类的绝对\径的一些方?/font> </strong> </div> <div> <span>    </span>下面是一些得到classpath和当前类的绝对\径的一些方法。你可能需要用其中的一些方法来得到你需要的资源的绝对\径?/div> <div> <strong>1</strong> <strong>QFileTest.class.getResource("")</strong> </div> <div style="text-indent: 24pt;">得到的是当前cFileTest.class文g的URI目录。不包括自己Q?/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>QFileTest.<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;">QThread.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;">QFileTest.<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>QClassLoader.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应用E序中资源的d</font> </strong> </div> <div> <span>    </span>上文中说q,当前用户目录Q即相对于System.getProperty("user.dir")q回的\径?/div> <div style="text-indent: 24pt;">对于JavaEE服务器,q可能是服务器的某个路径Q这个ƈ没有l一的规范!</div> <div style="text-indent: 24pt;">而不是我们发布的Web应用E序的根目录Q?/div> <div style="text-indent: 24pt;">q样Q在Web应用E序中,我们l对不能使用相对于当前用L录的相对路径?/div> <div style="text-indent: 24pt;">在Web应用E序中,我们一般通过ServletContext.getRealPath("/")Ҏ得到Web应用E序的根目录的绝对\径?/div> <div style="text-indent: 24pt;">q样Q我们只需要提供相对于Web应用E序根目录的路径Q就可以构徏出定位资源的l对路径?/div> <div style="text-indent: 24pt;">q是我们开发Web应用E序时一般所采取的策略?/div> <div> </div> <div> <strong> <font size="6">通用的相对\径解军_?/font> </strong> </div> <div style="text-indent: 24pt;">Java中各U相对\径非常多Q不Ҏ使用Q非常容易出错。因此,我编写了一个便利方法,帮助更容易的解决相对路径问题?/div> <div> </div> <div> <strong> <font size="5">Web应用E序中用JavaSEq行的资源寻址问题</font> </strong> </div> <div style="text-indent: 24pt;">在JavaSEE序中,我们一般用classpath来作为存放资源的目的地。但是,在Web应用E序中,我们一般用classpath外面的WEB-INF及其子目录作源文件的存放地?/div> <div style="text-indent: 24pt;">在Web应用E序中,我们一般通过ServletContext.getRealPath("/")Ҏ得到Web应用E序的根目录的绝对\径。这P我们只需要提供相对于Web应用E序根目录的路径Q就可以构徏出定位资源的l对路径?/div> <div style="text-indent: 24pt;">Web应用E序Q可以作为Web应用E序q行发布和运行。但是,我们也常怼以JavaSE的方式来q行Web应用E序的某个类的mainҎ。或者,使用JUnit试。这都需要用JavaSE的方式来q行?/div> <div style="text-indent: 24pt;">q样Q我们就无法使用ServletContext.getRealPath("/")Ҏ得到Web应用E序的根目录的绝对\径?/div> <div style="text-indent: 24pt;">而JDK提供的ClassLoaderc,</div> <div style="text-indent: 24pt;">它的getResource(String name),<code><strong>getResourceAsStream</strong>(String name){方法,使用相对于当前项目的classpath的相对\径来查找资源?/code></div> <div style="text-indent: 24pt;">d属性文件常用到的ResourceBundlecȝgetBundle(String path)也是如此?/div> <div style="text-indent: 24pt;">它们都只能用相对\径来dclasspath下的资源Q无法定位到classpath外面的资源?/div> <div> <strong> <font size="4">Classpath外配|文件读取问?/font> </strong> </div> <div style="text-indent: 24pt;">如,我们使用试驱动开发的ҎQ开发Spring、Hibernate、iBatis{用配|文件的Web应用E序Q就会遇到问题?/div> <div style="text-indent: 24pt;">管Spring自己提供了FileSystemQ也是相对于user,dir目录Q来dWeb配置文g的方法,但是l究不是很方ѝ而且与WebE序中的代码使用方式不一_</div> <div>至于HibernateQiBatis更ȝ了!只有把配|文件移到classpath下,否则Ҏ不可能用测试驱动开发!</div> <div> </div> <div> <span>    </span>q怎么办?</div> <div> </div> <div> <strong> <font size="6">通用的相对\径解军_?/font> </strong> </div> <div style="text-indent: 24pt;">面对q个问题Q我军_~写一个助手类<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>Q提供一个便利方法[<strong>public</strong><strong>static</strong> URL getExtendResource(String relativePath)]。在Web应用E序{一切JavaE序中,需要定位classpath外的资源Ӟ都用这个助手类的便利方法,而不使用 Web应用E序Ҏ的ServletContext.getRealPath("/")Ҏ来定位资源?/div> <div> </div> <div> <strong> <font size="4">利用classpath的绝对\径,定位所有资?/font> </strong> </div> <div style="text-indent: 24pt;">q个便利Ҏ的实现原理,是“利用classpath的绝对\径,定位所有资源”?/div> <div style="text-indent: 24pt;">ClassLoadercȝgetResource("")Ҏ能够得到当前classpath的绝对\径,q是所有JavaE序都拥有的能力Q具有最大的适应性!</div> <div style="text-indent: 24pt;">而目前的JDK提供的ClassLoadercȝgetResource(String 相对路径)ҎQ只能接受一般的相对路径。这P使用ClassLoadercȝgetResource(String 相对路径)Ҏ只能定位到classpath下的资源?/div> <div style="text-indent: 24.1pt;"> <strong>如果Q它能够接受?./</strong> <strong>”这L参数Q允许我们用相对路径来定位classpath</strong> <strong>外面的资源,那么我们可以定位位|的资源Q?/strong> </div> <div style="text-indent: 24pt;">当然Q我无法修改ClassLoadercȝq个ҎQ于是,我编写了一个助手类ClassLoaderUtilc,提供了[<strong>public</strong><strong>static</strong> URL getExtendResource(String relativePath)]q个Ҏ。它能够接受带有?./”符L相对路径Q实C自由L资源的功能?/div> <div> </div> <div> <strong> <font size="6">通过相对classpath路径实现自由L资源的助手类的源代码Q?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 /> *  用来加蝲c,ClassPath下的资源文gQ属性文件等?br /> *  getExtendResource(StringrelativePath)ҎQ可以?./W号来加载ClassPath外部的资源?br /> *  <br /> * </span> <span style="color: rgb(128, 128, 128);">@author</span>  <span style="color: rgb(0, 128, 0);">蓝色q默 整理                    <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 />     * 加蝲JavacR 用全限定cd<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 />     * 得到cd载器<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的资源\径,q回文g的输入流<br />     * <br />     * @paramrelativePath必须传递资源的相对路径。是相对于classpath的\径。如果需要查找classpath外部的资源,需要?./来查?br />     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"> 文g输入?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的资源\径,q回属性对象,它是一个散列表<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);"> l对路径Q?/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);"><</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;">ClassLoaderUtilcȝpublic static URL getExtendResource(String relativePath)Q虽然很单,但是实可以解决大问题?/div> <div style="text-indent: 24pt;">不过q个Ҏq是比较陋的。我q想在未来有I时Q进一步增强它的能力。比如,增加Ant风格的匹配符。用**代表多个目录Q?代表多个字符Q?代表一个字W。达到Spring那样的能力,一ơ返回多个资源的URLQ进一步方便大家开发?/div> <div> </div> <div> <strong> <font size="4">ȝQ?/font> </strong> </div> <div>1Q尽量不要用相对于System.getProperty("user.dir")当前用户目录的相对\径。这是一颗定时炸弹,随时可能要你的命?/div> <div>2Q尽量用URI形式的绝对\径资源。它可以很容易的转变为URI,URLQFile对象?/div> <div>3Q? 量使用相对classpath的相对\径。不要用绝对\径。用上面ClassLoaderUtilcȝpublic static URL getExtendResource(String relativePath)Ҏ已经能够使用相对于classpath的相对\径定位所有位|的资源?/div> <div>4Q绝对不要用硬~码的绝对\径。因为,我们完全可以使用ClassLoadercȝgetResource("")Ҏ得到当前classpath的绝对\径?/div> <div style="text-indent: 24pt;">使用编码的l对路径是完全没有必要的Q它一定会让你ȝ很难看!E序无法移植!</div> <div style="text-indent: 24pt;">如果你一定要指定一个绝对\径,那么使用配置文gQ也比硬~码要好得多Q?/div> <div>当然Q我q是推荐你用程序得到classpath的绝对\径来D源的l对路径Q?/div> <br /> </div> <img src ="http://www.aygfsteel.com/jdo/aggbug/136791.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/jdo/" target="_blank">蓝色q默</a> 2007-08-14 23:15 <a href="http://www.aygfsteel.com/jdo/articles/136791.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">ξ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">ʡ</a>| <a href="http://" target="_blank">罭</a>| <a href="http://" target="_blank">̽</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ӥ̶</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ŷ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">˹</a>| <a href="http://" target="_blank">ƶ</a>| <a href="http://" target="_blank">ij</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ѷ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank">Զ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ԫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͨ</a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>