﻿<?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-wiflish-随笔分类-java</title><link>http://www.blogjava.net/wiflish/category/11012.html</link><description>Loving Life! Loving Coding!</description><language>zh-cn</language><lastBuildDate>Tue, 01 Apr 2008 10:34:46 GMT</lastBuildDate><pubDate>Tue, 01 Apr 2008 10:34:46 GMT</pubDate><ttl>60</ttl><item><title>JPA annotation</title><link>http://www.blogjava.net/wiflish/archive/2008/04/01/190053.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Tue, 01 Apr 2008 05:12:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2008/04/01/190053.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/190053.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2008/04/01/190053.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/190053.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/190053.html</trackback:ping><description><![CDATA[@Id的annotation只在属性上，将使用属性级别的annotation，忽略getter方法级别的annotation；<br />只要@Id的annotation在getter方法上，就将使用getter方法上的annotation，忽略属性级别的annotation。<br /><img src ="http://www.blogjava.net/wiflish/aggbug/190053.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2008-04-01 13:12 <a href="http://www.blogjava.net/wiflish/archive/2008/04/01/190053.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]Java中的内部类和匿名类</title><link>http://www.blogjava.net/wiflish/archive/2007/07/01/127344.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Sun, 01 Jul 2007 03:40:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2007/07/01/127344.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/127344.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2007/07/01/127344.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/127344.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/127344.html</trackback:ping><description><![CDATA[转：http://hi.baidu.com/chillll/blog/item/7b939444593b034e500ffe02.html<br /><br /><div class="cnt">提起Java内部类（<strong>Inner Class</strong>）可能很多人不太熟悉，实际上类似的概念在C++里也有，那就是嵌套类（<strong>Nested Class</strong>），
关于这两者的区别与联系，在下文中会有对比。内部类从表面上看，就是在类中又定义了一个类（下文会看到，内部类可以在很多地方定义），而实际上并没有那么
简单，乍看上去内部类似乎有些多余，它的用处对于初学者来说可能并不是那么显著，但是随着对它的深入了解，你会发现Java的设计者在内部类身上的确是用
心良苦。学会使用内部类，是掌握Java高级编程的一部分，它可以让你更优雅地设计你的程序结构。下面从以下几个方面来介绍：<br clear="all" /><ul><li><font size="+1"><strong>第一次见面</strong></font></li></ul>
   
<table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong>interface</strong><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> {<br />
    <font color="#0000ff"><strong>int</strong></font> value();<br />
}</p><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong>interface</strong> Destination {<br />
    <font color="#0000ff"><strong>String</strong></font> readLabel();<br />
}</p><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong>class</strong> Goods {<br />
    <font color="#0000ff"><strong>private</strong></font><strong>class</strong> Content implements <span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> {<br />
        <font color="#0000ff"><strong>private int</strong></font> i = 11;<br />
        <font color="#0000ff"><strong>public int</strong></font> value() { <br />
            <strong><font color="#0000ff">return</font></strong> i; <br />
         }<br />
     }</p><p class="unnamed1">    <font color="#0000ff"><strong>protected</strong></font><strong>class</strong> GDestination <strong><font color="#0000ff">implements</font></strong> Destination {<br />
        <font color="#0000ff"><strong>private</strong></font><font color="#cccccc"><strong><font color="#000000">String</font></strong></font> label;<br />
        <font color="#0000ff"><strong>private</strong></font> GDestination(<strong><font color="#0000ff">String</font></strong> whereTo) {<br />
            <font color="#0000ff"><strong>label</strong></font> = whereTo;<br />
         }<br />
        <font color="#0000ff"><strong>public</strong></font><strong>String</strong> readLabel() { <br />
            <font color="#0000ff"><strong>return</strong></font> label; <br />
         }<br />
     }</p><p class="unnamed1">    <font color="#0000ff"><strong>public</strong></font> Destination dest(<strong><font color="#0000ff">String</font></strong> s) {<br />
        <font color="#0000ff"><strong>return </strong></font><strong>new</strong> GDestination(s);<br />
     }<br />
    <font color="#0000ff"><strong>public</strong></font><strong><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span></strong> cont() {<br />
        <font color="#0000ff"><strong>return</strong></font><strong>new</strong> Content();<br />
     }<br />
}</p><p class="unnamed1"><font color="#0000ff"><strong>class</strong></font> TestGoods {<br />
    <font color="#0000ff"><strong>public</strong></font><strong><font color="#0000ff">static</font> void main</strong>(<strong><font color="#0000ff">String[]</font></strong> args) {<br />
         Goods p = <strong><font color="#0000ff">new</font></strong> Goods();<br />
        <span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> c = p.cont();<br />
         Destination d = p.dest("Beijing");<br />
     }<br />
} </p></td></tr></tbody></table>
     在
这个例子里类Content和GDestination被定义在了类Goods内部，并且分别有着protected和private修饰符来控制访问级
别。Content代表着Goods的内容，而GDestination代表着Goods的目的地。它们分别实现了两个接口Content和
Destination。在后面的main方法里，直接用 <span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> c和Destination d进行操作，你甚至连这两个内部类的名字都没有看见！这样，内部类的第一个好处就体现出来了——<strong><font color="#0000ff">隐藏你不想让别人知道的操作</font></strong>，也即封装性。 
<p align="left">     同时，我们也发现了在外部类作用范围之外得到内部类对象的第一个方法，那就是利用其外部类的方法创建并返回。上例中的cont()和dest()方法就是这么做的。那么还有没有别的方法呢？当然有，其语法格式如下：</p><table class="code" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1" align="left">outerObject=<strong><font color="#0000ff">new </font></strong>outerClass(Constructor Parameters);</p><p class="unnamed1" align="left">outerClass.innerClass innerObject=outerObject.new InnerClass(Constructor Parameters);</p></td></tr></tbody></table><p align="left">     注意在创建非静态内部类对象时，一定要先创建起相应的外部类对象。至于原因，也就引出了我们下一个话题——</p><ul><li><font size="+1"><strong>非静态内部类对象有着指向其外部类对象的引用</strong></font></li></ul><p>对刚才的例子稍作修改：</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1" align="left"><font color="#0000ff"><strong>public</strong></font><strong>class</strong> Goods {</p><p class="unnamed1" align="left">   <font color="#0000ff"><font color="#ff0000"><strong>private valueRate=2;</strong></font></font></p><p class="unnamed1" align="left">    <strong><font color="#0000ff">private</font> class </strong>Content<strong> implements </strong><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> {<br />
        <strong><font color="#0000ff">private int</font></strong> i = <font color="#ff0000"><strong>11*valueRate;</strong></font><br />
        <strong><font color="#0000ff">public int </font></strong>value() { <br />
            <font color="#0000ff"><strong>return</strong></font> i; <br />
         }<br />
     }</p><p class="unnamed1" align="left">    <strong><font color="#0000ff">protected</font> class</strong> GDestination <strong>implements</strong> Destination {<br />
        <strong><font color="#0000ff">private String</font></strong> label;<br />
        <font color="#0000ff"><strong>private</strong></font> GDestination(<strong><font color="#0000ff">String</font></strong> whereTo) {<br />
            <strong><font color="#0000ff">label</font></strong> = whereTo;<br />
         }<br />
        <strong><font color="#0000ff">public String</font></strong> readLabel() { <br />
            <font color="#0000ff"><strong>return</strong></font> label; <br />
         }<br />
     }</p><p class="unnamed1" align="left">    <font color="#0000ff"><strong>public</strong></font> Destination dest(<strong><font color="#0000ff">String</font></strong> s) {<br />
        <strong><font color="#0000ff">return</font> new</strong> GDestination(s);<br />
     }<br />
    <font color="#0000ff"><strong>public</strong></font><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> cont() {<br />
        <font color="#0000ff"><strong>return</strong></font><font color="#0000ff"><strong><font color="#000000">new</font></strong></font> Content();<br />
     }<br />
}</p></td></tr></tbody></table><p align="left"></p>
     修改的部分用蓝色显玖恕Ｔ谡饫镂颐歉鳪oods类增加了一个private成员变量valueRate，意义是货物的
价值系数，在内部类Content的方法value()计算价值时把它乘上。我们发现，value()可以访问valueRate，这也是内部类的第二个
好处——<strong><font color="#0000ff">一个内部类对象可以访问创建它的外部类对象的内容</font></strong>，
甚至包括私有变量！这是一个非常有用的特性，为我们在设计时提供了更多的思路和捷径。要想实现这个功能，内部类对象就必须有指向外部类对象的引用。
Java编译器在创建内部类对象时，隐式的把其外部类对象的引用也传了进去并一直保存着。这样就使得内部类对象始终可以访问其外部类对象，同时这也是为什
么在外部类作用范围之外向要创建内部类对象必须先创建其外部类对象的原因。 <p align="left">     有人会问，如果内部类里的一个成员变量与外部类的一个成员变量同名，也即外部类的同名成员变量被屏蔽了，怎么办？没事，Java里用如下格式表达外部类的引用：</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td class="unnamed1">outerClass.this</td></tr></tbody></table><p align="left">有了它，我们就不怕这种屏蔽的情况了。</p><ul><li><strong><font size="+1">静态内部类</font></strong></li></ul><p>    
和普通的类一样，内部类也可以有静态的。不过和非静态内部类相比，区别就在于静态内部类没有了指向外部的引用。这实际上和C++中的嵌套类很相像
了，Java内部类与C++嵌套类最大的不同就在于是否有指向外部的引用这一点上，当然从设计的角度以及以它一些细节来讲还有区别。</p><p>     除此之外，在任何非静态内部类中，都不能有静态数据，静态方法或者又一个静态内部类（内部类的嵌套可以不止一层）。不过静态内部类中却可以拥有这一切。这也算是两者的第二个区别吧。</p><ul><li><strong><font size="+1">局部内部类</font></strong></li></ul><p>是的，Java内部类也可以是局部的，它可以定义在一个方法甚至一个代码块之内。</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong>class</strong> Goods1 {<br />
     <font color="#0000ff"><strong>public</strong></font> Destination dest(<strong><font color="#0000ff">String</font></strong> s) {<br />
          <font color="#0000ff"><strong>class</strong></font> GDestination <strong><font color="#000000">implements</font></strong> Destination {<br />
               <font color="#0000ff"><strong>private String</strong></font> label;<br />
               <font color="#0000ff"><strong>private</strong></font> GDestination(<strong><font color="#0000ff">String</font></strong> whereTo) {<br />
                    <font color="#0000ff"><strong>label</strong></font> = whereTo;<br />
                }<br />
               <font color="#0000ff"><strong>public String</strong></font> readLabel() { <strong><font color="#0000ff">return</font></strong> label; }<br />
           }<br />
          <font color="#0000ff"><strong>return new </strong></font>GDestination(s);<br />
      }</p><p class="unnamed1">     <font color="#0000ff"><strong>public static</strong></font><font color="#000000"><strong>void main</strong></font>(<strong><font color="#0000ff">String[]</font></strong> args) {<br />
           Goods1 g= <strong><font color="#0000ff">new</font></strong> Goods1();<br />
           Destination d = g.dest("Beijing");<br />
      }<br />
}</p></td></tr></tbody></table><p>     上面就是这样一个例子。在方法dest中我们定义了一个内部类，最后由这个方法返回这个内部类的对象。如果我们在用一个内部类的时候仅需要创建它的一个对象并创给外部，就可以这样做。当然，定义在方法中的内部类可以使设计多样化，用途绝不仅仅在这一点。</p><p>下面有一个更怪的例子：</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td><p class="unnamed1"><font color="#0000ff"><strong>public</strong></font><strong><font color="#000000">class</font></strong> Goods2{<br />
     <font color="#0000ff"><strong>private</strong></font><strong><font color="#000000">void</font></strong> internalTracking(<strong><font color="#0000ff">boolean</font></strong> b) {<br />
           if(b) {<br />
               <font color="#0000ff"><strong><font color="#000000">class</font></strong></font> TrackingSlip {<br />
                    <font color="#0000ff"><strong>private String</strong></font> id;<br />
                     TrackingSlip(<strong><font color="#0000ff">String</font></strong> s) {<br />
                          id = s;<br />
                     }<br />
                    <font color="#00ff00"><strong><font color="#0000ff">String</font></strong></font> getSlip() { <strong><font color="#0000ff">return</font></strong> id; }<br />
                }<br />
                TrackingSlip ts = <strong><font color="#0000ff">new</font></strong> TrackingSlip("slip");<br />
               <font color="#0000ff"><strong>String</strong></font> s = ts.getSlip();<br />
           } <br />
      }</p><p class="unnamed1">     <font color="#0000ff"><strong>public void</strong></font> track() { internalTracking(<strong><font color="#0000ff">true</font></strong>); }</p><p class="unnamed1">     <font color="#0000ff"><strong>public static</strong></font><strong>void main</strong>(<strong><font color="#0000ff">String[]</font></strong> args) {<br />
           Goods2 g= <strong><font color="#000000">new</font></strong> Goods2();<br />
           g.track();<br />
      }<br />
}</p></td></tr></tbody></table><p>     你不能在if之外创建这个内部类的对象，因为这已经超出了它的作用域。不过在编译的时候，内部类TrackingSlip和其他类一样同时被编译，只不过它由它自己的作用域，超出了这个范围就无效，除此之外它和其他内部类并没有区别。</p><ul><li><font size="+1"><strong>匿名内部类</strong></font></li></ul><p>     java的匿名内部类的语法规则看上去有些古怪，不过如同匿名数组一样，当你只需要创建一个类的对象而且用不上它的名字时，使用内部类可以使代码看上去简洁清楚。它的语法规则是这样的：</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td class="unnamed1"><font color="#0000ff"><strong>new</strong></font> interfacename(){......}; 或 <strong><font color="#0000ff">new</font></strong> superclassname(){......};</td></tr></tbody></table><p>下面接着前面继续举例子：</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td class="unnamed1"><font color="#0000ff"><strong>public class</strong></font> Goods3 {<br />
     <font color="#0000ff"><strong>public</strong></font><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span> cont(){<br />
          <font color="#0000ff"><strong>return</strong></font><strong><font color="#0000ff">new</font></strong><span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span>(){<br />
               <font color="#0000ff"><strong>private int</strong></font> i = 11;<br />
               <font color="#0000ff"><strong>public int</strong></font> value() { <br />
                    <font color="#0000ff"><strong>return</strong></font> i; <br />
                }<br />
           };<br />
      }<br />
}</td></tr></tbody></table><p>这里方法cont()使用匿名内部类直接返回了一个实现了接口<span style="padding: 0px; font-weight: bold; color: rgb(238, 102, 0); background-color: yellow;">Contents</span>的类的对象，看上去的确十分简洁。</p><p>在java的事件处理的匿名适配器中，匿名内部类被大量的使用。例如在想关闭窗口时加上这样一句代码：</p><table class="code" align="center" bgcolor="#e0e0e0" border="0" cellspacing="4" width="100%"><tbody><tr><td class="unnamed1">frame.<strong><font color="#000000">addWindowListener</font></strong>(<strong><font color="#0000ff">new</font></strong> WindowAdapter(){<br />
     <font color="#0000ff"><strong>public void</strong></font> windowClosing(WindowEvent e){<br />
           System.exit(0); <br />
      }<br />
});</td></tr></tbody></table><p>    
有一点需要注意的是，匿名内部类由于没有名字，所以它没有构造函数（但是如果这个匿名内部类继承了一个只含有带参数构造函数的父类，创建它的时候必须带上
这些参数，并在实现的过程中使用super关键字调用相应的内容）。如果你想要初始化它的成员变量，有下面几种方法：</p><ol><li>如果是在一个方法的匿名内部类，可以利用这个方法传进你想要的参数，不过记住，这些参数必须被声明为final。 </li><li>将匿名内部类改造成有名字的局部内部类，这样它就可以拥有构造函数了。 </li><li>在这个匿名内部类中使用初始化代码块。 </li></ol><ul><li><font size="+1"><strong>为什么需要内部类？</strong></font></li></ul><p>java内部类有什么好处？为什么需要内部类？</p><p>    
首先举一个简单的例子，如果你想实现一个接口，但是这个接口中的一个方法和你构想的这个类中的一个方法的名称，参数相同，你应该怎么办？这时候，你
可以建一个内部类实现这个接口。由于内部类对外部类的所有内容都是可访问的，所以这样做可以完成所有你直接实现这个接口的功能。</p><p>     不过你可能要质疑，更改一下方法的不就行了吗？</p><p>     的确，以此作为设计内部类的理由，实在没有说服力。</p><p>     真正的原因是这样的，java中的内部类和接口加在一起，可以的解决常被C++程序员抱怨java中存在的一个问题——没有多继承。实际上，C++的多继承设计起来很复杂，而java通过内部类加上接口，可以很好的实现多继承的效果。</p><p>     本文的目的只是向大家介绍一下内部类的概念以及使用方法，在后续文章里，将会针对本文中的内容举更多具体的例子，以及介绍如何使用内部类构建一个Applicaton Framework。</p></div><img src ="http://www.blogjava.net/wiflish/aggbug/127344.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2007-07-01 11:40 <a href="http://www.blogjava.net/wiflish/archive/2007/07/01/127344.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>基于Struts的防止页面重复提交的代码片段</title><link>http://www.blogjava.net/wiflish/archive/2007/04/12/110293.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Thu, 12 Apr 2007 15:00:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2007/04/12/110293.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/110293.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2007/04/12/110293.html#Feedback</comments><slash:comments>9</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/110293.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/110293.html</trackback:ping><description><![CDATA[1、在进入增加和编辑页面的action方法（如action的add方法）中，增加如下代码：<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, 0);">saveToken(request);</span></div><br />2、在进行数据保存操作的action的方法中（如save方法），增加如下代码：<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);">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);">isTokenValid(request)) {<br />        ActionMessages messages </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);"> ActionMessages();<br /></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);">        messages.add(ActionMessages.GLOBAL_MESSAGE,<br />            </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ActionMessage(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">error.submit.double</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />        saveMessages(request.getSession(), messages);<br />        <br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">如果是重复提交，重新生成token</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">        saveToken(request);<br />        <br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> mapping.findForward(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">edit</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />    <br />    </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">不是重复提交就保存数据，并删除该次提交的token</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    resetToken(request);<br /></span></div><br />3、在编辑记录的jsp页面，使用&lt;html:errors /&gt;标签，显示错误提示。<br /><img src ="http://www.blogjava.net/wiflish/aggbug/110293.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2007-04-12 23:00 <a href="http://www.blogjava.net/wiflish/archive/2007/04/12/110293.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]使用JMock来实现孤立测试</title><link>http://www.blogjava.net/wiflish/archive/2007/04/10/109632.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Tue, 10 Apr 2007 06:40:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2007/04/10/109632.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/109632.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2007/04/10/109632.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/109632.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/109632.html</trackback:ping><description><![CDATA[
		<p class="entryContent">使用JMock来实现孤立测试(转)<br /> </p>
		<p>我们在测试某类时，由于它要与其他类发生联系，因此往往在测试此类的代码中也将与之联系的类也一起测试了。这种测试，将使被测试的类直接依赖于其他
类，一旦其他类发生改变，被测试类也随之被迫改变。更重要的是，这些其他类可能尚未经过测试，因此必须先测试这些类，才能测试被测试类。这种情况下，测试
驱动开发成为空谈。而如果其他类中也引用了被测试类，我们到底先测试哪一个类？因此，在测试中，如果我们能将被测试类孤立起来，使其完全不依赖于其他类的
具体实现，这样，我们就能做到测试先行，先测试哪个类，就先实现哪个类，而不管与之联系的类是否已经实现。</p>
		<p>虚拟对象(mock
object)就是为此需要而诞生的。它通过JDK中的反射机制，在运行时动态地创建虚拟对象。在测试代码中，我们可以验证这些虚拟对象是否被正确地调用
了，也可以在明确的情况下，让其返回特定的假想值。而一旦有了这些虚拟对象提供的服务，被测试类就可以将虚拟对象作为其他与之联系的真实对象的替身，从而
轻松地搭建起一个很完美的测试环境。</p>
		<p>JMock是帮助创建mock对象的工具，它基于Java开发，在Java测试与开发环境中有不可比拟的优势，更重要的是，它大大简化了虚拟对象的使用。</p>
		<p>本文中，通过一个简单的测试用例来说明JMock如何帮助我们实现这种孤立测试。有三个主要的类，User，UserDAO，及
UserService。本文中，我们只需测试UserService，准备虚拟UserDAO。对于User，由于本身仅是一个过于简单的POJO，可
以不用测试。但如果你是一个完美主义者，也可以使用JMock的虚拟它。在这领域，JMock几乎无所不能。:)</p>
		<p>User是一个POJO，用以在视图中传输数据及映射数据库。其代码如下：</p>
		<p>package com.sarkuya.model;</p>
		<p>public class User {<br />
    private String name;</p>
		<p>    public User() {<br />
    }<br />
    <br />
    public User(String name) {<br />
        this.name = name;<br />
    }<br />
    <br />
    public String getName() {<br />
        return name;<br />
    }<br />
    <br />
    public void setName(String name) {<br />
        this.name = name;<br />
    }<br />
}</p>
		<p>
				<br />
UserDAO负责与数据库打交道，通过数据库保存、获取User的信息。尽管我们可以不用知道JMock如何通过JDK的反射机制来实现孤立测试，但至
少应知道，JDK的反射机制要求这些在运行时创建的动态类必须定义接口。在使用JMock的环境中，由于我们要虚拟UserDAO，意味着UserDAO
必须定义接口。代码如下：</p>
		<p>package com.sarkuya.dao;</p>
		<p>import com.sarkuya.model.User;</p>
		<p>public interface UserDAO {<br />
    public void saveUser(User user);<br />
    public User getUser(Long id);<br />
}</p>
		<p>UserService存有UserDAO的引用，通过其对外提供应用级的服务。相应地，我们先定义了其接口(尽管在本文中，作为被测试类，UserService不需要有接口，但如果以后此类需要被虚拟，也应该带有接口，基于此原因，我们也为其定义了接口)。</p>
		<p>package com.sarkuya.service;</p>
		<p>import com.sarkuya.dao.UserDAO;<br />
import com.sarkuya.model.User;</p>
		<p>public interface UserService {<br />
    public void setUserDAO(UserDAO userDAO);<br />
    <br />
    public void saveUser(User user);<br />
    public User getUser(Long id);<br />
}</p>
		<p>可以看到，除了setUserDAO()外，其另外的方法与UserDAO一样。这是设计模式中门面模式的典型应用，应用只通过UserService提供服务，而UserService在内部通过调用UserDAO来实现相应的功能。</p>
		<p>根据测试先行的原则，你应该先写测试，再编写实现。这里先编写实现的原因，主要是使读者更加清楚我们接着要测试什么。由于本文是着重介绍JMock的使用，加上UserServiceImpl比较简单，因此先列出其代码如下：</p>
		<p>package com.sarkuya.service.impl;</p>
		<p>import com.sarkuya.dao.UserDAO;<br />
import com.sarkuya.model.User;<br />
import com.sarkuya.service.UserService;</p>
		<p>public class UserServiceImpl implements UserService {<br />
    private UserDAO userDAO;<br />
    <br />
    public UserServiceImpl() {<br />
    }</p>
		<p>    public void setUserDAO(UserDAO userDAO) {<br />
        this.userDAO = userDAO;<br />
    }</p>
		<p>    public User getUser(Long id) {<br />
        return userDAO.getUser(id);<br />
    }</p>
		<p>    public void saveUser(User user) {<br />
        userDAO.saveUser(user);<br />
    }<br />
}</p>
		<p>下面是UserService的测试代码：</p>
		<p>package com.sarkuya.service;</p>
		<p>import com.sarkuya.dao.UserDAO;<br />
import com.sarkuya.model.User;<br />
import com.sarkuya.service.impl.UserServiceImpl;<br />
import junit.framework.*;<br />
import org.jmock.Mock;<br />
import org.jmock.MockObjectTestCase;</p>
		<p>public class UserServiceTest extends MockObjectTestCase {<br />
    private UserService userService = new UserServiceImpl();<br />
    <br />
    private Mock userDAO = null;<br />
    <br />
    public UserServiceTest(String testName) {<br />
        super(testName);<br />
    }<br />
    <br />
    protected void setUp() throws Exception {<br />
        userDAO = new Mock(UserDAO.class);<br />
        userService.setUserDAO((UserDAO)userDAO.proxy());<br />
    }<br />
    <br />
    protected void tearDown() throws Exception {<br />
    }<br />
    <br />
    public static Test suite() {<br />
        TestSuite suite = new TestSuite(UserServiceTest.class);<br />
        <br />
        return suite;<br />
    }<br />
    <br />
    public void testGetUser() {<br />
        User fakeUser = new User("John");<br />
        userDAO.expects(once()).method("getUser").with(eq(1L)).will(returnValue(fakeUser));<br />
        <br />
        User user = userService.getUser(1L);<br />
        assertNotNull(user);<br />
        assertEquals("John", user.getName());<br />
    }<br />
    <br />
    public void testSaveUser() {<br />
        User fakeUser = new User("John");<br />
        <br />
        userDAO.expects(once()).method("getUser").with(eq(1L)).will(returnValue(fakeUser));<br />
        User user = userService.getUser(1L);<br />
        assertEquals("John", user.getName());<br />
        <br />
        userDAO.expects(once()).method("saveUser").with(same(fakeUser));<br />
        user.setName("Mike");<br />
        userService.saveUser(user);<br />
        <br />
        userDAO.expects(once()).method("getUser").with(eq(1L)).will(returnValue(user));<br />
        User modifiedUser = userService.getUser(1L);<br />
        assertEquals("Mike", user.getName());<br />
    }<br />
}</p>
		<p>此段代码有几点应注意：</p>
		<p>1、此测试类继承了JMock的MockObjectTestCase</p>
		<p>2、private Mock userDAO = null;说明userDao是一个准备虚拟的对象</p>
		<p>3、在setup()中，将userDAO.class传入Mock()后，再通过proxy()方法返回一个UserDAO的代理类实例(即虚拟对象实例)，并赋值于userService</p>
		<p>4、在testGetUser()方法中，如果我们先将第一行及第二行代码屏蔽掉，可以看出，这是一个真实环境下的测试代码。先获取一个User，
然后确认其非空值，再确认其姓名为“John”。此时，在真实环境下，这段代码要测试成功的前提必须是UserDAO已经连接到了数据库，然后返回一个
User后传给UserService。<br />
但问题是，到目前为止，且不说UserDAO还未经历连接数据库这一系列繁琐而痛苦的过程，我们甚至还未实现UserDAO的接口！那么，为何加上第一行
及第二行代码后就可以了呢？这正是JMock的威力所在。先实例化一个测试用的fakeUser，然后通过一系列的指令，在第二行代码中告诉JMock应
该如何“做假”。尽管这句代码很长，我们可作如下理解：<br />
1) userDAO.expects(once())：我们期望userDAO的某方法被执行一次，如果此方法未被执行，或者执行了二次以上，测试就不会通过<br />
2) method("getUser")：这个期望被执行一次的方法名为userDAO.getUser()<br />
3) with(eq(1L))：执行getUser()方法时，确认其传入的参数值为“1L”<br />
4) will(returnValue(fakeUser))：上述条件均满足后，返回一个虚假的对象，即我们前面实例化的fakeUser<br />
总体来说，当设定好第二行语句后，JMock就在后台监控着，确保userDAO.getUser()必须，且只被执行一次，且参数“1L”已经正确地传给了此方法，一旦这些条件被满足，就返回fakeUser。<br />
而在第三行，User user = userService.getUser(1L)将触发所有这些条件，作为奖励，它接受了奖品fakeUser并赋值于user对象。而下面第四行及第五行均对此user对象进行测试，不通过才怪。</p>
		<p>5) testSaveUser()方法中的原理类似。其思路是，将id为“1”的user从数据库中取出，将其名改为“Mike”，再存回数据库，然后再从数据库中取出此user，确保其名字已被改变。<br />
第五行userDAO.expects(once()).method("saveUser").with(same(fakeUser))比较特殊。首
先，with(same(fakeUser))说明，传入参数必须是fakeUser此实例，尽管我们在下面的语句中通过user.setName
("Mike")，但只是改变了其name的属性，而fakeUser的实例引用并未发生改变，因此可以满足条件。其次，其后没有.will
(returnValue(fakeUser))，因为userDAO.saveUser()不需要返回任何对象或基本数据类型。<br />
另外，当再次执行userDAO.expects()时，JMock将重设其监控条件。我们也可以通过userDAO.reset()来显式是清除监控条件。</p>
		<p>通过以上实例代码及其说明，我们看出，用好JMock的关键是先设置监控条件，再写相应的测试语句。一旦设好监控条件后，在某段代码块执行完毕时，
如果监控条件未得到满足，或是没有通过expects()再次重设条件，或通过reset()来显式是清除监控条件，测试将无法通过。</p>
		<p>以上介绍了JMock的基本使用方法。而这种基本用法，占了全面掌握JMock所需学习的知识70%以上。关于JMock的更多细节，感兴趣的读者可以访问JMock的网站进一步学习。</p>
<img src ="http://www.blogjava.net/wiflish/aggbug/109632.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2007-04-10 14:40 <a href="http://www.blogjava.net/wiflish/archive/2007/04/10/109632.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【原创】JIRA安装(windows)</title><link>http://www.blogjava.net/wiflish/archive/2007/04/01/107831.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Sun, 01 Apr 2007 13:49:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2007/04/01/107831.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/107831.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2007/04/01/107831.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/107831.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/107831.html</trackback:ping><description><![CDATA[JIRA安装<br />1、环境：Windows XP，tomcat5.0.28，mysql5.0.37，apache2.0.59，<br />2、下载jira，http://downloads.atlassian.com/software/jira/downloads/atlassian-jira-enterprise-3.8-standalone.tar.gz<br />3、解压到一个目录，jira的根目录用%JIRA_HOME%表示，atlassian-jira-enterprise-3.8-standalone自带了tomcat，如果已经设置过了CATALINA_HOME，更改%JIRA_HOME%\bin\startup.bat文件，找到：:okHome，在其下增加：<br />cd ..<br />set CATALINA_HOME=%cd%<br />这样更改后，运行%JIRA_HOME%\bin\startup.bat就能启动jira自带的tomcat，<br />4、修改连接池配置（jira默认使用HSQLDB）修改%JIRA_HOME%\conf\server.xml，<br />将该文件中的连接池配置更改为mysql的配置。如：<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, 128, 128);">1</span> <span style="color: rgb(0, 0, 0);">username="root"<br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);">password=""<br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);">driverClassName="com.mysql.jdbc.Driver"<br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">url="jdbc:mysql://localhost/jira?useUnicode=true</span><span style="color: rgb(255, 0, 0);">&amp;amp;</span><span style="color: rgb(0, 0, 0);">characterEncoding=utf-8"</span></div>注：一定要加：<span style="color: rgb(0, 0, 0);">useUnicode=true</span><span style="color: rgb(255, 0, 0);">&amp;amp;</span><span style="color: rgb(0, 0, 0);">amp;characterEncoding=utf-8，并在c:\WINDOWS\my.ini（mysql配置文件）中的[mysqld]部分加入：default-character-set=UTF8（即设置mysql的默认字符集为UTF8），否则有乱码。<br /><br />5、修改%JIRA_HOME%\atlassian-jira\WEB-INF\classes\entityengine.xml文件，查找：&lt;datasource name="defaultDS" field-type-name="hsql"<br />      helper-class="org.ofbiz.core.entity.GenericHelperDAO"<br /></span>将hsql更改为：mysql。<br /><br />6、运行%JIRA_HOME%\bin\startup.bat，输入：http://localhost:8080，看到jira的安装向导，安装成功。<br /><br />注：<br />a）将mysql5的jdbc驱动：mysql-connector-java-5.0.5-bin.jar放到%JIRA_HOME%\common\lib目录下。<br />b）mysql的安装参见：http://www.blogjava.net/wiflish/archive/2006/12/26/90123.html<br />c）由于jira是收费的，启动jira自带的tomcat，进入安装向导后，需要输入注册码。<br /><br /><br /><br /><img src ="http://www.blogjava.net/wiflish/aggbug/107831.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2007-04-01 21:49 <a href="http://www.blogjava.net/wiflish/archive/2007/04/01/107831.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java编译和运行小工具</title><link>http://www.blogjava.net/wiflish/archive/2007/03/07/102418.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Wed, 07 Mar 2007 07:47:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2007/03/07/102418.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/102418.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2007/03/07/102418.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/102418.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/102418.html</trackback:ping><description><![CDATA[
		<p>编译和运行java程序的DOS批处理文件。<br />java初学者编写测试代码时，不用专门开个dos窗口，输入命令来编译和运行java程序。<br />将待编译的java文件拖动到compile.bat上，就能编译；<br />将待运行的class文件拖动到run.bat上，就能运行。<br /><a title="java编译运行小工具" href="/Files/wiflish/java编译运行小工具.rar" target="_blank">点击下载</a></p>
<img src ="http://www.blogjava.net/wiflish/aggbug/102418.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2007-03-07 15:47 <a href="http://www.blogjava.net/wiflish/archive/2007/03/07/102418.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>【转】JAVA的内省（introspector）与反射（reflection）</title><link>http://www.blogjava.net/wiflish/archive/2007/03/05/101964.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Mon, 05 Mar 2007 09:40:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2007/03/05/101964.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/101964.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2007/03/05/101964.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/101964.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/101964.html</trackback:ping><description><![CDATA[
		<font color="#000000">
				<div class="postTitle">
						<a href="http://blog.csdn.net/daoquan/archive/2006/03/17/627810.aspx">
								<img height="13" src="http://blog.csdn.net/images/zhuan.gif" width="15" border="0" /> JAVA语言的反射和内省</a>
				</div>
				<div class="postText">
						<p class="MsoNormal" style="TEXT-INDENT: 21pt">
								<span style="FONT-FAMILY: 宋体">很多朋友在深入的接触</span>
								<span lang="EN-US">JAVA</span>
								<span style="FONT-FAMILY: 宋体">语言后就会发现这样两个词：反射</span>
								<span lang="EN-US">(Reflection)</span>
								<span style="FONT-FAMILY: 宋体">和内省</span>
								<span lang="EN-US">(Introspector)</span>
								<span style="FONT-FAMILY: 宋体">，经常搞不清楚这到底是怎么回事，在什么场合下应用以及如何使用？今天把这二者放在一起介绍，因为它们二者是相辅相成的。</span>
						</p>
						<p class="MsoNormal">
								<span style="FONT-FAMILY: 宋体">反射</span>
						</p>
						<p class="MsoNormal">
								<span lang="EN-US">
										<?xml:namespace prefix = o /?>
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="MsoNormal" style="TEXT-INDENT: 21pt">
								<span style="FONT-FAMILY: 宋体">相对而言，反射比内省更容易理解一点。用一句比较白的话来概括，反射就是让你可以通过名称来得到对象</span>
								<span lang="EN-US">(</span>
								<span style="FONT-FAMILY: 宋体">类，属性，方法</span>
								<span lang="EN-US">)</span>
								<span style="FONT-FAMILY: 宋体">的技术。例如我们可以通过类名来生成一个类的实例；知道了方法名，就可以调用这个方法；知道了属性名就可以访问这个属性的值。</span>
						</p>
						<p class="MsoNormal">
								<span style="FONT-FAMILY: 宋体">还是写两个例子让大家更直观的了解反射的使用方法：</span>
						</p>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellspacing="0" cellpadding="0" border="1">
								<tbody>
										<tr>
												<td style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 426.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 0.5pt solid" valign="top" width="568">
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span>
																<span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">通过类名来构造一个类的实例<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Class cls_str = Class.forName(</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"java.lang.String"</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">);<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span>
																<span style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体">上面这句很眼熟，因为使用过</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'">JDBC</span>
																<span style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体">访问数据库的人都用过</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: Wingdings">
																		<span>J<br /></span>
																</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Object str = cls_str.newInstance();<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span>
																<span style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体">相当于</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'">String str = new String();</span>
														</p>
												</td>
										</tr>
								</tbody>
						</table>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellspacing="0" cellpadding="0" border="1">
								<tbody>
										<tr>
												<td style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 426.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 0.5pt solid" valign="top" width="568">
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span>
																<span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">通过方法名来调用一个方法<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">String methodName = </span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"length"</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">;<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Method m = cls_str.getMethod(methodName,</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">null</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">);<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">System.out.println(</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"length is "</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">+ m.invoke(str,</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">null</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">));<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span>
																<span style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体">相当于</span>
																<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'">System.out.println(str.length());</span>
														</p>
												</td>
										</tr>
								</tbody>
						</table>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="MsoNormal" style="TEXT-INDENT: 21pt">
								<span style="FONT-FAMILY: 宋体">上面的两个例子是比较常用方法。看到上面的例子就有人要发问了：为什么要这么麻烦呢？本来一条语句就完成的事情干吗要整这么复杂？没错，在上面的例子中确实没有必要这么麻烦。不过你想像这样一个应用程序，它支持动态的功能扩展，也就是说程序不重新启动但是可以自动加载新的功能，这个功能使用一个具体类来表示。首先我们必须为这些功能定义一个接口类，然后我们要求所有扩展的功能类必须实现我指定的接口，这个规定了应用程序和可扩展功能之间的接口规则，但是怎么动态加载呢？我们必须让应用程序知道要扩展的功能类的类名，比如是</span>
								<span lang="EN-US">test.Func1</span>
								<span style="FONT-FAMILY: 宋体">，当我们把这个类名</span>
								<span lang="EN-US">(</span>
								<span style="FONT-FAMILY: 宋体">字符串</span>
								<span lang="EN-US">)</span>
								<span style="FONT-FAMILY: 宋体">告诉应用程序后，它就可以使用我们第一个例子的方法来加载并启用新的功能。这就是类的反射，请问你有别的选择吗？</span>
						</p>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="MsoNormal">
								<span lang="EN-US">
										<span>       </span>
								</span>
								<span style="FONT-FAMILY: 宋体">关于方法的反射建议大家看我的另外一篇文章《</span>
								<span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">利用</span>
								<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Turbine</span>
								<span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">的事件映射来扩展</span>
								<span lang="EN-US" style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Struts</span>
								<span style="FONT-SIZE: 10pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">的功能</span>
								<span style="FONT-FAMILY: 宋体">》，地址是：</span>
								<span lang="EN-US">
										<a href="http://www.javayou.com/article/CSDN/extend_struts.html">http://www.javayou.com/article/CSDN/extend_struts.html</a>
								</span>
								<span style="FONT-FAMILY: 宋体">。这篇文章详细介绍了如果通过反射来扩展</span>
								<span lang="EN-US">Struts</span>
								<span style="FONT-FAMILY: 宋体">框架的功能。</span>
						</p>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="MsoNormal">
								<span style="FONT-FAMILY: 宋体">内省</span>
						</p>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="MsoNormal" style="TEXT-INDENT: 21pt">
								<span style="FONT-FAMILY: 宋体">内省是</span>
								<span lang="EN-US">Java</span>
								<span style="FONT-FAMILY: 宋体">语言对</span>
								<span lang="EN-US">Bean</span>
								<span style="FONT-FAMILY: 宋体">类属性、事件的一种缺省处理方法。例如类</span>
								<span lang="EN-US">A</span>
								<span style="FONT-FAMILY: 宋体">中有属性</span>
								<span lang="EN-US">name,</span>
								<span style="FONT-FAMILY: 宋体">那我们可以通过</span>
								<span lang="EN-US">getName,setName</span>
								<span style="FONT-FAMILY: 宋体">来得到其值或者设置新的值。通过</span>
								<span lang="EN-US">getName/setName</span>
								<span style="FONT-FAMILY: 宋体">来访问</span>
								<span lang="EN-US">name</span>
								<span style="FONT-FAMILY: 宋体">属性，这就是默认的规则。</span>
								<span lang="EN-US">Java</span>
								<span style="FONT-FAMILY: 宋体">中提供了一套</span>
								<span lang="EN-US">API</span>
								<span style="FONT-FAMILY: 宋体">用来访问某个属性的</span>
								<span lang="EN-US">getter/setter</span>
								<span style="FONT-FAMILY: 宋体">方法，通过这些</span>
								<span lang="EN-US">API</span>
								<span style="FONT-FAMILY: 宋体">可以使你不需要了解这个规则（但你最好还是要搞清楚），这些</span>
								<span lang="EN-US">API</span>
								<span style="FONT-FAMILY: 宋体">存放于包</span>
								<span lang="EN-US">java.beans</span>
								<span style="FONT-FAMILY: 宋体">中。</span>
						</p>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="MsoNormal" style="TEXT-INDENT: 21pt">
								<span style="FONT-FAMILY: 宋体">一般的做法是通过类</span>
								<span lang="EN-US">Introspector</span>
								<span style="FONT-FAMILY: 宋体">来获取某个对象的</span>
								<span lang="EN-US">BeanInfo</span>
								<span style="FONT-FAMILY: 宋体">信息，然后通过</span>
								<span lang="EN-US">BeanInfo</span>
								<span style="FONT-FAMILY: 宋体">来获取属性的描述器（</span>
								<span lang="EN-US">PropertyDescriptor</span>
								<span style="FONT-FAMILY: 宋体">），通过这个属性描述器就可以获取某个属性对应的</span>
								<span lang="EN-US">getter/setter</span>
								<span style="FONT-FAMILY: 宋体">方法，然后我们就可以通过反射机制来调用这些方法。下面我们来看一个例子，这个例子把某个对象的所有属性名称和值都打印出来：</span>
						</p>
						<p class="MsoNormal" style="TEXT-INDENT: 21pt">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<table style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse" cellspacing="0" cellpadding="0" border="1">
								<tbody>
										<tr>
												<td style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 426.1pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 0.5pt solid" valign="top" width="568">
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">/* <br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span> </span>* Created on 2004-6-29<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span> </span>*/</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">package</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">demo;</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">import</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">java.beans.BeanInfo;<br /></span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">import</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">java.beans.Introspector;<br /></span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">import</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">java.beans.PropertyDescriptor;</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">/**<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span> </span>
																</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">*</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																</span>
																<span style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">内省演示例子<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span> </span>
																</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">*</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,159,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">@author</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">liudong<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span> </span>
																</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,95,191); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">*/</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" dir="ltr" style="MARGIN-RIGHT: 0px; TEXT-ALIGN: left" align="left">
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">public</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">class</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">IntrospectorDemo {<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>    </span>String name;<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>    </span>
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">public</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">static</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">void</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">main(String[] args) </span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">throws</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Exception{<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">        IntrospectorDemo demo = </span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">new</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">IntrospectorDemo();<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">        demo.setName(</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"Winter Lau"</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">);</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>        </span>
																</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>        </span>
																</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span>
																<span style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">如果不想把父类的属性也列出来的话，<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>        </span>
																</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">//</span>
																<span style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">那</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">getBeanInfo</span>
																<span style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(63,127,95); FONT-FAMILY: 宋体; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">的第二个参数填写父类的信息<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>        </span>BeanInfo bi = Introspector.getBeanInfo(demo.getClass(),</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">Object.</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">class</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">);<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>        </span>PropertyDescriptor[] props = bi.getPropertyDescriptors();<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>        </span>
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">for</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">(</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">int</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">i=0;i&lt;props.length;i++){<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>            </span>System.out.println(props[i].getName()+</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(42,0,255); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">"="</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">+<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>                    </span>props[i].getReadMethod().invoke(demo,</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">null</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">));<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>        </span>}</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>    </span>}</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>    </span>
																</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>    </span>
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">public</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">String getName() {<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>        </span>
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">return</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">name;<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>    </span>}</span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'">
																		<o:p>
																		</o:p>
																</span>
														</p>
														<p class="MsoNormal" style="TEXT-ALIGN: left" align="left">
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>    </span>
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">public</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">void</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">setName(String name) {<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>        </span>
																</span>
																<strong>
																		<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: rgb(127,0,85); FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">this</span>
																</strong>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">.name = name;<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">
																		<span>    </span>}<br /></span>
																<span lang="EN-US" style="FONT-SIZE: 9pt; BACKGROUND: white 0% 50%; COLOR: black; FONT-FAMILY: 'Courier New'; moz-background-clip: -moz-initial; moz-background-origin: -moz-initial; moz-background-inline-policy: -moz-initial">}</span>
														</p>
												</td>
										</tr>
								</tbody>
						</table>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="MsoNormal" style="TEXT-INDENT: 21pt">
								<span lang="EN-US">Web</span>
								<span style="FONT-FAMILY: 宋体">开发框架</span>
								<span lang="EN-US">Struts</span>
								<span style="FONT-FAMILY: 宋体">中的</span>
								<span lang="EN-US">FormBean</span>
								<span style="FONT-FAMILY: 宋体">就是通过内省机制来将表单中的数据映射到类的属性上，因此要求</span>
								<span lang="EN-US">FormBean</span>
								<span style="FONT-FAMILY: 宋体">的每个属性要有</span>
								<span lang="EN-US">getter/setter</span>
								<span style="FONT-FAMILY: 宋体">方法。但也并不总是这样，什么意思呢？就是说对一个</span>
								<span lang="EN-US">Bean</span>
								<span style="FONT-FAMILY: 宋体">类来讲，我可以没有属性，但是只要有</span>
								<span lang="EN-US">getter/setter</span>
								<span style="FONT-FAMILY: 宋体">方法中的其中一个，那么</span>
								<span lang="EN-US">Java</span>
								<span style="FONT-FAMILY: 宋体">的内省机制就会认为存在一个属性，比如类中有方法</span>
								<span lang="EN-US">setMobile</span>
								<span style="FONT-FAMILY: 宋体">，那么就认为存在一个</span>
								<span lang="EN-US">mobile</span>
								<span style="FONT-FAMILY: 宋体">的属性，这样可以方便我们把</span>
								<span lang="EN-US">Bean</span>
								<span style="FONT-FAMILY: 宋体">类通过一个接口来定义而不用去关心具体实现，不用去关心 </span>
								<span lang="EN-US">Bean</span>
								<span style="FONT-FAMILY: 宋体">中数据的存储。比如我们可以把所有的</span>
								<span lang="EN-US">getter/setter</span>
								<span style="FONT-FAMILY: 宋体">方法放到接口里定义，但是真正数据的存取则是在具体类中去实现，这样可提高系统的扩展性。</span>
						</p>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="MsoNormal">
								<span style="FONT-FAMILY: 宋体">总结</span>
						</p>
						<p class="MsoNormal">
								<span lang="EN-US">
										<o:p>
										</o:p>
								</span>
						</p>
						<p class="MsoNormal" style="TEXT-INDENT: 21pt">
								<span style="FONT-FAMILY: 宋体">将</span>
								<span lang="EN-US">Java</span>
								<span style="FONT-FAMILY: 宋体">的反射以及内省应用到程序设计中去可以大大的提供程序的智能化和可扩展性。有很多项目都是采取这两种技术来实现其核心功能，例如我们前面提到的</span>
								<span lang="EN-US">Struts</span>
								<span style="FONT-FAMILY: 宋体">，还有用于处理</span>
								<span lang="EN-US">XML</span>
								<span style="FONT-FAMILY: 宋体">文件的</span>
								<span lang="EN-US">Digester</span>
								<span style="FONT-FAMILY: 宋体">项目，其实应该说几乎所有的项目都或多或少的采用这两种技术。在实际应用过程中二者要相互结合方能发挥真正的智能化以及高度可扩展性。</span>
						</p>
				</div>
		</font>
<img src ="http://www.blogjava.net/wiflish/aggbug/101964.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2007-03-05 17:40 <a href="http://www.blogjava.net/wiflish/archive/2007/03/05/101964.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>tomcat配置(提高运行效率)</title><link>http://www.blogjava.net/wiflish/archive/2007/01/15/93970.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Mon, 15 Jan 2007 07:50:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2007/01/15/93970.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/93970.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2007/01/15/93970.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/93970.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/93970.html</trackback:ping><description><![CDATA[
		<p>在%CATALINA_HOME%/conf/web.xml中有(以tomcat5.0.28为例)：</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080"> 1</span>
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">servlet</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 2</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">servlet-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">jsp</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 3</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">servlet-class</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">org.apache.jasper.servlet.JspServlet</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet-class</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 4</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">init-param</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 5</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">param-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">fork</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">param-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 6</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">param-value</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">false</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">param-value</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 7</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">init-param</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 8</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">init-param</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080"> 9</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">param-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">xpoweredBy</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">param-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080">10</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">param-value</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">false</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">param-value</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080">11</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">init-param</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080">12</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">load-on-startup</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">3</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">load-on-startup</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #008080">13</span>
				<span style="COLOR: #000000">
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>
		<br />在该段代码中增加：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080"> 1</span><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">jsp</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">org.apache.jasper.servlet.JspServlet</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">init-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">fork</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">false</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 7</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">init-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">init-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">xpoweredBy</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">false</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">init-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000">增加的初始化参数</span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">init-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">development</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">false</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">param-value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">16</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">init-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">17</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">load-on-startup</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">3</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">load-on-startup</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /></span><span style="COLOR: #008080">18</span><span style="COLOR: #000000"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet</span><span style="COLOR: #0000ff">&gt;</span></div><br />development参数的说明：<br />development         Is Jasper used in development mode (will check for JSP modification on every access)?  [true]<br />该参数默认值为true，即tomcat会对jsp页面的每次访问都检测它是否发生了修改；将该参数设置为false后，也就是说tomcat不以开发模式运行，即不再检测jsp是否发生了修改，这样能提高运行效率。<br />如果系统运行后，偶尔对某个jsp页面进行了修改，只要删除该jsp页面在%CATALINA_HOME%/work目录中对应的servlet源文件和class文件，再访问该jsp页面后，tomcat(jsp引擎)就会重新编译该jsp文件。<br /><img src ="http://www.blogjava.net/wiflish/aggbug/93970.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2007-01-15 15:50 <a href="http://www.blogjava.net/wiflish/archive/2007/01/15/93970.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]关于文件下载的几个问题总结</title><link>http://www.blogjava.net/wiflish/archive/2006/12/29/90670.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Fri, 29 Dec 2006 02:44:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/12/29/90670.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/90670.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/12/29/90670.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/90670.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/90670.html</trackback:ping><description><![CDATA[
		<p>转：<a href="http://ltc603.javaeye.com/blog/25158">http://ltc603.javaeye.com/blog/25158</a><br /><br />使用servlet来下载文件，其原理非常简单，只要得到文件的输入流（或相应字节），然后写输出流即可。现就其中的几个细节问题展开： <br />1. MIME类型的设置： <br />Web 浏览器使用 MIME 类型来识别非 HTML 文档，并决定如何显示该文档内的数据。 <br />例如EXCEL文件的 MIME 类型是 "application/vnd.ms-excel "。要用servlet 来打开一个 EXCEL 文档，需要将 response 对象中 header 的 contentType 设置成“application/vnd.ms-excel ”。 <br />response.setContentType(contentType); <br />2. Content disposition <br />HTTP response header中的content-disposition 允许 servlet 指定文档表示的信息。使用这种header ，你就可以将文档指定成单独打开（而不是在浏览器中打开），还可以根据用户的操作来显示。 <br />如果用户要保存文档，你还可以为该文档建议一个文件名。这个建议名称会出现在 Save As 对话框的“文件名”栏中。如果没有指定，则对话框中就会出现 servlet 的名字。 <br />servlet 中，将 header 设置成下面这样： <br />response.setHeader("Content-disposition","attachment;filename="+ "Example.xls" );</p>
		<p>response.setHeader("Content-Disposition", "inline; filename="fliename) <br />点击打开会在ie中打开。</p>
		<p>需要说明的有三点： <br />Ø 中文文件名需要进行iso8859-1转码方可正确显示： <br />fileName = new String(fileName.getBytes("GBK"),"iso8859-1"); <br />Ø 传递的文件名，需要包含后缀名（如果此文件有后缀名），否则丢失文件的属性，而不能自行选择相关程序打开。 <br />Ø 有下载前询问（是打开文件还是保存到计算机）和通过IE浏览器直接选择相关应用程序插件打开两种方式，前者如上代码所示，后者如下： <br />response.setHeader("Content-disposition","filename="+ "Example.xls" ); <br />3. 在研究文件的上传及下载过程中，有几点体会 <br />程序的I/O操作往往是性能的瓶颈所在，java io定义了两个基本的抽象类:InputStream和OutputStream,对于不同的数据类型比如磁盘，网络又提供了不同的实现，java.io 也提供了一些缓冲流(BufferedStream)，使硬盘可以很快的读写一大块的数据, 而Java基本的I/O类一次只能读写一个字节,但缓冲流(BufferedStream)可以一次读写一批数据，,缓冲流(Buffered Stream)大大提高了I/O的性能。所以: <br />Ø小块小块的读写数据会非常慢,因此,尽量大块的读写数据 <br />Ø使用BufferedInputStream和BufferedOutputStream来批处理数据以提高性能 <br />Ø对象的序列化(serialization)非常影响I/O的性能,尽量少用 <br /><br />注：<br />1、Servlet中输出流的简单处理方法：      </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">      <img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #008000">//</span><span style="COLOR: #008000">得到当前web应用根目录下test.txt文件的实际物理路径.</span><span style="COLOR: #008000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span><span style="COLOR: #000000">       String path </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> getServletContext().getRealPath(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">/test.txt</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);    <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />       OutputStream os </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> response.getOutputStream();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />       InputStream is </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileInputStream(path);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />       </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[] buff </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">byte</span><span style="COLOR: #000000">[</span><span style="COLOR: #000000">1024</span><span style="COLOR: #000000">];<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />       </span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> len;<br /><img id="Codehighlighter1_305_350_Open_Image" onclick="this.style.display='none'; Codehighlighter1_305_350_Open_Text.style.display='none'; Codehighlighter1_305_350_Closed_Image.style.display='inline'; Codehighlighter1_305_350_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_305_350_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_305_350_Closed_Text.style.display='none'; Codehighlighter1_305_350_Open_Image.style.display='inline'; Codehighlighter1_305_350_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />   </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">((len </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> is.read(buff)) </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000">  </span><span style="COLOR: #000000">-</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">) </span><span id="Codehighlighter1_305_350_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img src="http://www.blogjava.net/images/dot.gif" /></span><span id="Codehighlighter1_305_350_Open_Text"><span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />            os.write(buff, </span><span style="COLOR: #000000">0</span><span style="COLOR: #000000">, len);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />       }</span></span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />       <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />       is.close();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />       os.close(); <br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span></div>
		<p>
				<br />2、输出流跟PrintWriter out = response.getWriter();不能同时使用。<br /></p>
<img src ="http://www.blogjava.net/wiflish/aggbug/90670.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-12-29 10:44 <a href="http://www.blogjava.net/wiflish/archive/2006/12/29/90670.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HTTP响应头</title><link>http://www.blogjava.net/wiflish/archive/2006/11/23/83082.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Thu, 23 Nov 2006 09:16:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/11/23/83082.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/83082.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/11/23/83082.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/83082.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/83082.html</trackback:ping><description><![CDATA[禁止浏览器缓存当前页面：<br />1、response.setDateHeader("Expires", 0);<br />2、response.setHeader("Cache-Control", "no-cache");<br />3、response.setHeader("Pragma", "no-cache");<br />定时刷新当前页面：<br />response.setHeader("Refresh", "5");     //每隔5秒刷新一次当前页面。<br />定时跳转页面<br />response.setHeader("Refresh", "5; URL=http://www.google.com"); //5秒后，当前页面跳转到google。<br /><br /><img src ="http://www.blogjava.net/wiflish/aggbug/83082.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-11-23 17:16 <a href="http://www.blogjava.net/wiflish/archive/2006/11/23/83082.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用jar命令创建可执行的jar包</title><link>http://www.blogjava.net/wiflish/archive/2006/07/05/56672.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Wed, 05 Jul 2006 03:00:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/07/05/56672.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/56672.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/07/05/56672.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/56672.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/56672.html</trackback:ping><description><![CDATA[
		<br />1、创建可执行的jar包。<br />手工写manifest.mf文件(jar命令自动生成的MANIFEST.MF文件中不会包含Main-Class属性)，举例说明：<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, 0);"></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">mymanifest.mf //该文件可以随意放置,只要在执行jar命令时指定mymanifest.mf文件所在位置.</span><br /><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">src<br />  </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">test<br />    </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">Test.</span><span style="color: rgb(0, 0, 255);">class</span></div><br />test.Test代码：<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, 128, 128);">1</span> <span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> test;<br /></span><span style="color: rgb(0, 128, 128);">2</span> <span style="color: rgb(0, 0, 0);"></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);"> Test {<br /></span><span style="color: rgb(0, 128, 128);">3</span> <span style="color: rgb(0, 0, 0);">    </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) {<br /></span><span style="color: rgb(0, 128, 128);">4</span> <span style="color: rgb(0, 0, 0);">        System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">HelloWorld!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">5</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">6</span> <span style="color: rgb(0, 0, 0);">}</span></div><br />mymanifest.mf文件内容：<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, 0);">Manifest</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Version: </span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">该属性是创建可执行jar包必需的，指定的Main-Class为全路径类名（且该类必需有main方法）</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">Main</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Class: test.Test<br />Created</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">By: wiflish</span></div><br />在src目录下执行： <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, 0);">jar cvfm test.jar ..</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">mymanifest .</span></div>完成后会在src目录下生成一个test.jar文件。由于没有可视化界面，双击test.jar将会看到没反应。<br />在命令行执行java -jar test.jar就会得到输出HelloWorld!<br /><br />这时就完成了基本的创建可执行的jar包。<br /><br />2、创建要依赖其他包的可执行jar包。<br />这时只要更改mymanifest.mf文件加入：<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, 0);">Manifest</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Version: </span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">该属性是创建可执行jar包必需的，指定的Main-Class为全路径类名（且该类必需有main方法）</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">Main</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Class: test.Test<br /></span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">该属性指定依赖包的路径(路径是相对jar包所在路径)</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">Class</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">Path: lib</span><span style="color: rgb(0, 0, 0);">/</span><span style="color: rgb(0, 0, 0);">swing</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">layout</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);">.jar </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);">Created</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">By: wiflish</span></div><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, 0);">-</span><span style="color: rgb(0, 0, 0);">src<br />  </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">test<br />    </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">TestDepends.</span><span style="color: rgb(0, 0, 255);">class //假设该类执行依赖于 swing-layout-1.0.jar，具体代码略。</span><span style="color: rgb(0, 0, 0);"><br />  </span><span style="color: rgb(0, 0, 0);">testDepends</span><span style="color: rgb(0, 0, 0);">.jar<br />  </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">lib<br />    swing</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">layout</span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">1.0</span><span style="color: rgb(0, 0, 0);">.jar</span></div><br />双击<span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">testDepends</span><span style="color: rgb(0, 0, 0);">.jar就能正确执行，如果</span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">TestDepends</span><span style="color: rgb(0, 0, 0);">.jar包所在的当前目录下没有lib/swing-layout-1.0.jar的话，如下目录结构：<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, 0);">-</span><span style="color: rgb(0, 0, 0);">src<br />  </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);">test<br />    </span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 0);">TestDepends.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">假设该类执行依赖于 swing-layout-1.0.jar，具体代码略。</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">  testDepends.jar</span><span style="color: rgb(0, 0, 0);"></span></div>双击testDepends.jar,将会报Could not find the main class, Program will exit.<br />在命令行执行 java -jar testDepends.jar,就会得到找不到TestDepends.class中所依赖的类的错误.<br /></span><br /><br /><img src ="http://www.blogjava.net/wiflish/aggbug/56672.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-07-05 11:00 <a href="http://www.blogjava.net/wiflish/archive/2006/07/05/56672.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>jar命令中的MANIFEST文件属性列表</title><link>http://www.blogjava.net/wiflish/archive/2006/07/05/56659.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Wed, 05 Jul 2006 02:09:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/07/05/56659.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/56659.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/07/05/56659.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/56659.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/56659.html</trackback:ping><description><![CDATA[官方链接：<a target="_blank" title="JAR File Specification" href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Manifest%20Specification"><b>JAR File Specification</b></a><br />MANIFEST.MF文件属性：<br /><h3>Main Attributes</h3>
Main attributes are the attributes that are present in the main section
of the manifest. They fall into the following different groups:
<ul><li>
general main attributes</li></ul><ul><ul><li>
Manifest-Version:</li></ul><ul>Defines the manifest file version. The value is a legitimate version
number, as described in the above spec.
<br /> 
<li>
Created-By:</li><br />Defines the version and the vendor of the java implementation on top
of which this manifest file is generated. This attribute is generated by
the <tt>jar</tt> tool.
<br /> 
<li>
Signature-Version:</li><br />Defines the signature version of the jar file. The value should be
a valid <i>version-number</i> string.
<br /> 
<li>
Class-Path :</li><br />The value of this attribute specifies the relative URLs of the extensions
or libraries that this application or extension needs. URLs are separated
by one or more spaces. The application or extension class loader uses the
value of this attribute to construct its internal search path.
<br /> </ul><li>
attribute defined for stand-alone applications</li>
This attribute is used by stand-alone applications that are bundled into
executable jar files which can be invoked by the java runtime directly
by running "<tt>java -jar x.jar</tt>".
<ul><li>
Main-Class :</li><br />The value of this attribute defines the relative path of the main application
class which the launcher will load at startup time. The value must 
<em>not</em> have the <tt>.class</tt> extension appended to the class 
name.</ul></ul><ul><li>
attributes defined for applets</li>
These attributes is used by an applet which is bundled into JAR files
to define requirements, version and location information for the extensions
which this applet depends on. (see  <a href="http://java.sun.com/j2se/1.3/docs/guide/extensions/versioning.html">Extension Versioning</a> ). 
<ul><li>
Extension-List:</li><br />This attribute indicates the extensions that are needed by the applet.
Each extension listed in this attribute will have a set of additional attributes
that the applet uses to specify which version and vendor of the extension
it requires.
<br /> 
<li>
&lt;extension&gt;-Extension-Name :</li><br />This attribute is the unique name of the extension. The Java Plug-in
will compare the value of this attribute with the Extension-Name attribute
in the manifests of installed extensions to determine if the extension
is installed.
<br /> 
<li>
&lt;extension&gt;-Specification-Version</li><br />This attribute specifies the minimum extension specification version
that is required by the applet. The Java Plug-in will compare the value
of this attribute with the Specification-Version attribute of the installed
extension to determine if the extension is up to date.
<br /> 
<li>
&lt;extension&gt;-Implementation-Version</li><br />This attritute specifies the minimum extension implementation version
number that is required by the applet. The Java Plug-in will compare the
value of this attribute with the Implementation-Version attribute of the
installed extension to see if a more recent implementation needs to be
downloaded.
<br /> 
<li>
&lt;extension&gt;-Implementation-Vendor-Id</li><br />This attribute can be used to identify the vendor of an extension implementation
if the applet requires an implementation from a specific vendor. The Java
Plug-in will compare the value of this attribute with the Implementation-Vendor-Id
attribute of the installed extension.
<br /> 
<li>
&lt;extension&gt;-Implementation-URL</li><br />This attribute specifies a URL that can be used to obtain the most
recent version of the extension if the required version is not already
installed.
<br /> </ul><li>
attribute defined for extension identification</li>
This attribute is used by extensions to define their unique identity.
<ul><li>
Extension-Name:</li>
This attribute specifies a name for the extension contained in the Jar
file. The name should be a unique identifier such as the name of the main
package comprising the extension.</ul>
 
<li>
attributes defined for extension and  package <a href="http://java.sun.com/j2se/1.3/docs/guide/versioning/index.html">versioning</a> 
and <a href="http://java.sun.com/j2se/1.3/docs/guide/extensions/spec.html#sealing">sealing</a>
information</li>
These attributes define features of the extension which the JAR file is
a part of. The value of these attributes apply to all the packages in the
JAR file, but can be overridden by per-entry attributes. 
<ul><li>
Implementation-Title :</li>
The value is a string that defines the title of the extension implementation. 
<li>
Implementation-Version :</li><br />The value is a string that defines the version of the extension implementation.
<br /> 
<li>
Implementation-Vendor :</li><br />The value is a string that defines the organization that maintains
the extension implementation.
<br /> 
<li>
Implementation-Vendor-Id :</li><br />The value is a string id that uniquely defines the organization that
maintains the  extension implementation.
<br /> 
<li>
Implementation-URL :</li><br />This attribute defines the URL from which the extension implementation
can be downloaded from.
<br /> 
<li>
 Specification-Title :</li><br />The value is a string that defines the title of the extension specification.
<br /> 
<li>
Specification-Version :</li><br />The value is a string that defines the version of the extension specification.
<br /> 
<li>
Specification-Vendor :</li><br />The value is a string that defines the organization that maintains
the extension specification.</ul></ul><ul><ul><li>
Sealed :</li><br />This attribute defines whether this JAR file is sealed or not. The
value can be either "true" or "false", case is ignored. If it is set to
"true", then all the packages in the JAR file are defaulted to be sealed,
unless they are defined otherwise individually.</ul></ul><br /><img src ="http://www.blogjava.net/wiflish/aggbug/56659.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-07-05 10:09 <a href="http://www.blogjava.net/wiflish/archive/2006/07/05/56659.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>通过java获取系统环境变量</title><link>http://www.blogjava.net/wiflish/archive/2006/07/03/56384.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Mon, 03 Jul 2006 09:11:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/07/03/56384.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/56384.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/07/03/56384.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/56384.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/56384.html</trackback:ping><description><![CDATA[代码如下：<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, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">    </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);"> Map getEnv() {<br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">        Map map </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);"> HashMap();<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">        String OS </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> System.getProperty(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">os.name</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).toLowerCase();<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">        Process p </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, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">        <br /></span><span style="color: rgb(0, 128, 128);"> 7</span>           <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 128, 0);">         * 以windows为例.<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 128, 0);">         </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</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);">(OS.indexOf(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">windows</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">) </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);">-</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">) {<br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);"> {<br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">                p </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> Runtime.getRuntime().exec(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">cmd /c set</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">                BufferedReader br </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);"> BufferedReader(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> InputStreamReader(p.getInputStream()));<br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">                <br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">                String line;<br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">                <br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">((line </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> br.readLine()) </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, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">                    String[] str </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> line.split(</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, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">                    map.put(str[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">], str[</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">]);<br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">                }<br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">            } </span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">(IOException ioe) {<br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">                ioe.printStackTrace();<br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">            }<br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">        }<br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> map;<br /></span><span style="color: rgb(0, 128, 128);">26</span> <span style="color: rgb(0, 0, 0);">    }</span></div><br />上述代码将windows系统中的环境变量转换为java的Map，只要通过map.get(key)就能得到环境变量值，比如map.get("JAVA_HOME")，得到JAVA_HOME的值，即JAVA_HOME的系统路径。<br /><br />值得注意的是在java中使用windows操作系统命令时要在命令前加<u><b> cmd /c</b></u>，否则java会报错(),错误列表如下：<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, 128, 128);"> 1</span> <span style="color: rgb(0, 0, 0);">java.io.IOException: CreateProcess: ${执行的操作命令表达式或者.bat文件} error</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);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">at java.lang.Win32Process.create(Native Method)<br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">at java.lang.Win32Process.</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">init</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">(Win32Process.java:</span><span style="color: rgb(0, 0, 0);">63</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">at java.lang.Runtime.execInternal(Native Method)<br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);">at java.lang.Runtime.exec(Runtime.java:</span><span style="color: rgb(0, 0, 0);">566</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">at java.lang.Runtime.exec(Runtime.java:</span><span style="color: rgb(0, 0, 0);">428</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">at java.lang.Runtime.exec(Runtime.java:</span><span style="color: rgb(0, 0, 0);">364</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">at java.lang.Runtime.exec(Runtime.java:</span><span style="color: rgb(0, 0, 0);">326</span><span style="color: rgb(0, 0, 0);">)<br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">at org.apache.jsp.ChangeDirBajaRCXX_jsp._jspService(ChangeDirBaja<br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">p.java:</span><span style="color: rgb(0, 0, 0);">185</span><span style="color: rgb(0, 0, 0);">)</span></div><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, 0);">The error </span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);"> comes from the CreateProcess() call, from MSDN (GetLastError():<br /><br /></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);"> The system cannot find the file specified. </span><span style="color: rgb(0, 0, 0);">-</span><span style="color: rgb(0, 0, 0);"> ERROR_FILE_NOT_FOUND<br /><br />So, it means the path you passed cannot be found. Maybe you did not configure your Runtime </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> correctly. <br />put the batch file in the same directory as the </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> file and use (</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);"> a test):</span></div><br /><img src ="http://www.blogjava.net/wiflish/aggbug/56384.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-07-03 17:11 <a href="http://www.blogjava.net/wiflish/archive/2006/07/03/56384.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>[转]java基本类装入异常</title><link>http://www.blogjava.net/wiflish/archive/2006/05/24/47837.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Wed, 24 May 2006 08:24:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/05/24/47837.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/47837.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/05/24/47837.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/47837.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/47837.html</trackback:ping><description><![CDATA[
		<p>
				<a target="_blank" class="" title="" href="http://www-128.ibm.com/developerworks/cn/java/j-dclp2.html" name="1">原文链接：http://www-128.ibm.com/developerworks/cn/java/j-dclp2.html<span class="atitle"></span></a>
		</p>
		<p>
				<a name="1">
						<span class="atitle">
						</span>
				</a>
		</p>
		<br />
		<p>
				<a name="1">
						<span class="atitle">ClassNotFoundException</span>
				</a>
		</p>
		<p>
				<code>ClassNotFoundException</code> 是最常见的类装入异常类型。它发生在装入阶段。Java 规范对 <code>ClassNotFoundException</code> 的描述是这样的：</p>
		<p>
当应用程序试图通过类的字符串名称，使用以下三种方法装入类，但却找不到指定名称的类定义时抛出该异常。</p>
		<ul>
				<li>类 <code>Class</code> 中的 <code>forName()</code> 方法。</li>
				<li>类 <code>ClassLoader</code> 中的 <code>findSystemClass()</code> 方法。</li>
				<li>类 <code>ClassLoader</code> 中的 <code>loadClass()</code> 方法。</li>
		</ul>
		<p>所以，如果显式地装入类的尝试失败，那么就抛出 <code>ClassNotFoundException</code>。清单 1 中的测试用例提供的示例代码抛出了一个 <code>ClassNotFoundException</code>：</p>
		<br />
		<a name="N100CC">
				<b>清单 1. ClassNotFoundExceptionTest.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />import java.net.MalformedURLException;<br />import java.net.URL;<br />import java.net.URLClassLoader;<br /><br />public class ClassNotFoundExceptionTest {<br /><br />    public static void main(String args[]) {<br />        try {<br />            URLClassLoader loader = new URLClassLoader(new URL[] { new URL(<br />                "file://C:/CL_Article/ClassNotFoundException/")});<br />            loader.loadClass("DoesNotExist");<br />        } catch (ClassNotFoundException e) {<br />            e.printStackTrace();<br />        } catch (MalformedURLException e) {<br />            e.printStackTrace();<br />        }<br />    }<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这个测试用例定义了一个类装入器（<code>MyClassLoader</code>），用于装入一个不存在的类（<code>DoesNotExist</code>）。当它运行时，会出现以下异常：</p>
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />java.lang.ClassNotFoundException: DoesNotExist<br />    at java.net.URLClassLoader.findClass(URLClassLoader.java:376)<br />    at java.lang.ClassLoader.loadClass(ClassLoader.java:572)<br />    at java.lang.ClassLoader.loadClass(ClassLoader.java:504)<br />    at ClassNotFoundExceptionTest.main(ClassNotFoundExceptionTest.java:11)</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>因为这个测试试图使用对 <code>loadClass()</code> 的显式调用来进行装入，所以抛出 <code>ClassNotFoundException</code>。</p>
		<p>通过抛出 <code>ClassNotFoundException</code>，类装入器提示，定义类时所需要的字节码在类装入器所查找的位置上不存在。这些异常修复起来通常比较简单。可以用 IBM 的 verbose 选项检查类路径，确保使用的类路径设置正确（要获得 verbose 的更多信息，请参阅本系列的 <a href="http://www-128.ibm.com/developerworks/cn/java/j-dclp1/">第一篇文章</a>）。如果类路径设置正确，但是仍然看到这个错误，那么就是需要的类在类路径中不存在。要修复这个问题，可以把类移动到类路径中指定的目录或 JAR 文件中，或者把类所在的位置添加到类路径中。</p>
		<br />
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" />
										<br />
										<img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" align="right" cellpadding="0" cellspacing="0">
				<tbody>
						<tr align="right">
								<td>
										<img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" />
										<br />
										<br />
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="2">
						<span class="atitle">NoClassDefFoundError</span>
				</a>
		</p>
		<p>
				<code>NoClassDefFoundError</code> 是类装入器在装入阶段抛出的另一个常见异常。JVM 规范对 <code>NoClassDefFoundError</code> 的定义如下：</p>
		<blockquote>
如果 Java 虚拟机或 <code>ClassLoader</code> 实例试图装入类定义（作为正常的方法调用的一部分，或者作为使用 new 表达式创建新实例的一部分），但却没有找到类定义时抛出该异常。
<br /><br />
当目前执行的类已经编译，但是找不到它的定义时，会存在 searched-for 类定义。
</blockquote>
		<p>实际上，这意味着 <code>NoClassDefFoundError</code> 的抛出，是不成功的隐式类装入的结果。</p>
		<p>清单 2 到清单 4 的测试用例产生了 <code>NoClassDefFoundError</code>，因为类 <code>B</code> 的隐式装入会失败：</p>
		<br />
		<a name="N1012A">
				<b>清单 2. NoClassDefFoundErrorTest.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class NoClassDefFoundErrorTest {<br />	public static void main(String[] args) {<br />		A a = new A();<br />	}<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<a name="N10134">
				<b>清单 3. A.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class A extends B {<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<a name="N1013E">
				<b>清单 4. B.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class B {<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这几个清单中的代码编译好之后，删除 <code>B</code> 的类文件。当代码执行时，就会出现以下错误：</p>
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />Exception in thread "main" java.lang.NoClassDefFoundError: B<br />    at java.lang.ClassLoader.defineClass0(Native Method)<br />    at java.lang.ClassLoader.defineClass(ClassLoader.java:810)<br />    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:147)<br />    at java.net.URLClassLoader.defineClass(URLClassLoader.java:475)<br />    at java.net.URLClassLoader.access$500(URLClassLoader.java:109)<br />    at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:848)<br />    at java.security.AccessController.doPrivileged1(Native Method)<br />    at java.security.AccessController.doPrivileged(AccessController.java:389)<br />    at java.net.URLClassLoader.findClass(URLClassLoader.java:371)<br />    at java.lang.ClassLoader.loadClass(ClassLoader.java:572)<br />    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:442)<br />    at java.lang.ClassLoader.loadClass(ClassLoader.java:504)<br />    at NoClassDefFoundErrorTest.main(NoClassDefFoundErrorTest.java:3)<br /></code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>类 <code>A</code> 扩展了类 <code>B</code>；所以，当类 <code>A</code> 装入时，类装入器会隐式地装入类 <code>B</code>。因为类 <code>B</code> 不存在，所以抛出 <code>NoClassDefFoundError</code>。如果显式地告诉类装入器装入类 <code>B</code>（例如通过 <code>loadClass("B")</code> 调用），那么就会抛出 <code>ClassNotFoundException</code>。</p>
		<p>显然，要修复这个特殊示例中的问题，在对应的类装入器的类路径中，必须存在类 <code>B</code>。这个示例看起来可能价值不大、也不真实，但是，在复杂的有许多类的真实系统中，会因为类在打包或部署期间的遗失而发生这类情况。</p>
		<p>在这个例子中，<code>A</code> 扩展了 <code>B</code>；但是，即使 <code>A</code> 用其他方式引用 <code>B</code>，也会出现同样的问题 —— 例如，以方法参数引用或作为实例字段。如果两个类之间的关系是引用关系而不是继承关系，那么会在第一次使用 <code>A</code> 时抛出错误，而不是在装入 <code>A</code> 时抛出。</p>
		<br />
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" />
										<br />
										<img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" align="right" cellpadding="0" cellspacing="0">
				<tbody>
						<tr align="right">
								<td>
										<img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" />
										<br />
										<br />
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="3">
						<span class="atitle">ClassCastException</span>
				</a>
		</p>
		<p>类装入器能够抛出的另一个异常是 <code>ClassCastException</code>。它是在类型比较中发现不兼容类型的时候抛出的。JVM 规范指定 <code>ClassCastException</code> 是：</p>
		<blockquote>
该异常的抛出，表明代码企图把对象的类型转换成一个子类，而该对象并不是这个子类的实例。
</blockquote>
		<p>清单 5 演示的代码示例会产生一个 <code>ClassCastException</code>：</p>
		<br />
		<a name="N101B8">
				<b>清单 5. ClassCastException.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class ClassCastExceptionTest {<br />    public ClassCastExceptionTest() {<br />    }<br /><br />    private static void storeItem(Integer[] a, int i, Object item) {<br />        a[i] = (Integer) item;<br />    }<br /><br />    public static void main(String args[]) {<br />        Integer[] a = new Integer[3];<br />        try {<br />            storeItem(a, 2, new String("abc"));<br />        } catch (ClassCastException e) { <br />            e.printStackTrace();<br />        }<br />    }<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>在清单 5 中，调用了 <code>storeItem()</code> 方法，使用一个 <code>Integer</code> 数组、一个 <code>int</code> 和一个字符串作为参数。但是在内部，该方法做了两件事：</p>
		<ul>
				<li>隐式地把 <code>String</code> 对象类型转换成 <code>Object</code> 类型（用于参数列表）。</li>
				<li>显式地把这个 <code>Object</code> 类型转换成 <code>Integer</code> 类型（在方法定义中）。</li>
		</ul>
		<p>当程序运行时，会出现以下异常：</p>
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />java.lang.ClassCastException: java.lang.String<br />    at ClassCastExceptionTest.storeItem(ClassCastExceptionTest.java:6)<br />    at ClassCastExceptionTest.main(ClassCastExceptionTest.java:12)</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这个异常是由显式类型转换抛出的，因为测试用例试图把类型为 <code>String</code> 的东西转换成 <code>Integer</code>。</p>
		<p>当检查对象（例如清单 5 中的 <code>item</code>）并把类型转换成目标类（<code>Integer</code>）时，类装入器会检查以下规则：</p>
		<ul>
				<li>
						<b>对于普通对象（非数组）：</b>对象必须是目标类的实例或目标类的子类的实例。如果目标类是接口，那么会把它当作实现了该接口的一个子类。<br /><br /></li>
				<li>
						<b>对于数组类型：</b>目标类必须是数组类型或 <code>java.lang.Object</code>、<code>java.lang.Cloneable</code> 或 <code>java.io.Serializable</code>。</li>
		</ul>
		<p>如果违反了以上任何一条规则，那么类装入器就会抛出 <code>ClassCastException</code>。修复这类异常的最简单方式就是仔细检查对象要转换到的类型是否符合以上提到的规则。在某些情况下，在做类型转换之前用 <code>instanceof</code> 进行检查是有意义的。</p>
		<br />
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" />
										<br />
										<img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" align="right" cellpadding="0" cellspacing="0">
				<tbody>
						<tr align="right">
								<td>
										<img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" />
										<br />
										<br />
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="4">
						<span class="atitle">UnsatisfiedLinkError</span>
				</a>
		</p>
		<p>在把本机调用链接到对应的本机定义时，类装入器扮演着重要角色。如果程序试图装入一个不存在或者放错的本机库时，在链接阶段的解析过程会发生 <code>UnsatisfiedLinkError</code>。JVM 规范指定 <code>UnsatisfiedLinkError</code> 是：</p>
		<blockquote>
对于声明为 <code>native</code> 的方法，如果 Java 虚拟机找不到和它对应的本机语言定义，就会抛出该异常。
</blockquote>
		<p>当调用本机方法时，类装入器会尝试装入定义了该方法的本机库。如果找不到这个库，就会抛出这个错误。</p>
		<p>清单 6 演示了抛出 <code>UnsatisfiedLinkError</code> 的测试用例 ：</p>
		<br />
		<a name="listing6">
				<b>清单 6. UnsatisfiedLinkError.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class UnsatisfiedLinkErrorTest {<br /><br />    public native void call_A_Native_Method();<br /><br />    static {<br />        System.loadLibrary("myNativeLibrary");<br />    }<br /><br />    public static void main(String[] args) {<br />        new UnsatisfiedLinkErrorTest().call_A_Native_Method();<br />    }<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这段代码调用本机方法 <code>call_A_Native_Method()</code>，该方法是在本机库 <code>myNativeLibrary</code> 中定义的。因为这个库不存在，所以在程序运行时会发生以下错误：</p>
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />The java class could not be loaded. java.lang.UnsatisfiedLinkError:<br />  Can't find library myNativeLibrary  (myNativeLibrary.dll)<br />  in sun.boot.library.path or java.library.path<br />sun.boot.library.path=D:\sdk\jre\bin<br />java.library.path= D:\sdk\jre\bin<br /><br />at java.lang.ClassLoader$NativeLibrary.load(Native Method)<br />    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2147)<br />    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:2006)<br />    at java.lang.Runtime.loadLibrary0(Runtime.java:824)<br />    at java.lang.System.loadLibrary(System.java:908)<br />    at UnsatisfiedLinkErrorTest.&lt;clinit&gt;(UnsatisfiedLinkErrorTest.java:6)<br /></code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>本机库的装入由调用 <code>System.loadLibrary()</code> 方法的类的类装入器启动 —— 在清单 6 中，就是 <code>UnsatisfiedLinkErrorTest</code> 的类装入器。根据使用的类装入器，会搜索不同的位置：</p>
		<ul>
				<li>对于由 bootstrap 类装入器装入的类，搜索 <code>sun.boot.library.path</code>。</li>
				<li>对于由扩展类装入器装入的类，先搜索 <code>java.ext.dirs</code>，然后是 <code>sun.boot.library.path</code>，然后是 <code>java.library.path</code>。</li>
				<li>对于由系统类装入器装入的类，搜索 <code>sun.boot.library.path</code>，然后是 <code>java.library.path</code>。</li>
		</ul>
		<p>在清单 6 中，<code>UnsatisfiedLinkErrorTest</code> 类是由系统类装入器装入的。要装入所引用的本机库，这个类装入器先查找 <code>sun.boot.library.path</code>，然后查找 <code>java.library.path</code>。因为在两个位置中都没有需要的库，所以类装入器抛出 <code>UnsatisfiedLinkageError</code>。</p>
		<p>一旦理解了库装入过程所涉及的类装入器，就可以通过把库放在合适位置来解决这类问题。</p>
		<br />
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" />
										<br />
										<img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" align="right" cellpadding="0" cellspacing="0">
				<tbody>
						<tr align="right">
								<td>
										<img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" />
										<br />
										<br />
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="5">
						<span class="atitle">ClassCircularityError</span>
				</a>
		</p>
		<p>JVM 规范指定 <code>ClassCircularityError</code> 的抛出条件是：</p>
		<blockquote>
类或接口由于是自己的超类或超接口而不能被装入。
</blockquote>
		<p>这个错误是在链接阶段的解析过程中抛出的。这个错误有点奇怪，因为 Java 编译器不允许发生这种循环情况。但是，如果独立地编译类，然后再把它们放在一起，就可能发生这个错误。请设想以下场景。首先，编译清单 7 和清单 8 中的类：</p>
		<br />
		<a name="listing7">
				<b>清单 7. A.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class A extends B {<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<a name="N102D0">
				<b>清单 8. B.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class B {<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>然后，分别编译清单 9 和清单 10 中的类：</p>
		<br />
		<a name="listing9">
				<b>清单 9. A.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class A {<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<a name="listing10">
				<b>清单 10. B.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class B extends A {<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>最后，采用清单 7 的类 <code>A</code> 和清单 10 的类 <code>B</code>，并运行一个应用程序，试图装入 <code>A</code> 或者 <code>B</code>。这个情况看起来可能不太可能，但是在复杂的系统中，在把不同部分放在一起的时候，可能会发生类似的情况。</p>
		<p>显然，要修复这个问题，必须避免循环的类层次结构。</p>
		<br />
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" />
										<br />
										<img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" align="right" cellpadding="0" cellspacing="0">
				<tbody>
						<tr align="right">
								<td>
										<img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" />
										<br />
										<br />
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="6">
						<span class="atitle">ClassFormatError</span>
				</a>
		</p>
		<p>JVM 规范指出，抛出 <code>ClassFormatError</code> 的条件是：</p>
		<blockquote>
负责指定所请求的编译类或接口的二进制数据形式有误。
</blockquote>
		<p>这个异常是在类装入的链接阶段的校验过程中抛出。如果字节码发生了更改，例如主版本号或次版本号发生了更改，那么二进制数据的形式就会有误。例如，如果对字节码故意做了更改，或者在通过网络传送类文件时现出了错误，那么就可能发生这个异常。</p>
		<p>修复这个问题的惟一方法就是获得字节码的正确副本，可能需要重新进行编译。</p>
		<br />
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<img src="http://www.ibm.com/i/v14/rules/blue_rule.gif" alt="" height="1" width="100%" />
										<br />
										<img alt="" src="http://www.ibm.com/i/c.gif" border="0" height="6" width="8" />
								</td>
						</tr>
				</tbody>
		</table>
		<table class="no-print" align="right" cellpadding="0" cellspacing="0">
				<tbody>
						<tr align="right">
								<td>
										<img src="http://www.ibm.com/i/c.gif" alt="" height="4" width="100%" />
										<br />
										<br />
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<br />
		<p>
				<a name="7">
						<span class="atitle">ExceptionInInitializerError</span>
				</a>
		</p>
		<p>根据 JVM 规范，抛出 <code>ExceptionInInitializer</code> 的情况是：</p>
		<ul>
				<li>如果初始化器突然完成，抛出一些异常 <code>E</code>，而且 <code>E</code> 的类不是 <code>Error</code> 或者它的某个子类，那么就会创建 <code>ExceptionInInitializerError</code> 类的一个新实例，并用 <code>E</code> 作为参数，用这个实例代替 <code>E</code>。<br /><br /></li>
				<li>如果 Java 虚拟机试图创建类 <code>ExceptionInInitializerError</code> 的新实例，但是因为出现 <code>Out-Of-Memory-Error</code> 而无法创建新实例，那么就抛出 <code>OutOfMemoryError</code> 对象作为代替。</li>
		</ul>
		<p>清单 8 中的代码抛出 <code>ExceptionInInitializerError</code>：</p>
		<br />
		<a name="listing8">
				<b>清单 8. ExceptionInInitializerErrorTest.java</b>
		</a>
		<br />
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />
														<br />public class ExceptionInInitializerErrorTest {<br />    public static void main(String[] args) {<br />        A a = new A();<br />    }<br />}<br /><br />class A {<br />    // If the SecurityManager is not turned on, a <br />    // java.lang.ExceptionInInitializerError will be thrown <br />    static {<br />        if(System.getSecurityManager() == null)<br />            throw new SecurityException();<br />    }<br />}</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>当静态代码块中发生异常时，会被自动捕捉并用 <code>ExceptionInInitializerError</code> 包装该异常。在下面的输出中可以看到这点：</p>
		<table bgcolor="#eeeeee" border="1" cellpadding="5" cellspacing="0" width="100%">
				<tbody>
						<tr>
								<td>
										<pre>
												<code class="section">
														<br />Exception in thread "main" java.lang.ExceptionInInitializerError<br />   at ExceptionInInitializerErrorTest.main(ExceptionInInitializerErrorTest.java:3)<br />Caused by: java.lang.SecurityException<br />   at A.&lt;clinit&gt;(ExceptionInInitializerErrorTest.java:12)<br />   ... 1 more</code>
										</pre>
								</td>
						</tr>
				</tbody>
		</table>
		<br />
		<p>这个错误在类装入的初始化阶段抛出。修复这个错误的方法是检查造成 <code>ExceptionInInitializerError</code> 的异常（在堆栈跟踪的 <code>Caused by:</code> 下显示）并寻找阻止抛出这个异常的方式。</p>
<img src ="http://www.blogjava.net/wiflish/aggbug/47837.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-05-24 16:24 <a href="http://www.blogjava.net/wiflish/archive/2006/05/24/47837.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Google Web Toolkit</title><link>http://www.blogjava.net/wiflish/archive/2006/05/22/47455.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Mon, 22 May 2006 06:12:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/05/22/47455.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/47455.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/05/22/47455.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/47455.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/47455.html</trackback:ping><description><![CDATA[
		<p>Google Web Toolkit (GWT) is a Java software development framework that makes writing AJAX applications like <a href="http://maps.google.com/">Google Maps</a> and <a href="http://mail.google.com/">Gmail</a>
easy for developers who don't speak browser quirks as a second
language. Writing dynamic web applications today is a tedious and
error-prone process; you spend 90% of your time working around subtle
incompatabilities between web browsers and platforms, and JavaScript's
lack of modularity makes sharing, testing, and reusing AJAX components
difficult and fragile.</p>
		<p>GWT lets you avoid many of these headaches while offering your users
the same dynamic, standards-compliant experience. You write your front
end in the <a href="http://java.sun.com/" rel="nofollow">Java</a> programming language, and the GWT compiler converts your Java classes to browser-compliant JavaScript and HTML.</p>
		<p>GWT website: <a href="http://code.google.com/webtoolkit/">http://code.google.com/webtoolkit/</a><br /></p>
<img src ="http://www.blogjava.net/wiflish/aggbug/47455.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-05-22 14:12 <a href="http://www.blogjava.net/wiflish/archive/2006/05/22/47455.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ant中宏定义例子</title><link>http://www.blogjava.net/wiflish/archive/2006/05/18/46856.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Thu, 18 May 2006 08:47:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/05/18/46856.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/46856.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/05/18/46856.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/46856.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/46856.html</trackback:ping><description><![CDATA[
		<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, 128, 128);">一个ant中用于编译的宏定义例子：<br /> 1</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">macrodef name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">compile</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 2</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">attribute name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">module</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 3</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">attribute name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">additional.src.dirs</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">default</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 4</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">element name</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">options</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> optional</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">yes</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 5</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 6</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">sequential</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 7</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">echo</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">Compiling @{module}<img src="http://www.blogjava.net/images/dot.gif" /></span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">echo</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 8</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">mkdir dir</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${build.dir}/@{module}/classes</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 9</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">mkdir dir</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${test.dir}/@{module}/classes</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">10</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">javac srcdir</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${src}/@{module};@{additional.src.dirs}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">11</span> <span style="color: rgb(0, 0, 0);">                destdir</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${build.dir}/@{module}/classes</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> debug</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${compile.debug}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">12</span> <span style="color: rgb(0, 0, 0);">                deprecation</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${compile.deprecation}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> optimize</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${compile.optimize}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">13</span> <span style="color: rgb(0, 0, 0);">                classpathref</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">@{module}.compile.classpath</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">14</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">options</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">15</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">javac</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">16</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">javac srcdir</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">test/@{module}</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> debug</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">true</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">17</span> <span style="color: rgb(0, 0, 0);">                destdir</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${test.dir}/@{module}/classes</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">18</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">classpath</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">19</span> <span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">path refid</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">@{module}.test.classpath</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">20</span> <span style="color: rgb(0, 0, 0);">                    </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">path location</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${build.dir}/@{module}/classes</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">21</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">classpath</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">22</span> <span style="color: rgb(0, 0, 0);">                </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">options</span><span style="color: rgb(0, 0, 0);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">23</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">javac</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">24</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">sequential</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">25</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 0);">&lt;/</span><span style="color: rgb(0, 0, 0);">macrodef</span><span style="color: rgb(0, 0, 0);">&gt;<br /><br /></span><span style="color: rgb(0, 128, 128);"></span><span style="color: rgb(0, 0, 0);">   </span><span style="color: rgb(0, 128, 128);">调用宏代码： <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, 0);">1、</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">compile module</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">web</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);"> additional.src.dirs</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">${build.dir}/web/gen</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">/&gt;<br />2、&lt;compile module="dao"/&gt;<br /></span></div></span><span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 128);"></span></div>
<img src ="http://www.blogjava.net/wiflish/aggbug/46856.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-05-18 16:47 <a href="http://www.blogjava.net/wiflish/archive/2006/05/18/46856.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ant property标签粗解</title><link>http://www.blogjava.net/wiflish/archive/2006/05/12/45814.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Fri, 12 May 2006 03:49:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/05/12/45814.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/45814.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/05/12/45814.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/45814.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/45814.html</trackback:ping><description><![CDATA[
		<h2>
				<a name="property">Property设置属性的7种方法：</a>
		</h2>
		<h2>
				<a name="property">
				</a>
		</h2>
		<h2>
				<a name="property">
				</a>
		</h2>1、设置name和value属性值，比如：&lt;property name="srcdir" value="${basedir}/src"/&gt;<br />2、设置name和refid属性值，比如：&lt;property name="srcpath" refid="dao.compile.classpath"/&gt;，其中    dao.compile.classpath在别的地方定义。<br />3、设置name和location属性值，比如：&lt;property name="srcdir" location="src"/&gt;，即将srcdir的值设    置为：当前项目根目录的/src目录。<br />4、设置file属性值，比如：&lt;property file="build.properties"/&gt;， 导入build.properties属性文件中    的属性值<br />5、设置resource属性值，比如：&lt;propety resource="build.properties"/&gt;,导入build.properties属性文    件中的属性值<br />6、设置url属性值，比如：&lt;property url="http://www.blogjava.net/wiflish/build.properties"/&gt;,导    入http://www.blogjava.net/wiflish/build.properties属性文件中的属性值。<br />7、设置环境变量，比如：&lt;property environment="env"/&gt;，设置系统的环境变量为前缀env.<br />      &lt;property name="tomcat.home" value="${env.CATALINA_HOME}"/&gt; 将系统的tomcat安装目录设置到    tomcat.home属性中。<br /><img src ="http://www.blogjava.net/wiflish/aggbug/45814.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-05-12 11:49 <a href="http://www.blogjava.net/wiflish/archive/2006/05/12/45814.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Xdoclet的标签及用法</title><link>http://www.blogjava.net/wiflish/archive/2006/05/11/45626.html</link><dc:creator>想飞的鱼</dc:creator><author>想飞的鱼</author><pubDate>Thu, 11 May 2006 03:43:00 GMT</pubDate><guid>http://www.blogjava.net/wiflish/archive/2006/05/11/45626.html</guid><wfw:comment>http://www.blogjava.net/wiflish/comments/45626.html</wfw:comment><comments>http://www.blogjava.net/wiflish/archive/2006/05/11/45626.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/wiflish/comments/commentRss/45626.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wiflish/services/trackbacks/45626.html</trackback:ping><description><![CDATA[参照链接: <a target="_blank" class="" title="Xdoclet的标签及用法" href="http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-tags.html#@hibernate.class%20%280..1%29">Xdoclet的标签及用法</a><br /><img src ="http://www.blogjava.net/wiflish/aggbug/45626.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wiflish/" target="_blank">想飞的鱼</a> 2006-05-11 11:43 <a href="http://www.blogjava.net/wiflish/archive/2006/05/11/45626.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>