??xml version="1.0" encoding="utf-8" standalone="yes"?>中文字幕在线观看一区,久久全国免费视频,国产精品久久久久久久久图文区http://www.aygfsteel.com/mlh123caoer/category/11360.html无ؓ则可为,无ؓ则至深! zh-cnTue, 04 Oct 2011 17:29:42 GMTTue, 04 Oct 2011 17:29:42 GMT60Java heap dump触发和分?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2011/10/04/360020.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Tue, 04 Oct 2011 14:31:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2011/10/04/360020.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/360020.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2011/10/04/360020.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/360020.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/360020.html</trackback:ping><description><![CDATA[<span id="wmqeeuq" class="Apple-style-span" style="color: #4e4e4e; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: normal; background-color: #ffffff; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">Z分析java应用的内存泄漏,使用thread dump往往解决不了问题。用jstat【egQ?a target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; color: #0071bb; outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; ">jstat </a>-gcutil pid 1000 5】工h看运行的java应用的heap size,perm size ,survivor ratio{,当时你无法知道是什么对象把堆填满了?/span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 9px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, helvetica, sans-serif; line-height: 21px; background-color: #e6e6fa; height: 25px; width: 602px; font-size: 14px; color: #000000; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; ">     什么是 Java heap dump<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; " /></strong></span></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 6px; padding-left: 6px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; border-left-width: 2px; border-left-style: solid; border-left-color: #cccccc; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">      首先需要搞懂什么是java heapQjava heap是分配给实例cd数组对象q行数据区,所有javaU程在运行期间共享heap中的数据。Java heap dump相当于java应用在运行的时候在某个旉点上打了个快照(snapshotQ?/span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">     如果你不懂啥是snapshotQ点?a target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; color: #0071bb; outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; ">q里</a></span></p></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 9px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, helvetica, sans-serif; line-height: 21px; background-color: #e6e6fa; height: 25px; width: 602px; font-size: 14px; color: #000000; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; ">     触发 Java heap dump</strong></span></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 6px; padding-left: 6px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; border-left-width: 2px; border-left-style: solid; border-left-color: #cccccc; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">有以下方法出发heap dump</span></p><ol style="margin-top: 0.4em; margin-right: 0px; margin-bottom: 1em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; list-style-position: outside; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">使用$JAVA_HOME/bin/<a style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; color: #0071bb; outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; ">jmap</a> -dump来触发,egQjmap -dump:format=b,file=/home/longhao/heamdump.out <pid></span></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; list-style-position: outside; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">使用$JAVA_HOME/bin/<a target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; color: #0071bb; outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; ">jcosole</a>中的MBeanQ到MBean>com.sun.management>HotSpotDiagnostic>操作>dumpHeap中,点击 dumpHeap按钮。生成的dump文g在java应用的根目录下面?/span></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; list-style-position: outside; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">在应用启动时配置相关的参?-XX:+HeapDumpOnOutOfMemoryErrorQ当应用抛出OutOfMemoryError时生成dump文g?/span></li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 2.5em; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; list-style-position: outside; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">使用<a target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; color: #0071bb; outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; ">hprof</a>。启动虚拟机加入-Xrunhprof:head=siteQ会生成java.hprof.txt文g。该配置会导致jvmq行非常的慢Q不适合生环境?/span></li></ol><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; "><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; " /></span></p></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 9px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, helvetica, sans-serif; line-height: 21px; background-color: #e6e6fa; height: 25px; width: 602px; font-size: 14px; color: #000000; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; ">     分析 Java heap dump</strong></span></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 6px; padding-left: 6px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; border-left-width: 2px; border-left-style: solid; border-left-color: #cccccc; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 9px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, helvetica, sans-serif; line-height: 21px; background-color: #e6e6fa; height: 25px; width: 588px; font-size: 14px; color: #000000; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; ">     1Q用IBM HeapAnalyzer<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; " /></strong></span></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 6px; padding-left: 6px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; border-left-width: 2px; border-left-style: solid; border-left-color: #cccccc; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">    <a target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; color: #0071bb; outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; ">IBM HeapAnalyzer</a>是一Ƒօ费的JVM内存堆的囑Ş分析工具Q它可以有效的列丑֠的内存用状况,帮助分析Java内存泄漏的原因?/span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">    下蝲解压后有一个ha413.jarQ执? java -Xmx512m -jar ha413.jar /home/longhao/heapdump.out</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">     执行l果如图所C:</span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; text-align: center; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; "><img alt="" src="http://farm6.static.flickr.com/5176/5573840400_7d8e21a701.jpg" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; " /></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">   </span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "></p></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 9px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, helvetica, sans-serif; line-height: 21px; background-color: #e6e6fa; height: 25px; width: 588px; font-size: 14px; color: #000000; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; ">     2Qjhat</strong></span></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 6px; padding-left: 6px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; border-left-width: 2px; border-left-style: solid; border-left-color: #cccccc; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">   <a target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; color: #0071bb; outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; "> jhatQJava Head Analyse Tool Q?/a>是用来分析java堆的命oQ可以将堆中的对象以html的Ş式显C出来,包括对象的数量,大小{等Qƈ支持对象查询语言OQLQ分析相关的应用后,可以通过http://localhost:7000来访问分析结果?/span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">    CZ: $JAVA_HOME/bin/jhat -J-Xmx512m /home/longhao/dump.out<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; " /></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; text-align: center; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; "><img alt="" height="500" src="http://farm6.static.flickr.com/5013/5573880930_5f758206f8.jpg" width="474" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; " /></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "></p></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 9px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: arial, helvetica, sans-serif; line-height: 21px; background-color: #e6e6fa; height: 25px; width: 588px; font-size: 14px; color: #000000; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; "><strong style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; ">     3QEclipse MemoryAnalyzer<br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; " /></strong></span></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 6px; padding-left: 6px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; border-left-width: 2px; border-left-style: solid; border-left-color: #cccccc; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">   <a target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; color: #0071bb; outline-style: none; outline-width: initial; outline-color: initial; text-decoration: none; "> Eclipse Memory Analyzer</a>是一个快速ƈ且功能强大的Java heap分析器,能够帮助你查扑ֆ存泄漏和减少内存消耗。在File>Acquire Heap Dump>configure>HPROF jmap dump provider讄一下分析应用的JDKQ点ȝ兛_用列表来生成heap dumpq分析?br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; " /></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; text-align: center; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">    <img alt="" src="http://farm6.static.flickr.com/5303/5573880998_98d2cd5d98.jpg" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /><br style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; " /></span></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "></p></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.8em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; line-height: 21px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: 'Segoe UI', Calibri, 'Myriad Pro', Myriad, 'Trebuchet MS', Helvetica, Arial, sans-serif; font-size: 14px; ">    在socketQnio中的有些API中,甌的内存是直接向OS要的Q在堆中分析内存是查看不到的Q可以通过-XX:MaxDirectMemorySize=<size>来设|应用向OS直接甌的最大内存数?/span></p></div></span><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/360020.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2011-10-04 22:31 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2011/10/04/360020.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>java中Class.getResource用法http://www.aygfsteel.com/mlh123caoer/archive/2009/09/29/296937.html草儿草儿Tue, 29 Sep 2009 11:43:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2009/09/29/296937.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/296937.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2009/09/29/296937.html#Feedback0http://www.aygfsteel.com/mlh123caoer/comments/commentRss/296937.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/296937.html阅读全文

草儿 2009-09-29 19:43 发表评论
]]>
OOME错误抛出原因http://www.aygfsteel.com/mlh123caoer/archive/2008/09/20/230104.html草儿草儿Sat, 20 Sep 2008 03:20:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2008/09/20/230104.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/230104.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2008/09/20/230104.html#Feedback0http://www.aygfsteel.com/mlh123caoer/comments/commentRss/230104.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/230104.html
OOME错误抛出原因Q排列以发生的可能性ؓ据)Q?/div>
  1. Java Heap中无法申请到_的内存用于创建新的objectQJVM会抛出OOME错误
      Ҏ异常发生的日志分析,有可能是因ؓPOP3受信Ӟ发生死锁Q导致旧对象无法?/div>
      放,Java heap 内存过最大分配内存,OOME抛出?/div>
   2. Native memory JVM正常q行?JNI调用W三方库时分配内存。Native内存会在JVMq程所
      需要的内存向系l申P如果JNI调用不能甌到内存就会抛出OOME错误?/div>
   3. Process memory size 不够。这U可能性比较小?/div>

草儿 2008-09-20 11:20 发表评论
]]>Java学习W记 - 基础?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/12/16/168109.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Sun, 16 Dec 2007 13:04:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/12/16/168109.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/168109.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/12/16/168109.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/168109.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/168109.html</trackback:ping><description><![CDATA[<div><strong>一、面向对象的~程概念</strong><strong></strong></div> <div><strong></strong></div> <div>观察现实对象两个性质Q状态、行为?/div> <div></div> <div>面向对象的好处:模块化、隐藏信息?/div> <div></div> <div>l承Q子cM父类Q超c)l承状态和行ؓQ子cd以改变父cȝ状态和行ؓ?/div> <div></div> <div>接口Q是无关对象用来q行彼此交互的设备;一个对象可以实现多个接口?/div> <div></div> <div></div> <div><strong>二、语a基础</strong><strong></strong></div> <div></div> <div><strong>变量</strong><strong></strong></div> <div>对象它的状态存储在变量中;变量是一个由标识W命名的数据V?/div> <div>声明变量的Ş式:<cd> <名称></div> <div></div> <div><strong>JAVA</strong><strong>语言两大数据cd</strong><strong></strong></div> <div>原始cd数据(基本数据cd)、引用类型?/div> <div>原始cd数据是不能再分解的数据类?8U:byte、short、int、long、float、double、char、boolean)Q数据在作ؓ函数参数是以“传?#8221;方式工作的;</div> <div></div> <div><strong>整数</strong>           byteQ?字节长的整数Q?位有W号的二q制补码整数</div> <div>                  shortQ短整数Q?6位有W号的二q制补码整数</div> <div>                  intQ整敎ͼ32位有W号的二q制补码整数</div> <div>                  longQ长整数Q?4位有W号的二q制补码整数</div> <div></div> <div><strong>实数</strong>            flatQ单_ֺ点敎ͼ32位IEEE 754点?/div> <div>                  doubleQ双_ֺ点敎ͼ64位IEEE 754点?/div> <div></div> <div><strong>其他cd</strong> charQ单一Unicode字符Q?6位Unicode字符</div> <div>                  booleanQ布?true或false)Q??1?8位空_1位数?</div> <div>     </div> <div>引用cd包括c?class)、接?interface)、数l?array)。引用类型有时也U复合类型,它是可以分解为基本类型的数据cdQ其数据在作为函数参数时是以“传址”的方式工作的。与原始cd相对Q引用类型变量的值是对由此变量代表的一个值或一l值的引用(也就是地址)?/div> <div></div> <div><strong>如:</strong><strong></strong></div> <div>原始cd int a = 3; //“a”表示变量名称Q?#8220;3”表示变量|如果写成“final int a = 3;”Q?#8220;final”表示不可改变|所以这里的3(变量?不可?/div> <div>引用cd Staing b = "Hello Java"; //“b”表示引用名称Q?#8220;Hello Java”表示字Q串数l?/div> <div></div> <div><strong>程控制语句</strong><strong></strong></div> <div>循环         while、do - while、for</div> <div>判断         if - else、switch - case</div> <div>异常处理 try – catch – finally、throw</div> <div>分支         break、continue、label :、return</div> <div></div> <div>循环Q?/div> <div>while和do – while语句QWhile语句用于在条件保持ؓtrue时反复执行一个代码块Q?/div> <div>do – while语句的代码块中的语句臛_被执行一ơ?/div> <div></div> <div>for语句Q?/div> <div>for语句提供一UP代某个范围内的值的紧湊方式?/div> <div></div> <div>判断Q?/div> <div>if – else 语句Qif语句使程序能够根据某些条件有选择地执行其他语句;</div> <div>switch语句用于Ҏ一个整数表辑ּ有条件的执行语句Q?/div> <div>注意Q必要有明的break语句Q否则,程控制一个接一个的l过后面的case语句</div> <div>比较if语句和switch语句(if语句可以用于Ҏ某范围的值或条gq行判断;switch语句只用于根据单个整数D行判??/div> <div></div> <div>异常处理语句Q?/div> <div>当程序发生错误时Q程序会抛出一个异常,E序的正常流E被中断Q?/div> <div>分支语句Qbreak、continue语句可以和标{语句一起用,也可以没有标{;</div> <div>标签是放在一个语句前的标识符Q标识符后跟一个冒P</div> <div>continue 语句Qcontinue语句用于跌for、while、do – while循环的当前P代;</div> <div>return 语句Q返回一个|不返回倹{?/div> <div></div> <div></div> <div><strong>三、对象基和简单数据结?/strong><strong></strong></div> <div><strong></strong></div> <div>创徏对象Q声明一个变量来引用变量Q对对象q行实例?构造器)Q?/div> <div>用new操作W和构造器从类创徏对象?/div> <div></div> <div>两种方式使用一个对象:引用一个对象的变量Q调用对象的Ҏ?/div> <div></div> <div><strong>字符和字W串</strong><strong></strong></div> <div>JAVAq_包含三个用于处理字符数据的类Q?/div> <div>CharacterQ包含单个字W|定义了一些可用于操作和检查单字符数据的方?Charactercȝ对象实例包含单个字符|可用Character对象替代基本cdchar)?/div> <div>StringQ这个类用于处理由多个字W组成的不可改变的数据?/div> <div>StringBufferQ存储和操作由多个字W组成的可改变的数据?/div> <div></div> <div><strong>字符串和字符串缓冲区</strong><strong></strong></div> <div>StringQ不能改变自w的倹{?/div> <div>StringBufferQ用于将被修改的字符丌Ӏ?/div> <div></div> <div><strong>得到字符串或字符串缓冲区的长?/strong><strong></strong></div> <div>lengthҎQ返回字W串或字W串~冲Z包含的字W数?/div> <div>capacityҎQStringBufferҎQ返回分配给字符串缓冲区的空间量Q而不是被使用的空间量?/div> <div>StringcL有capacityҎQ因为字W串不能改变?/div> <div></div> <div><strong>通过索引从字W串或字W串~冲区得到字W?/strong><strong></strong></div> <div>charAt(int)ҎQ得到字W串或字W串~冲区某索引位置上的字符?/div> <div>注意Q第一个字W串的烦引ؓ0Q最后一个字W的索引为length – 1Q?/div> <div>subString(int), subString(int,int)Q从字符串或字符串缓冲区中得到多个字W?/div> <div></div> <div><strong>在字W串中搜索字W或子字W串</strong><strong></strong></div> <div>StringcL供了两个讉K器方法:indexOf Ҏ从字W串的开头向前搜索;lastIndexOf Ҏ从字W串的末֐后搜索;</div> <div>StringBuffercM支持indexOf和lastIndexOfҎ?/div> <div></div> <div><strong>操作字符?/strong><strong></strong></div> <div>StringcL几个Ҏ看v来可以修改字W串。当Ӟ字符串是不能被修改的Q所以,q些Ҏ实际上是创徏q返回包含结果的另一个字W串?/div> <div></div> <div><strong>修改字符串缓?/strong><strong></strong></div> <div>字符串缓冲是可以修改的,StingBuffer提供了几个用于修改字W串~冲区的数据的方法;</div> <div>如果修改字符串缓冲区的操作造成字符串缓冲区的大超出它的当前容量,那么字符串缓冲区会自动分配更多的内存?/div> <div></div> <div><strong>字符串和~译?/strong><strong></strong></div> <div>~译器在很多地方自动的用String和StringBuffercL处理字符串直接值和字符串连接;</div> <div>~译器ؓ它遇到的每个字符串直接D动创Z个新的String对象Q?/div> <div>可以使用+操作W连接字W串?/div> <div></div> <div></div> <div><strong>四、类和?/strong><strong></strong></div> <div><strong></strong></div> <div><strong>实现l承Q?/strong>extends关键?/div> <div></div> <div><strong>为类提供构造器</strong><strong></strong></div> <div>构造器用于初始化类的新对象Q构造器不是ҎQ没有返回类型;构造器的声明中可以使用以下讉K说明W:</div> <div>–      private</div> <div>–      protected</div> <div>–      public</div> <div>–      无说明符</div> <div></div> <div><strong>信息传递给Ҏ或构造器</strong><strong></strong></div> <div>参数cdQ?/div> <div>参数名称Q?/div> <div>按g递:参数是原始类型,Ҏ不能改变其|参数是引用类型,Ҏ不能改变其引用,但可以改变引用对象的倹{?/div> <div></div> <div><strong>从方法返回?/strong><strong></strong></div> <div>在方法声明中声明Ҏ的返回类型;eturn语句q回值的数据cd必须匚wҎ声明的返回类型;Ҏ可以q回原始cdQ也可以q回引用cd?strong></strong></div> <div></div> <div><strong>使用</strong><strong>this</strong><strong>关键?/strong><strong></strong></div> <div>在实例方法或构造器中,this引用当前对象Q也是被调用的Ҏ或构造器所属的对象Q在构造器中,q可以用this关键字调用相同类中的另一个构造器?/div> <div></div> <div><strong>控制对类成员的访?/strong><strong></strong></div> <div>讉K说明W决定其他类是否可以使用某个成员或调用某个方法。Java~程语言支持四种用于成员变量和方法的讉KU别Qprivate、protected、public?如果没有指定)package?strong></strong></div> <div><strong>讉KU别</strong><strong></strong></div> <div>PrivateQ类</div> <div>无说明符Q类、包</div> <div>ProtectedQ类、包、子c?/div> <div>PublicQ类、包、子cR所有类</div> <div></div> <div><strong>实例和类成员的初始化</strong><strong></strong></div> <div>可以在声明的同时q行初始化,但是有一些限Ӟ</div> <div>–      必须以一个赋D句表辑ֈ始化方式</div> <div>–      初始化表辑ּ不能调用M被声明ؓ抛出非运行时异常的方?/div> <div>–      如果初始化表辑ּ调用一个抛行时异常的方法,那么它不能进行错误恢?/div> <div>使用静态初始化块初始化cL员;</div> <div>实例成员的初始化?/div> <div><strong></strong></div> <div><strong>覆盖和隐藏方?/strong><strong></strong></div> <div>覆盖QoverrideQ(实例ҎQ:</div> <div>–      子类中的 个实例方法与类中的实例Ҏh相同的标记和q回cd</div> <div>–      Ҏ的标讎ͼ名称Q参数数量、参数类?/div> <div>–      覆盖Ҏ可以h不同的throws子句</div> <div>–      覆盖Ҏ的访问说明符允许讉K限制只能比被覆盖Ҏ的多</div> <div>–      子类不能覆盖类中声明ؓfinal的方?/div> <div>–      子类必须覆盖类中声明ؓabstract的方法,否则子类本n必须是抽象的</div> <div>覆盖和重载(overloadQ;</div> <div>覆盖和隐藏(cL法)?/div> <div></div> <div><strong>隐藏成员变量</strong><strong></strong></div> <div>在类中,如果一个成员变量与类中的成员变量同名Q即使它们的cd不同Q,那么它隐藏超cL员变量;</div> <div>在子cMQ不能通过单名U引用超cM的成员变量,而是必须通过super讉K它;</div> <div>代码可读性差Q不隐藏成员变量?/div> <div></div> <div><strong>使用</strong><strong>super</strong></div> <div>使用super调用被覆盖的ҎQ用super调用被隐藏的成员变量Q用super在构造器中调用超cȝ构造器?/div> <div></div> <div><strong>使用</strong><strong>Object</strong><strong>的后?/strong><strong></strong></div> <div>每个c都是Objectcȝ直接后代或间接后代;</div> <div>Objectcd义了所有类都必L的基本状态和行ؓQ?/div> <div>–      clone</div> <div>–      equals和hashCode</div> <div>–      finalize</div> <div>–      toString</div> <div>–      getClass</div> <div>–          notify、notifyAll和wait</div> <div></div> <div><strong>~写</strong><strong>final</strong><strong>cdҎ</strong><strong></strong></div> <div>类声明为finalQ即cM能被子类化:</div> <div>–      通过防止pȝ被改版来提高pȝ的安全?/div> <div>–      Z设计上的原因Q某些类不需要子c?/div> <div>finalҎQ?/div> <div>–          在方法声明中使用final关键字表C个方法不能被子类覆盖</div> <div></div> <div><strong>~写抽象cdҎ</strong><strong></strong></div> <div>抽象c:</div> <div>–      表示一个抽象的概念Q不应该被实例化</div> <div>–      abstract关键?/div> <div>抽象ҎQ?/div> <div>–      没有实现的方法,允许子类提供q些Ҏ的实现细?/div> <div>–          如果抽象cd包含抽象ҎQ那么它应该被定义成接口</div> <div></div> <div><strong>创徏cȝ结</strong><strong>    </strong></div> <div>cȝ定义有两个部分:</div> <div>–     cd?/div> <div>–     cMQ成员变量、方法、构造器</div> <div>讉K说明W——控制对成员变量和方法的讉K方式Q?/div> <div>cd量、类ҎQstaticҎ关键?/div> <div>实例成员、实例方?/div> <div></div> <div></div> <div><strong>五、接口和?/strong><strong></strong></div> <div><strong></strong></div> <div><strong>实现接口Q?/strong>implements关键?/div> <div></div> <div>cd以实现多个接?implements关键字后面跟以逗号分隔的接口列表;</div> <div>如果有extends关键?implements子句应该在extends子句的后面;</div> <div>c要么必需实现接口及其接口中的所有方?要么cd被声明为抽象的Q?/div> <div>cM的方法标?名称和参数列?必须匚w接口中的Ҏ标记?/div> <div></div> <div><strong>接口作为类型?/strong><strong></strong></div> <div>在定义了一个新接口?是在定义一个新的引用数据类型;</div> <div>定义可一用接?实例化是必须用类?/div> <div></div> <div><strong>接口不能改变</strong><strong></strong></div> <div>从语法的角度?接口可以被改变;</div> <div>从设计的角度?一个已l在pȝ中被q泛使用的接?不能L被改变;</div> <div>如果改变了接?实现原接口的c都无法工作;</div> <div>应该可能的考虑接口所提供的方法;</div> <div>如果要改变接?用承的方式定义新的接口?/div> <div></div> <div><strong>接口结</strong><strong></strong></div> <div>接口定义了一U功能描q?定义了对象之间进行通讯的协议;</div> <div>接口定义由接口声明和接口体组成;</div> <div>接口包含一l方法的声明,但没有方法的实现Q?/div> <div>实现接口的类必须实现接口中声明的所有方法;</div> <div>接口名称可以作ؓ数据cd使用?/div> <div></div> <div><strong>创徏和用包</strong><strong></strong></div> <div>创徏包:</div> <div>–     package语句作ؓcL接口源代码文件中的第一条语?/div> <div>–     cL接口的源代码和类文g的\径名与包的名U相对应</div> <div>使用另一个包中的接口或类Q?/div> <div>–     cL接口的限定名</div> <div>–     导入cL接口</div> <div>–     导入cL接口所在的整个?/div> <div></div> <div><strong>六、用异常处理错?/strong><strong></strong></div> <div><strong></strong></div> <div><strong>什么是异常</strong>Q异?exception)是在E序执行期间中断指o的正常流E的事g?/div> <div></div> <div><strong>try</strong><strong>?/strong><strong></strong></div> <div>try {</div> <div>       statements</div> <div>}</div> <div>statements是包含一个或多个可能抛出异常的语句?/div> <div></div> <div><strong>catch</strong><strong>?/strong><strong></strong></div> <div>每个catch块是一个异常处理器Q它处理由其参数指定的异常类?/div> <div>try{</div> <div>       ......</div> <div>} catch(ExceptionType name) {</div> <div>       ……</div> <div>} catch (ExceptionType name) {</div> <div>       ……</div> <div>}</div> <div></div> <div><strong>finally</strong><strong>?/strong><strong></strong></div> <div>finally块是可选的Q它提供一U机Ӟ其目的是无论try块中是否发生异常都确保进行清理工作;</div> <div>无论是否发生异常Q都会执行finally块中的代码?/div> <div></div> <div><strong>throw</strong><strong>语句</strong><strong></strong></div> <div>throw语句需要一个参敎ͼ一个可抛出的(ThrowableQ对象;可抛出对象是Throwablecȝ子类?/div> <div></div> <div><strong>Throwable</strong><strong>cd其子c?/strong><strong></strong></div> <div>ThrowablecL两个直接子类Q?/div> <div>–     Error</div> <div>–     Exception</div> <div>ErrorQ?/div> <div>–     JAVA虚拟机的动态链接故障或其它“?#8221;故障Q一般的E序不应该捕获ErrorQ也不能抛出Error</div> <div>ExceptionQ?/div> <div>大多数程序抛出ƈ捕获从ExceptioncL生的对象。Exception表示发生了一个问题,但ƈ不是严重的系l问题。你写的多数E序抛出ƈ捕获Exception(而不是Error)?/div> <div>–     Exception表示发生了一个问题,但ƈ不是严重的系l问?/div> <div>–     Exception的不同子c表C可能发生的各种异常</div> <div></div> <div><strong>异常的优点:</strong>错误代码与“常规”代码分离Q将错误沿调用堆栈向上传递;寚w误类型进行分l和区分?/div> <div></div> <div><strong>异常的小l?/strong><strong></strong></div> <div>E序可以使用异常表明发生了错误;</div> <div>E序可以使用throw语句抛出异常Q?/div> <div>异常是一个对象(Throwable的子c)Q?/div> <div>E序可以使用try、catch语句finally来捕获异常:</div> <div>–     try语句标识出可能发生的异常</div> <div>–     catch语句标识出异常处理器</div> <div>–          finally代码块不论抛出异怸否都会被执行Q适用于清理工?/div> <div></div> <div></div> <div><strong>七、线E:同时执行多个d</strong><strong></strong></div> <div><strong></strong></div> <div><strong>只要用到U程必ȝ承或接口Q?/strong><strong>Thread</strong><strong>?/strong><strong></strong></div> <div><strong>只要用到U程必要?/strong><strong>run</strong><strong>Ҏ?/strong><strong></strong></div> <div><strong></strong></div> <div><strong>什么是U程Q?/strong><strong></strong></div> <div>–     U程是程序内的一个单一的顺序控制流E?/div> <div>–     U程本n不是E序Q不能单独运行,它在一个程序内q行</div> <div>–     多个U程可以同时q行Q在一个程序内执行不同的Q?/div> <div></div> <div><strong>定制U程?/strong><strong>run</strong><strong>Ҏ</strong><strong></strong></div> <div>runҎ执行U程的工作;</div> <div>runҎ实现了线E的q行行ؓQ?/div> <div>runҎ可以做Q何可以用语句实现的事?/div> <div></div> <div><strong>为线E提?/strong><strong>run</strong><strong>ҎQ?/strong><strong></strong></div> <div>–     l承Threadc,q覆盖runҎ</div> <div>–     实现Runnable接口</div> <div></div> <div><strong>?/strong><strong>Thread</strong><strong>c进行子cd和覆?/strong><strong>run</strong></div> <div>public class SimpleThread extends Thread {</div> <div>       public SimpleThread(String str) {</div> <div>           super(str);</div> <div>       }</div> <div>       public void run() {</div> <div>           for (int i = 0; i < 10; i++) {</div> <div>               System.out.println(i + " " + getName());</div> <div>               try {</div> <div>                   sleep((long)(Math.random() * 1000));</div> <div>               } catch (InterruptedException e) {}</div> <div>           }</div> <div>           System.out.println("DONE! " + getName());</div> <div>       }</div> <div>}</div> <div></div> <div><strong>实现</strong><strong>Runnable</strong><strong>接口Q?/strong>如果一个类已经l承了另一个类Q那么要惛_现线E就必须实现Runnable接口?/div> <div></div> <div>在线E中l果是随Z生的Q如果想锁定对象p使用Synchronized关键字意思ؓ锁定Ҏ所有在的对象。在对象被解锁前Q其他线E不能调用相同对象上的被同步的方法。意思ؓ执行一个对象后Ȁzd一个对象,自n暂时睡眠Q等待另一个对象执行完毕,在执行下一步,反复如此?/div> <div><font face="Verdana"></font></div> <div><font face="Verdana"><strong>八、IOQ读和写</strong></font></div> <div> <p><font face="Verdana"><strong>如何使用道:</strong>道用于一个线E的输出q接到另一个线E的输入</font></p> <p><font face="Verdana"><strong>如何装:</strong>经常被以下的这UŞ式封装v来,以便l合许多的各种功能</font></p> <p><font face="Verdana"><strong>对象的串行化Q?/strong>Java.io包中的两个流——ObjectInputStream和ObjectOutputStream是字节流Q他们的工作与其他输入和输出类伹{但他们的特D之处在于它们可以读写对象?/font></p> <p><font face="Verdana"><strong>对对象进行串行化Q?/strong>如果一个不能串行化的对象传递给writeObjectҎQ那么它抛出一个NotSerializable Exception。对象只能在它的cdCSerializable接口的情况下被串行化?/font></p> <p><font face="Verdana"><strong>为类提供对象串行化:</strong>只有在对象的cdCSerializable接口情况下,对象才是可串行化的。所有,如果惌对你的类的实例进串行化,q个cdd现Serializable接口。Serializable接口是一个空接口Q也是_他不包含MҎ声明Q它的作用只是表明这个类的对象可以被串行化?/font></p> <p><font face="Verdana"><strong>I/O复制程?Copy.java)Q如下:</strong></font></p> <p><font face="Verdana">import java.io.File;<br /> import java.io.FileReader;<br /> import java.io.FileWriter;<br /> import java.io.IOException;<br /> //以上是此E序用到的IOcȝ包,也可以用“import java.io.*”</font></p> <p><font face="Verdana">public class Copy {<br />        public static void main(String[] args) throws IOException {<br /> File inputFile = new File("D:\\temp\\HelloWorld.java"); //目标文g路径QJAVA中\径地址只能?#8220;\\”?#8220;/”不能使用“\”<br /> File outputFile = new File("D:\\temp\\OutAgain.java"); //复制后新文g保存路径</font></p> <p><font face="Verdana">           FileReader in = new FileReader(inputFile);<br />            FileWriter out = new FileWriter(outputFile);<br />            int c;</font></p> <p><font face="Verdana">           while ((c = in.read()) != -1) //一直@环到0表示已经复制完毕Q所以这里用不{于?<br />               out.write(c);</font></p> <p><font face="Verdana">           in.close(); //关闭L件对?br />            out.close(); //关闭写文件对?br />        }<br /> </font></p> </div><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/168109.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-12-16 21:04 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/12/16/168109.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java 5|6 q发包介l?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/10/24/155474.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Wed, 24 Oct 2007 02:14:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/10/24/155474.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/155474.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/10/24/155474.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/155474.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/155474.html</trackback:ping><description><![CDATA[     摘要: java.util.concurrent 包含许多U程安全、测试良好、高性能的ƈ发构建块。不客气地说Q创?java.util.concurrent 的目的就是要实现 Collection 框架Ҏ据结构所执行的ƈ发操作。通过提供一l可靠的、高性能q发构徏块,开发h员可以提高ƈ发类的线E安全、可伸羃性、性能、可L和可靠性?如果一些类名看h怼Q可能是因ؓ java.util.concurr...  <a href='http://www.aygfsteel.com/mlh123caoer/archive/2007/10/24/155474.html'>阅读全文</a><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/155474.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-10-24 10:14 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/10/24/155474.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>1、堆排序的实?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/28/149091.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Fri, 28 Sep 2007 06:24:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/28/149091.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/149091.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/28/149091.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/149091.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/149091.html</trackback:ping><description><![CDATA[<div id="wmqeeuq" class="codeShade"><code><font color="#ffffff"></font><img alt="Heap sort" src="http://www.java2s.com/Code/JavaImages/Heap.PNG" border="0" /><br /> <font color="#ffffff">       </font></code></div> <font color="#7f0055"><strong>import </strong></font><font color="#000000">java.io.IOException;</font><br /> <font color="#ffffff"></font><br /> <font color="#7f0055"><strong>class </strong></font><font color="#000000">MyNode </font><font color="#000000">{</font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>int </strong></font><font color="#000000">iData; </font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#000000">MyNode</font><font color="#000000">(</font><font color="#7f0055"><strong>int </strong></font><font color="#000000">key</font><font color="#000000">) {</font><br /> <font color="#ffffff">    </font><font color="#000000">iData = key;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>int </strong></font><font color="#000000">getKey</font><font color="#000000">() {</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">iData;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#7f0055"><strong>public class </strong></font><font color="#000000">Heap </font><font color="#000000">{</font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#000000">MyNode</font><font color="#000000">[] </font><font color="#000000">heapArray;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>int </strong></font><font color="#000000">maxSize;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>private </strong></font><font color="#7f0055"><strong>int </strong></font><font color="#000000">currentSize; </font><font color="#3f7f5f">// number of items in array</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#000000">Heap</font><font color="#000000">(</font><font color="#7f0055"><strong>int </strong></font><font color="#000000">mx</font><font color="#000000">) {</font><br /> <font color="#ffffff">    </font><font color="#000000">maxSize = mx;</font><br /> <font color="#ffffff">    </font><font color="#000000">currentSize = </font><font color="#990000">0</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">heapArray = </font><font color="#7f0055"><strong>new </strong></font><font color="#000000">MyNode</font><font color="#000000">[</font><font color="#000000">maxSize</font><font color="#000000">]</font><font color="#000000">;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#000000">MyNode remove</font><font color="#000000">() </font><br /> <font color="#ffffff">  </font><font color="#000000">{ </font><br /> <font color="#ffffff">    </font><font color="#000000">MyNode root = heapArray</font><font color="#000000">[</font><font color="#990000">0</font><font color="#000000">]</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">heapArray</font><font color="#000000">[</font><font color="#990000">0</font><font color="#000000">] </font><font color="#000000">= heapArray</font><font color="#000000">[</font><font color="#000000">--currentSize</font><font color="#000000">]</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">trickleDown</font><font color="#000000">(</font><font color="#990000">0</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">root;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">trickleDown</font><font color="#000000">(</font><font color="#7f0055"><strong>int </strong></font><font color="#000000">index</font><font color="#000000">) {</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">largerChild;</font><br /> <font color="#ffffff">    </font><font color="#000000">MyNode top = heapArray</font><font color="#000000">[</font><font color="#000000">index</font><font color="#000000">]</font><font color="#000000">; </font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>while </strong></font><font color="#000000">(</font><font color="#000000">index < currentSize / </font><font color="#990000">2</font><font color="#000000">)</font><br /> <font color="#ffffff">    </font><font color="#000000">{</font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">leftChild = </font><font color="#990000">2 </font><font color="#000000">* index + </font><font color="#990000">1</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">rightChild = leftChild + </font><font color="#990000">1</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#3f7f5f">// 扑ֈ最大的子节?/font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">rightChild < currentSize</font><br /> <font color="#ffffff">          </font><font color="#000000">&& </font><br /> <font color="#ffffff">          </font><font color="#000000">heapArray</font><font color="#000000">[</font><font color="#000000">leftChild</font><font color="#000000">]</font><font color="#000000">.getKey</font><font color="#000000">() </font><font color="#000000">< heapArray</font><font color="#000000">[</font><font color="#000000">rightChild</font><font color="#000000">]</font><br /> <font color="#ffffff">              </font><font color="#000000">.getKey</font><font color="#000000">())</font><br /> <font color="#ffffff">        </font><font color="#000000">largerChild = rightChild;</font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>else</strong></font><br /> <font color="#ffffff">        </font><font color="#000000">largerChild = leftChild;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">top.getKey</font><font color="#000000">() </font><font color="#000000">>= heapArray</font><font color="#000000">[</font><font color="#000000">largerChild</font><font color="#000000">]</font><font color="#000000">.getKey</font><font color="#000000">())</font><br /> <font color="#ffffff">        </font><font color="#7f0055"><strong>break</strong></font><font color="#000000">;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">      </font><font color="#000000">heapArray</font><font color="#000000">[</font><font color="#000000">index</font><font color="#000000">] </font><font color="#000000">= heapArray</font><font color="#000000">[</font><font color="#000000">largerChild</font><font color="#000000">]</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#000000">index = largerChild; </font><br /> <font color="#ffffff">    </font><font color="#000000">}</font><br /> <font color="#ffffff">    </font><font color="#000000">heapArray</font><font color="#000000">[</font><font color="#000000">index</font><font color="#000000">] </font><font color="#000000">= top;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">displayHeap</font><font color="#000000">() {</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">nBlanks = </font><font color="#990000">32</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">itemsPerRow = </font><font color="#990000">1</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">column = </font><font color="#990000">0</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">currentIndex = </font><font color="#990000">0</font><font color="#000000">; </font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>while </strong></font><font color="#000000">(</font><font color="#000000">currentSize > </font><font color="#990000">0</font><font color="#000000">)</font><br /> <font color="#ffffff">    </font><font color="#000000">{</font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">column == </font><font color="#990000">0</font><font color="#000000">) </font><br /> <font color="#ffffff">        </font><font color="#7f0055"><strong>for </strong></font><font color="#000000">(</font><font color="#7f0055"><strong>int </strong></font><font color="#000000">k = </font><font color="#990000">0</font><font color="#000000">; k < nBlanks; k++</font><font color="#000000">)</font><br /> <font color="#ffffff">          </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#990000">' '</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#000000">heapArray</font><font color="#000000">[</font><font color="#000000">currentIndex</font><font color="#000000">]</font><font color="#000000">.getKey</font><font color="#000000">())</font><font color="#000000">;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">++currentIndex == currentSize</font><font color="#000000">) </font><font color="#3f7f5f">//  判断是否输出l束</font><br /> <font color="#ffffff">        </font><font color="#7f0055"><strong>break</strong></font><font color="#000000">;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">++column == itemsPerRow</font><font color="#000000">) </font><font color="#3f7f5f">// 是否到达行尾?</font><br /> <font color="#ffffff">      </font><font color="#000000">{</font><br /> <font color="#ffffff">        </font><font color="#000000">nBlanks /= </font><font color="#990000">2</font><font color="#000000">; </font><br /> <font color="#ffffff">        </font><font color="#000000">itemsPerRow *= </font><font color="#990000">2</font><font color="#000000">; </font><br /> <font color="#ffffff">        </font><font color="#000000">column = </font><font color="#990000">0</font><font color="#000000">; </font><br /> <font color="#ffffff">        </font><font color="#000000">System.out.println</font><font color="#000000">()</font><font color="#000000">; </font><br /> <font color="#ffffff">      </font><font color="#000000">} </font><font color="#7f0055"><strong>else</strong></font><br /> <font color="#ffffff">        </font><font color="#7f0055"><strong>for </strong></font><font color="#000000">(</font><font color="#7f0055"><strong>int </strong></font><font color="#000000">k = </font><font color="#990000">0</font><font color="#000000">; k < nBlanks * </font><font color="#990000">2 </font><font color="#000000">- </font><font color="#990000">2</font><font color="#000000">; k++</font><font color="#000000">)</font><br /> <font color="#ffffff">          </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#990000">' '</font><font color="#000000">)</font><font color="#000000">; </font><font color="#3f7f5f">// 输入I白</font><br /> <font color="#ffffff">    </font><font color="#000000">} </font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">displayArray</font><font color="#000000">() {</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>for </strong></font><font color="#000000">(</font><font color="#7f0055"><strong>int </strong></font><font color="#000000">j = </font><font color="#990000">0</font><font color="#000000">; j < maxSize; j++</font><font color="#000000">)</font><br /> <font color="#ffffff">      </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#000000">heapArray</font><font color="#000000">[</font><font color="#000000">j</font><font color="#000000">]</font><font color="#000000">.getKey</font><font color="#000000">() </font><font color="#000000">+ </font><font color="#2a00ff">" "</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#2a00ff">""</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">insertAt</font><font color="#000000">(</font><font color="#7f0055"><strong>int </strong></font><font color="#000000">index, MyNode newNode</font><font color="#000000">) {</font><br /> <font color="#ffffff">    </font><font color="#000000">heapArray</font><font color="#000000">[</font><font color="#000000">index</font><font color="#000000">] </font><font color="#000000">= newNode;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">incrementSize</font><font color="#000000">() {</font><br /> <font color="#ffffff">    </font><font color="#000000">currentSize++;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public static </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">main</font><font color="#000000">(</font><font color="#000000">String</font><font color="#000000">[] </font><font color="#000000">args</font><font color="#000000">) </font><font color="#7f0055"><strong>throws </strong></font><font color="#000000">IOException </font><font color="#000000">{</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">size, i;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">    </font><font color="#000000">size = </font><font color="#990000">100</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">Heap theHeap = </font><font color="#7f0055"><strong>new </strong></font><font color="#000000">Heap</font><font color="#000000">(</font><font color="#000000">size</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>for </strong></font><font color="#000000">(</font><font color="#000000">i = </font><font color="#990000">0</font><font color="#000000">; i < size; i++</font><font color="#000000">) {</font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">random = </font><font color="#000000">(</font><font color="#7f0055"><strong>int</strong></font><font color="#000000">) (</font><font color="#000000">java.lang.Math.random</font><font color="#000000">() </font><font color="#000000">* </font><font color="#990000">100</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#000000">MyNode newNode = </font><font color="#7f0055"><strong>new </strong></font><font color="#000000">MyNode</font><font color="#000000">(</font><font color="#000000">random</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#000000">theHeap.insertAt</font><font color="#000000">(</font><font color="#000000">i, newNode</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#000000">theHeap.incrementSize</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">    </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#2a00ff">"Random: "</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">theHeap.displayArray</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>for </strong></font><font color="#000000">(</font><font color="#000000">i = size / </font><font color="#990000">2 </font><font color="#000000">- </font><font color="#990000">1</font><font color="#000000">; i >= </font><font color="#990000">0</font><font color="#000000">; i--</font><font color="#000000">)</font><br /> <font color="#ffffff">      </font><font color="#000000">theHeap.trickleDown</font><font color="#000000">(</font><font color="#000000">i</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">    </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#2a00ff">"Heap:   "</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">theHeap.displayArray</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">theHeap.displayHeap</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>for </strong></font><font color="#000000">(</font><font color="#000000">i = size - </font><font color="#990000">1</font><font color="#000000">; i >= </font><font color="#990000">0</font><font color="#000000">; i--</font><font color="#000000">) {</font><br /> <font color="#ffffff">      </font><font color="#000000">MyNode biggestNode = theHeap.remove</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#000000">theHeap.insertAt</font><font color="#000000">(</font><font color="#000000">i, biggestNode</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">}</font><br /> <font color="#ffffff">    </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#2a00ff">"Sorted: "</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">theHeap.displayArray</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#000000">}</font><br /> <font color="#ffffff"></font><br /><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/149091.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-09-28 14:24 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/09/28/149091.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>DBq接池管理编ED?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/28/149082.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Fri, 28 Sep 2007 06:10:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/28/149082.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/149082.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/28/149082.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/149082.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/149082.html</trackback:ping><description><![CDATA[<div id="wmqeeuq" class="codeShade"><code><font color="#ffffff"></font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">java.sql.Connection;</font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">java.sql.ResultSet;</font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">java.sql.SQLException;</font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">java.sql.Statement;</font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">java.util.Properties;</font><br /> <font color="#ffffff"></font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">javax.naming.Context;</font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">javax.naming.InitialContext;</font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">javax.naming.NamingException;</font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">javax.sql.ConnectionPoolDataSource;</font><br /> <font color="#7f0055"><strong>import </strong></font><font color="#000000">javax.sql.PooledConnection;</font><br /> <font color="#ffffff"></font><br /> <font color="#7f0055"><strong>public class </strong></font><font color="#000000">MainClass </font><font color="#000000">{</font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>public static </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">main</font><font color="#000000">(</font><font color="#000000">String</font><font color="#000000">[] </font><font color="#000000">args</font><font color="#000000">) {</font><br /> <font color="#ffffff">    </font><font color="#000000">Connection connection = </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">Statement statement = </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">ResultSet resultSet = </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>try </strong></font><font color="#000000">{</font><br /> <font color="#ffffff">      </font><font color="#000000">connection = getConnection</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#3f7f5f">// 操作q接</font><br /> <font color="#ffffff">      </font><font color="#000000">statement = connection.createStatement</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#000000">String selectEmployeesSQL = </font><font color="#2a00ff">"SELECT * FROM employees"</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#000000">resultSet = statement.executeQuery</font><font color="#000000">(</font><font color="#000000">selectEmployeesSQL</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>while </strong></font><font color="#000000">(</font><font color="#000000">resultSet.next</font><font color="#000000">()) {</font><br /> <font color="#ffffff">        </font><font color="#000000">printEmployee</font><font color="#000000">(</font><font color="#000000">resultSet</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">      </font><font color="#000000">}</font><br /> <font color="#ffffff">    </font><font color="#000000">} </font><font color="#7f0055"><strong>catch </strong></font><font color="#000000">(</font><font color="#000000">Exception e</font><font color="#000000">) {</font><br /> <font color="#ffffff">      </font><font color="#000000">e.printStackTrace</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">} </font><font color="#7f0055"><strong>finally </strong></font><font color="#000000">{</font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">resultSet != </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">) {</font><br /> <font color="#ffffff">        </font><font color="#7f0055"><strong>try </strong></font><font color="#000000">{</font><br /> <font color="#ffffff">          </font><font color="#000000">resultSet.close</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">        </font><font color="#000000">} </font><font color="#7f0055"><strong>catch </strong></font><font color="#000000">(</font><font color="#000000">SQLException e</font><font color="#000000">) {</font><br /> <font color="#ffffff">        </font><font color="#000000">} </font><font color="#3f7f5f">// nothing we can do</font><br /> <font color="#ffffff">      </font><font color="#000000">}</font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">statement != </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">) {</font><br /> <font color="#ffffff">        </font><font color="#7f0055"><strong>try </strong></font><font color="#000000">{</font><br /> <font color="#ffffff">          </font><font color="#000000">statement.close</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">        </font><font color="#000000">} </font><font color="#7f0055"><strong>catch </strong></font><font color="#000000">(</font><font color="#000000">SQLException e</font><font color="#000000">) {</font><br /> <font color="#ffffff">        </font><font color="#000000">} </font><font color="#3f7f5f">// nothing we can do</font><br /> <font color="#ffffff">      </font><font color="#000000">}</font><br /> <font color="#ffffff">      </font><font color="#7f0055"><strong>if </strong></font><font color="#000000">(</font><font color="#000000">connection != </font><font color="#7f0055"><strong>null</strong></font><font color="#000000">) {</font><br /> <font color="#ffffff">        </font><font color="#7f0055"><strong>try </strong></font><font color="#000000">{</font><br /> <font color="#ffffff">          </font><font color="#000000">connection.close</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">        </font><font color="#000000">} </font><font color="#7f0055"><strong>catch </strong></font><font color="#000000">(</font><font color="#000000">SQLException e</font><font color="#000000">) {</font><br /> <font color="#ffffff">        </font><font color="#000000">} </font><font color="#3f7f5f">// nothing we can do</font><br /> <font color="#ffffff">      </font><font color="#000000">}</font><br /> <font color="#ffffff">    </font><font color="#000000">}</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>private static </strong></font><font color="#000000">Connection getConnection</font><font color="#000000">() </font><font color="#7f0055"><strong>throws </strong></font><font color="#000000">NamingException, SQLException </font><font color="#000000">{</font><br /> <font color="#ffffff">    </font><font color="#000000">InitialContext initCtx = createContext</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">String jndiName = </font><font color="#2a00ff">"HrDS"</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">ConnectionPoolDataSource dataSource = </font><font color="#000000">(</font><font color="#000000">ConnectionPoolDataSource</font><font color="#000000">) </font><font color="#000000">initCtx.lookup</font><font color="#000000">(</font><font color="#000000">jndiName</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">PooledConnection pooledConnection = dataSource.getPooledConnection</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">pooledConnection.getConnection</font><font color="#000000">()</font><font color="#000000">; </font><font color="#3f7f5f">// 从池中得到连?/font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>private static </strong></font><font color="#000000">InitialContext createContext</font><font color="#000000">() </font><font color="#7f0055"><strong>throws </strong></font><font color="#000000">NamingException </font><font color="#000000">{</font><br /> <font color="#ffffff">    </font><font color="#000000">Properties env = </font><font color="#7f0055"><strong>new </strong></font><font color="#000000">Properties</font><font color="#000000">()</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">env.put</font><font color="#000000">(</font><font color="#000000">Context.INITIAL_CONTEXT_FACTORY, </font><font color="#2a00ff">"com.sun.jndi.rmi.registry.RegistryContextFactory"</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">env.put</font><font color="#000000">(</font><font color="#000000">Context.PROVIDER_URL, </font><font color="#2a00ff">"rmi://localhost:1099"</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">InitialContext context = </font><font color="#7f0055"><strong>new </strong></font><font color="#000000">InitialContext</font><font color="#000000">(</font><font color="#000000">env</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">context;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">  </font><font color="#7f0055"><strong>private static </strong></font><font color="#7f0055"><strong>void </strong></font><font color="#000000">printEmployee</font><font color="#000000">(</font><font color="#000000">ResultSet resultSet</font><font color="#000000">) </font><font color="#7f0055"><strong>throws </strong></font><font color="#000000">SQLException </font><font color="#000000">{</font><br /> <font color="#ffffff">    </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#000000">resultSet.getInt</font><font color="#000000">(</font><font color="#2a00ff">"employee_id"</font><font color="#000000">)</font><font color="#000000">+</font><font color="#2a00ff">", "</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#000000">resultSet.getString</font><font color="#000000">(</font><font color="#2a00ff">"last_name"</font><font color="#000000">)</font><font color="#000000">+</font><font color="#2a00ff">", "</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">System.out.print</font><font color="#000000">(</font><font color="#000000">resultSet.getString</font><font color="#000000">(</font><font color="#2a00ff">"first_name"</font><font color="#000000">)</font><font color="#000000">+</font><font color="#2a00ff">", "</font><font color="#000000">)</font><font color="#000000">;</font><br /> <font color="#ffffff">    </font><font color="#000000">System.out.println</font><font color="#000000">(</font><font color="#000000">resultSet.getString</font><font color="#000000">(</font><font color="#2a00ff">"email"</font><font color="#000000">))</font><font color="#000000">;</font><br /> <font color="#ffffff">  </font><font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#000000">}</font><br /> <font color="#ffffff"></font><br /> <font color="#ffffff">           </font><br /> <font color="#ffffff">       </font></code></div><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/149082.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-09-28 14:10 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/09/28/149082.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java中如何重设数l的大小Q?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/19/146367.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Wed, 19 Sep 2007 02:34:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/19/146367.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/146367.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/19/146367.html#Feedback</comments><slash:comments>4</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/146367.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/146367.html</trackback:ping><description><![CDATA[在Java中,数组不能动态重讑֤。一个可替代Ҏ是?a goog_ds_charindex="31">java.util.ArrayList</a> (或?a goog_ds_charindex="56">java.util.Vector</a>)代替使用原始数组QarrayQ。另一U解x案是用一个不同大的数组重设数组Q将旧数l内Ҏ贝到新的数组。下面做了个演示E序实现W二U方案,~写了个通用函数r<em goog_ds_charindex="154">sizeArray</em> (参数)来实现此功能Q?<br /> <br /> <pre goog_ds_charindex="181">/**<br goog_ds_charindex="185" /> * 使用一个新大小重设数组Qƈ拯旧数l的内容到新数组<br goog_ds_charindex="249" /> * @param oldArray 旧数l被重设<br goog_ds_charindex="339" /> * @param newSize 新数l大?br goog_ds_charindex="378" /> * @return q回带同样内容的新数l?br goog_ds_charindex="433" /> */<br goog_ds_charindex="436" /> private static Object resizeArray (Object oldArray, int newSize){<br goog_ds_charindex="503" /> int oldSize = java.lang.reflect.Array.getLength(oldArray);<br goog_ds_charindex="565" /> Class elementType = oldArray.getClass().getComponentType();<br goog_ds_charindex="628" /> Object newArray = java.lang.reflect.Array.newInstance(<br goog_ds_charindex="686" /> elementType,newSize);<br goog_ds_charindex="717" /> int preserveLength = Math.min(oldSize,newSize);<br goog_ds_charindex="768" /> if (preserveLength > 0)<br goog_ds_charindex="795" /> System.arraycopy (oldArray,0,newArray,0,preserveLength);<br goog_ds_charindex="858" /> return newArray; <br /> }</pre> <pre goog_ds_charindex="884">// resizeArray()试用例<br /> public static void main (String[] args) {<br goog_ds_charindex="961" /> int[] a = {1,2,3};<br goog_ds_charindex="983" /> a = (int[])resizeArray(a,5);<br goog_ds_charindex="1015" /> a[3] = 4;<br goog_ds_charindex="1028" /> a[4] = 5;<br goog_ds_charindex="1041" /> for (int i=0; i<a.length; i++)<br goog_ds_charindex="1075" /> System.out.println (a[i]); }</pre> <br goog_ds_charindex="1111" /> <p goog_ds_charindex="1113"><strong goog_ds_charindex="1114">那二l数l如何重讑֤呢Q?很简单,是处理数组的数l呀Q?/strong></p> <p goog_ds_charindex="1155">要想重设二维数组Q?em>resizeArrayҎ</em>必须处理外部数组和所有嵌套数l,如下例: </p> <pre goog_ds_charindex="1346"> int a[][] = new int[2][3];<br goog_ds_charindex="1375" /> //...<br goog_ds_charindex="1383" /> a = (int[][])resizeArray(a,20);<br goog_ds_charindex="1417" /> // 新数l是[20][3]<br goog_ds_charindex="1445" /> for (int i=0; i<a.length; i++) {<br goog_ds_charindex="1480" /> if (a[i] == null)<br goog_ds_charindex="1503" /> a[i] = new int[30];<br goog_ds_charindex="1531" /> else a[i] = (int[])resizeArray(a[i],30); <br /> }<br goog_ds_charindex="1580" /> // 新数l是[20][30]</pre><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/146367.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-09-19 10:34 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/09/19/146367.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>常去的几个外国技术门?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/15/145394.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Sat, 15 Sep 2007 09:56:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/15/145394.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/145394.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/09/15/145394.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/145394.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/145394.html</trackback:ping><description><![CDATA[http://www.infoq.com<br /> http://www.theserverside.com<br /> http://www.javablogs.com<br /> http://www.java.net<br /> http://www.javasoft.com<br /> http://blogs.sun.com <br />    之(重要Q?br />    http://blogs.sun.com/roumen/<br />    http://blogs.sun.com/geertjan/<br />    http://blogs.sun.com/theaquarium/<br /> http://www.ibm.com/developerworks<br /> http://www.onjava.com/<br /> http://www.developer.com/java/<br /> http://www.javaworld.com/<br /> http://www.java.com/<br /> http://www.netbeans.org/kb/index.html<br /> http://www.eclipse.org<br /> http://www.oracle.com/technology/tech/java/index.html<br /> http://www.javaranch.com<br /> http://www.javablackbelt.com<br /> http://www.jugcologne.org<br /> http://www.dzone.com<br /><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/145394.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-09-15 17:56 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/09/15/145394.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Java Annotation手册http://www.aygfsteel.com/mlh123caoer/archive/2007/09/06/143260.html草儿草儿Thu, 06 Sep 2007 11:11:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/09/06/143260.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/143260.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/09/06/143260.html#Feedback13http://www.aygfsteel.com/mlh123caoer/comments/commentRss/143260.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/143260.htmlAnnotation 提供了一条与E序元素兌M信息或者Q何元数据QmetadataQ的途径。从某些斚w看,annotation像修饰W一栯使用Qƈ应用于包、类型、构造方法、方法、成员变量、参数、本地变量的声明中。这些信息被存储在annotation的“name=value”结构对中?annotationcd是一U接口,能够通过java反射API的方式提供对其信息的讉K?
  阅读全文

草儿 2007-09-06 19:11 发表评论
]]>
什么是JMX?http://www.aygfsteel.com/mlh123caoer/archive/2007/09/03/142456.html草儿草儿Mon, 03 Sep 2007 14:26:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/09/03/142456.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/142456.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/09/03/142456.html#Feedback5http://www.aygfsteel.com/mlh123caoer/comments/commentRss/142456.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/142456.htmlJMX(Java Management Extensions)是一个ؓ应用E序植入理功能的框架。JMX是一套标准的代理和服务,实际上,用户可以在Q何Java应用E序中用这些代理和服务实现理?

JMX的前w是JMAPI?

JMX致力于解军_布式pȝ理的问题,因此Q能够适合于各U不同的环境是非帔R要的。ؓ了能够利用功能强大的Java计算环境解决q一的问题,Sun公司扩充?a class="wikipage" >Java基础cdQ开发了专用的管理类库?

JMX是一U应用编E接口,可扩充对象和Ҏ的集合体Q可以用于跨一pd不同的异构操作系l^台、系l体pȝ构和|络传输协议Q灵zȝ开发无~集成的pȝ、网l和服务理应用它提供了用户界面指导、Javacd开发集成系l、网l及|络理应用的规范?

理对象是JMX应用E序的核心。JMXl构包括Q支持Java的Web览器用h口,理q行模块ARM(Admin Runtime Module)和应用。这三个部g之间通过RMIQRemote Method InvocationQ进行通信。这里需要说明的是,RMI是得一个Java虚拟机(JVMQ上q行的程序可以调用远E服务器上另一?a class="wikipage" >JVMȝ对象?

用户接口用来发布理操作Q这些操作可以间接的通过览器或通过单独的应用程序来Ȁ发。管理运行模块用来给应用提供实例化的理对象。它包括Agent对象接口Q通知接口和被数据接口。应用指的是那些被管讑֤单元?

JMX是一个完整的|络理应用E序开发环境,它同时提供了Q厂商需要收集的完整的特性清单,可生成资源清单表|囑Ş化的用户接口Q访?a class="editpage" title="Create 'SNMP'" >SNMP的网lAPIQ主机间q程q程调用Q数据库讉KҎ?

JMXq一d的管理基l构Qh值在于对被管理资源的服务实现了抽象,提供了低层的基本c集合,开发h员在保证大多数的公共理cȝ完整性和一致性的前提下,q行扩展以满特定网l管理应用的需要?

JMX注重于构造管理工L软g框架Qƈ量采用已成熟的技术?

JMX体系被分成三个层?

  • 表现?
  • 代理?
  • 分布式服务层

表现?

表现层定义的是JMX可管理资源所在的层?

q些已管理的资源可以~写或封装ؓMBean?

MBean分ؓ四种cdQ?标准、动态、开放、模?

代理?

定义的是MBean向应用程序施加管理的层。包括MBean服务器和代理服务的定义。还臛_包括一个协议适配器或q接器?

代理的组成: 。一个MBean服务?。要理的MBean 。作为MBean实现的代理服?。至一个协议适配?

MBean

在JMX中,最的可管理单元是MBean?

MBean不是一个真正的接口和类Q而是必须准@的设计模式以保资源是一个兼容的MBean?

MBean的激zL?

invoke()Ҏ是管理应用程序用于激zMBean的方法的手段?invoke()Ҏ有三个参敎ͼ分别是方法的名称、表C属性的对象数组和描q方法签名的一个字W串数组。它与?a class="editpage" title="Create 'JavaReflection'" >Java Reflection Api ȀzL法的方式cM?

Notification(通知)模型Q?

MBean的通知模型cM与Java事g的监听器模型?MBean或管理应用程序可以作为MBean事g的监听器注册?通知支持׃个基本的概念l成Q即q播器和监听器?

MBean服务?

MBean服务器用于注册可理的MBean?

所有对MBean的请求或查询都是通过MBean服务器实施的?

代理服务

代理服务是一些特D的函数Q代理把q些服务提供lMBeanQ这些代理服务独立于MMBean?

一个代理可以提供四U主要的服务Q?

  • 动态装载:允许代理通过下蝲q个Bean的类动态实例化MBeanQ这与装载applet的方式类伹{?

JMX使用m-letq个标记指定期望动态装载的MBean的位|?

  • 监控Q允总理通知有关的监听器监控一个MBean的属性值的变化

JMX允许使用三种基本cd的监控程?(1)CounterMonitorQ该E序可以观察cd斚w的变化,比如BytecM或Integercd (2)GaugeMonitorQ该E序可以观察cd斚w的变化,比如BytecM或IntegercdQ还可以在到达上下阀值时q行报告?(3)StringMonitorQ该E序可以观察java.lang.Stringcd的变化?

  • 计时器:允许预设的时间间隔发送通知Q可以作Z个调度程?
  • 关系Q允许创建和l护MBean之间的关p?

分布式服务层

包含协议适配器和q接器两U类型的lgQ通过它们q接到外部的应用Q如RMI理应用、基于浏览器的管理控制等

协议适配器和q接?

协议适配器是代理与管理客户通信的手D,每个通信的协议都可能不同?

它们都是理客户与MBean交互的方式?

JMX的好?

  • 可减对JAVA应用实施理的投?
  • 提供了一个可伸羃的管理框?
  • 集成现有的管理方案:如:WBEMQSNMPQTMN
  • 使用现有的标准JAVA技?
  • 能用未来的一些管理概念:如Jiniq接技术、通用x即用、服务定位协?Service Location Protocol)
  • 只定义了一些可以访问的接口

相关资源Q?/p>



草儿 2007-09-03 22:26 发表评论
]]>
?侯捷谈Java反射机制http://www.aygfsteel.com/mlh123caoer/archive/2007/08/29/140824.html草儿草儿Wed, 29 Aug 2007 03:24:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/29/140824.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/140824.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/29/140824.html#Feedback2http://www.aygfsteel.com/mlh123caoer/comments/commentRss/140824.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/140824.html阅读全文

草儿 2007-08-29 11:24 发表评论
]]>
国外开源网站聚?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/25/139337.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Sat, 25 Aug 2007 15:16:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/25/139337.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/139337.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/25/139337.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/139337.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/139337.html</trackback:ping><description><![CDATA[<p>sourceforge <a >http://www.sourceforge.net</a><br>java.net <a >http://www.java.net</a></p> <p><a >www.eclipse.org</a></p> <p><a >www.opensource.org</a><br></p> <p><span lang=EN-US style="FONT-FAMILY: SimSun; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: SimSun"><a >http://strutstestcase.sourceforge.net</a> <font color=#002c99>(StrutsTestCase</font></span><span style="FONT-FAMILY: SimSun; mso-bidi-font-size: 10.5pt; mso-font-kerning: 0pt; mso-bidi-font-family: SimSun">是基?span lang=EN-US>Junit</span>的一个方便测?span lang=EN-US>struts</span>框架的测试框?<br><br></span>Lomboz <a >http://www.objectlearn.com/index.jsp</a> (J2EE plugin for Eclipse)<br>htmlArea <a >http://sourceforge.net/projects/itools-htmlarea/</a> (所见即所得的在线HTML~辑?<br>XmlBuddy <a >http://www.xmlbuddy.com/</a> (XML Editor plugin for Eclipse)<br>JFreeChart <a >http://www.jfree.org/</a> (用于生成图表的项?<br>EclipseME <a >http://eclipseme.sourceforge.net/</a> (J2ME Developmnt Plugin for Eclipse)<br>mvnForum <a >http://sourceforge.net/projects/mvnforum/</a> (论坛)<br>jChatBox <a >http://www.javazoom.net/index.shtml</a> (用servlet实现的WEB聊天引擎)<br>POI <a >http://jakarta.apache.org/poi/index.html</a> (用于处理Excel,WORD{文档的目)<br>FileUpload <a >http://jakarta.apache.org/commons/fileupload/</a> (用于处理HTTP文g上传得项?<br>PDFBox <a >http://sourceforge.net/projects/pdfbox/</a> (处理PDF文档的项?<br>Lucene <a >http://jakarta.apache.org/lucene/index.html</a> (搜烦引擎)<br>Digester <a >http://jakarta.apache.org/commons/digester/</a> (处理XML信息的项?<br>DBCP <a >http://jakarta.apache.org/commons/dbcp/</a> (数据库连接池)<br>AXIS <a >http://ws.apache.org/axis/</a> (WebService 的实现框?<br>Jetspeed <a >http://portals.apache.org/jetspeed-1/</a> (Portal)<br>HSQLDB <a >http://sourceforge.net/projects/hsqldb/</a> (Im memory Database Engine)<br>CEWOLF <a >http://sourceforge.net/projects/cewolf/</a> (一套标{ֺ实现Web报表,使用的是jFreeChart引擎)<br>Struts Menu <a >http://sourceforge.net/projects/struts-menu/</a> (ZStruts的Web菜单目)<br>htmlparser <a >http://sourceforge.net/projects/htmlparser/</a> (用于解析HTML信息的项?<br>Mondrian <a >http://sourceforge.net/projects/mondrian/(Open</a> Source OLAP Database)<br>ProGuard <a >http://sourceforge.net/projects/proguard/(Java</a>的؜淆器)<br>InfoGlue <a >http://sourceforge.net/projects/infoglue/</a> (J2EE 内容理pȝ)<br>JPivot <a >http://sourceforge.net/projects/jpivot/</a> (ZWEB的OLAP 展现)<br><a >http://java-source.net/</a></p> <p>(5)几个常用JAVA开源项目的地址荟萃:<br>Lomboz <a >http://www.objectlearn.com/index.jsp</a> (J2EE plugin for Eclipse)<br>htmlArea <a >http://sourceforge.net/projects/itools-htmlarea/</a> (所见即所得的在线HTML~辑?<br>XmlBuddy <a >http://www.xmlbuddy.com/</a> (XML Editor plugin for Eclipse)<br>JFreeChart <a >http://www.jfree.org/</a> (用于生成图表的项?<br>EclipseME <a >http://eclipseme.sourceforge.net/</a> (J2ME Developmnt Plugin for Eclipse)<br>mvnForum <a >http://sourceforge.net/projects/mvnforum/</a> (论坛)<br>jChatBox <a >http://www.javazoom.net/index.shtml</a> (用servlet实现的WEB聊天引擎)<br>POI <a >http://jakarta.apache.org/poi/index.html</a> (用于处理Excel,WORD{文档的目)<br>FileUpload <a >http://jakarta.apache.org/commons/fileupload/</a> (用于处理HTTP文g上传得项?<br>PDFBox <a >http://sourceforge.net/projects/pdfbox/</a> (处理PDF文档的项?<br>Lucene <a >http://jakarta.apache.org/lucene/index.html</a> (搜烦引擎)<br>Digester <a >http://jakarta.apache.org/commons/digester/</a> (处理XML信息的项?<br>DBCP <a >http://jakarta.apache.org/commons/dbcp/</a> (数据库连接池)<br>AXIS <a >http://ws.apache.org/axis/</a> (WebService 的实现框?<br>Jetspeed <a >http://portals.apache.org/jetspeed-1/</a> (Portal)<br>HSQLDB <a >http://sourceforge.net/projects/hsqldb/</a> (Im memory Database Engine)<br>CEWOLF <a >http://sourceforge.net/projects/cewolf/</a>(一套标{ֺ实现Web报表,使用的是jFreeChart?<br>Struts Menu <a >http://sourceforge.net/projects/struts-menu/</a> (ZStruts的Web菜单目)<br>htmlparser <a >http://sourceforge.net/projects/htmlparser/</a> (用于解析HTML信息的项?<br>Mondrian <a >http://sourceforge.net/projects/mondrian/</a> (Open Source OLAPdatabase)<br>ProGuard <a >http://sourceforge.net/projects/proguard/</a> (Java的؜淆器)<br>InfoGlue <a >http://sourceforge.net/projects/infoglue/</a> (J2EE 内容理pȝ)<br>JPivot <a >http://sourceforge.net/projects/jpivot/</a> (ZWEB的OLAP 展现)<br>HttpClient <a >http://jakarta.apache.org/commons/httpclient/</a> 处理http客户端的接口</p><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/139337.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-08-25 23:16 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/08/25/139337.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JavaFX~程语言基础http://www.aygfsteel.com/mlh123caoer/archive/2007/08/17/137425.html草儿草儿Thu, 16 Aug 2007 16:39:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/17/137425.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/137425.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/17/137425.html#Feedback3http://www.aygfsteel.com/mlh123caoer/comments/commentRss/137425.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/137425.html阅读全文

草儿 2007-08-17 00:39 发表评论
]]>
深入学习JavaFX脚本语言-參?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/17/137424.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Thu, 16 Aug 2007 16:36:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/17/137424.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/137424.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/17/137424.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/137424.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/137424.html</trackback:ping><description><![CDATA[     摘要: Translated by Liu Dan (cleverpig) and Tian Le (Tin) 本文档将讨论在JavaFX语言中可用的各种GUIlgQƈ提供CZ代码Q讨论JavaFXlg与Swing GUIlg相比的差异? 前提条g 如果你从前没有阅读过JavaFX脚本语言h教程Q那么我们强烈推荐你在l阅L文档之前首先阅读JavaFX脚本语言h教程?你应该具有熟...  <a href='http://www.aygfsteel.com/mlh123caoer/archive/2007/08/17/137424.html'>阅读全文</a><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/137424.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-08-17 00:36 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/08/17/137424.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>讉K内存中JDBC驱动信息的小E序http://www.aygfsteel.com/mlh123caoer/archive/2007/08/13/136329.html草儿草儿Mon, 13 Aug 2007 03:43:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/13/136329.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/136329.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/13/136329.html#Feedback0http://www.aygfsteel.com/mlh123caoer/comments/commentRss/136329.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/136329.html在你同内存中多个JDBC驱动打交道的q程中,你可以访问更多的有关JDBC驱动的信息。下面是是访问这些内容的参考代码:
import java.sql.*;
import java.util.*;

public class drvinf{

public static void main(String[] args)
  {
  
  //l定属性文?br>  ResourceBundle bundle = ResourceBundle.getBundle("START");
  Connection conn=null;
  String drv=null;
  String url=null;

  //加蝲JDBC 驱动
 try{
     drv = bundle.getString("Driver");
     Class.forName(drv);
     }catch (ClassNotFoundException e)
       {System.out.println(e.getMessage());}

  //JDBC URL=jdbc:odbc:bank
  try{
     url = bundle.getString("jdbcURL");
     conn = DriverManager.getConnection(url);

     List drvs = Collections.list(DriverManager.getDrivers());
     for (int i=0; i<drvs.size(); i++)
       {
       System.out.println("----------------打印有关驱动的信?-----------");
       Driver driver = (Driver)drvs.get(i);
       String name = driver.getClass().getName();
       System.out.println(name);
       int maxV = driver.getMajorVersion();
       System.out.println(maxV);
       int minV = driver.getMinorVersion();
       System.out.println(minV);
       boolean comp = driver.jdbcCompliant();
       System.out.println(comp);
       }   
    }catch (SQLException e)
    {System.out.println(e.getMessage());}
       try{
          if(conn!=null)conn.close();
          }catch(SQLException e)   
               {System.out.println(e.getMessage());}
    }
}
START.properties 中的内容Q?

Driver=sun.jdbc.odbc.JdbcOdbcDriver
jdbcURL=jdbc:odbc:bank
login=admin
password=hashflush


草儿 2007-08-13 11:43 发表评论
]]>如何在Java中用Robotc?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/09/135499.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Thu, 09 Aug 2007 06:59:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/09/135499.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/135499.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/09/135499.html#Feedback</comments><slash:comments>12</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/135499.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/135499.html</trackback:ping><description><![CDATA[<p>Java.awt.Robot cȝ于控刉标和键盘。一旦你得到q种控制Q你能够通过你的Java代码做与<br>鼠标和键盘Q何类型的操作.q个c通常用于自动化测试。先面的代码样例向您展CRobot<br>cd何处理键盘事件。如果你q行此代码,q打开notepadQ您在notepad中看到HI CAOER。赶快试一试吧?br>import java.awt.AWTException;<br>import java.awt.Robot;<br>import java.awt.event.KeyEvent;<br><br>public class RobotExp {<br><br>public static void main(String[] args) {<br><br>try {<br><br>Robot robot = new Robot();<br>//定义5U的延迟以便你打开notepad 哈哈<br>// Robot 开始写<br>robot.delay(5000);<br>robot.keyPress(KeyEvent.VK_H);<br>robot.keyPress(KeyEvent.VK_I);<br>robot.keyPress(KeyEvent.VK_SPACE);<br>robot.keyPress(KeyEvent.VK_C);<br>robot.keyPress(KeyEvent.VK_A);<br>robot.keyPress(KeyEvent.VK_O);<br>robot.keyPress(KeyEvent.VK_E);<br>robot.keyPress(KeyEvent.VK_R);<br><br>} catch (AWTException e) {<br>e.printStackTrace();<br>}<br>}<br>}</p><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/135499.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-08-09 14:59 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/08/09/135499.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JavaFX入门教程?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/09/135471.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Thu, 09 Aug 2007 05:36:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/09/135471.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/135471.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/08/09/135471.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/135471.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/135471.html</trackback:ping><description><![CDATA[     摘要: 原作者: Anghel Leonard旉Q?8/01/2007译QCaoer2007q???JavaFX 代码同Java代码极容易集? q有一个用JavaFX装蝲一个图片到H体例子Q它允许使用者选择一个矩形区域保存这个矩形区域。这个捕捉保存操作由Java代码完成?源码列表 15 import java.io.*; import javafx.ui.*; import jav...  <a href='http://www.aygfsteel.com/mlh123caoer/archive/2007/08/09/135471.html'>阅读全文</a><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/135471.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-08-09 13:36 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/08/09/135471.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JavaFX入门教程一http://www.aygfsteel.com/mlh123caoer/archive/2007/08/07/134905.html草儿草儿Tue, 07 Aug 2007 03:49:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/07/134905.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/134905.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/07/134905.html#Feedback5http://www.aygfsteel.com/mlh123caoer/comments/commentRss/134905.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/134905.html 

原作者: Anghel Leonard
旉Q?/span>08/01/2007
译Q?/span>Caoer
2007q?/span>8?/span>5?/span>

什么是JavaFXQ?/span>SUNQ太阛_司)?/span>2007q春天发布了一个叫JavaFX新框架。这是一个泛泛的名字Q因?/span>JavaFX主要包含Script and Mobile两个lgQ在来SUN开发更多的lg?/span>

JavaFX 的核心是 JavaFX 脚本Q是一个声明式脚本语言。尽同Java代码非常不同Q但是同Javacd有很高的交互度?/span> JavaFX 中的很多cM要ؓ了更Ҏ实现Swing?/span>Java2D而设计的。?/span> JavaFX 脚本Q您能很Ҏ的ؓ文本和图形开?/span>GUI接口、动d非常COOL的效果。ƈ且,您能?/span>Java?/span>HTML代码包装?/span> JavaFX 脚本中?/span>

W二个组?/span>- JavaFX MobileQ是为移动设备开?/span>Java应用的^台。它最l会成ؓ开?/span> JavaFX 脚本的^C是现在同q篇文章实用的技术还很不兼容?/span>

JavaFX 应用的一些例?/span>

在开始学习一门新的语a前,让我们先看一?/span>JavaFX代码的一些例子?/span>JavaFX 官方站点h大量?/span>JavaFX 实例。请点击JavaFX Script 2D Graphics Tutorial下蝲该实?/span>. 下蝲完成以后Q双?/span>tutorial.jnlp 文g卛_q行。几U过后,你应该能够看到如图一?/span>JavaFX实例q行场景Q若没有出现该图片,你必Mؓ.jnlp扩展名重新配|?/span>Java Web StartQ?/span> 
Running the tutorial.jnlp
图一、运?/span> tutorial.jnlp tutorial

׃旉看一看这些例子和源代码。仅仅用有限的几行JavaFX代码p得到很多有趣的效果。如果你对于JavaFX的应用还是感到摸不着头脑Q看一看下面的两个demo。它们是StudioMoto ?/span> Tesla Motors 站点的部分重新实现。您可以?/span>OpenJFX 目站点下蝲OpenJFX 脚本Studiomoto Demo ?/span> Tesla Demo。它们需?/span>Java Web Start 才能q行Q但是也取决于你的机器配|它们可能自动运行,或者你必须扑ֈ和运行已l下载的.jnlp文g?/span>

下蝲安装JavaFX


如果你对于学习开?/span>JavaFX应用E序Q您应该了解臛_使用JavaFX三个Ҏ。同时了?/span>JavaFX应用E序不是Z览器的也很重要。最单最快捷的方法是Z?/span>JavaFXPad轻量U的工具。用该工具的主要优势是你总能立即看到你在~辑器里所作更改的效果。你能从JavaFX目|站下蝲到该工具Q?/span> JavaFXPad Q。ƈ且运行它需?/span>Java Web Start Q如图二Q?/span>

 Running the javafxpad editor
图二、运?/span>JavaFXPad~辑?/span>

使用JavaFX的另一U方式是使用JavaFX脚本NetBeans 5.5插g或?/span>Eclipse 3.2插gQ需要下载和安装NetBeans 5.5 或?/span> Eclipse 3.2.2以上集成开发工?/span> Q。若您已l?/span> NetBeans 5.5开始你?/span>JavaFX之旅,OpenJFX目|站的对?/span>NetBean开?/span>JavaFX的说?/span>会l予你帮助?/span> 怼的如果您使用ZEclipse?/span>JavaFX插gQ您可以?/span>JavaFX?/span>Eclipse插g。注意这文章中的所有例子已l在NetBeans5.5?/span>JavaFX插g中测试过Q但是应该能够用其他方法运行?/span>

使用NetBeans 5.5下的JavaFX插g开?/span>Hello World E序

每当开始学习一门新的语aӞ我们必定要写Hello World 程序:

源码列表1

import javafx.ui.*;

import java.lang.System;

Frame {

centerOnScreen: true

visible: true

height: 50

width: 350

title: "HelloWorld application..."

background: yellow

onClose: operation() {System.exit(0);}

content: Label {

text: "Hello World"

}

}

?/span>NetBeans5.5开发和q行q个程序步骤如?/span>:

1.                   启动NetBeans 5.5.

2.                   从主菜单选择File -> New Project.

3.                   在新目H口,选择目录常规目录?/span> Java 应用目(点击下一?/span>).

4.                   在新?/span>Java应用E序H口,在项目名文本框敲?/span> "FXExample".

5.                   在相同窗口,用浏览按钮选择目的目?/span>.

6.                   取消 "Set as main project" ?/span> "Create main class" 复选框 (点击完成).

7.                   叛_FXExample -> Source Packages 和选择 New -> File/Folder.

8.                   在新的文件窗口,选择另一个目录和JavaFX文gcdQ点M一步).

9.                   在新?/span>JavaFX文gH口Q敲?/span>"HelloWorld" 作ؓ文g名和"src"作ؓ目录(点击完成).

10.               拯源码列表1?/span> HelloWorld.fx.

11.               叛_FXExample 目选择目属?/span>.

12.               在项?/span>FXExample属性对话框 ,选择从目录面板运行节?/span>.

13.               在参数文本框敲入 "Hello World" (点击完成).

14.               叛_FXExample 目选择q行目选项.

如果一切良?/span>,你应该看C个窗体如图三Q?/span>

Running the Hello World application


图三?/span> ?/span>NetBeans 5.5中运?/span> Hello World 应用E序

现在你拥有了开发和q行MJavaFX应用E序?/span>IDE软g支持.

JavaFX 语法

在正式开始学?/span>JavaFXQ让我们览一遍该语言的语法要炏V如果你非常熟悉Java语言Q这些语法的大多C让你感到非常熟悉Q但是有一些会相当不一栗?/span>

JavaFX 原始cd

JavaFX 支持原始cdQ?/span>String (对应?/span> java.lang.String), Boolean (对应?/span> java.lang.Boolean), Number (对应?/span> java.lang.Number) ?/span> Integer (对应?/span> byte,short,int,long,BigInteger).

JavaFX 变量

一?/span>JavaFX变量使用var关键字声明。看下面的例子:

var x:Number = 0.9;

var name:String = "John";

var y:Integer = 0;

var flag:Boolean = true;

var numbers:Number = [1,2,3,4,5]Q?/span>

JavaFX 操作W?/span>


众所周知?/span>Java操作W?/span>&&, || ?/span> ! ?/span>JavaFX中采用下面的形式Q?/span>

·                     Java: &&
JavaFX: and

·                     Java: ||
JavaFX: or

·                     Java: !
JavaFX: not

JavaFX Ҏ


JavaFX
支持q些Ҏ. h参数、变量声明和q回值的Ҏ举例Q?/span>

function taxes(x) { var t:Number = (19.0/100.0)*x; return t; }

JavaFX if 语句


?/span>JavaFX中,你你能通过使用if语句使用条g判断?/span>

if (条g) { //动作 } else if (条g) { //动作 } else { //动作 }

JavaFX while 语句


q个 while 语句同在Java中的while语句怼?/span> while (条g) { //动作}

JavaFX for 语句


for 语句用于循环和间隔(间隔使用Ҏ?/span>[]?/span> .. W号表示).

//i 取| 0, 1, 2, 3, 4, 5象在 (i in [0..5]) { //伴随 i的动?/span> }代码块中

JavaFX q程


JavaFX
q程?/span>operation 关键字ؓ标志。一个简单的例子Q?/span>

operation startClock() {do{ while(true) {

if(seconds>=360) {seconds = 0; seconds = [0,6..360] dur 60000 linear;}

if(minutes>=360) {minutes = 0; minutes = [0,6..360] dur 3600000 linear;}

if(hours>=360) {hours = 0; hours = [0,6..360] dur 43200000 linear;} } }}

JavaFX c?/span>


JavaFX
cM?/span>class关键?/span>. 一?/span> JavaFX c能够?/span>extends 关键字承多个类使用逗号分割
q些cȝ名字。在花括号中间你可以攑ֱ性、方法和q程Q例如下面的例子Q?/span>

class Order {

attribute order_nr: String;

attribute ordertype: Order inverse Order.products;

attribute products: Order* inverse Order.ordertype;

function getOrderNr(): String;

operation addOrder(order: Order);

}

 

注意属性?/span>attribute关键字声明,Ҏ体和q程不在cM中,它们单元定义在类声明以后Q在下文你很快就能看到?/span> inverse 子句是一个可选项 Q它表示一U同在类中另一个属性的双向关系。在q个案例?/span>JavaFX自动完成更斎ͼ插入、替代和删除Q你能在Java.net上找到更完整?/span>文档?/span>

熟悉JavaFX

 

在本节Q您会看到一pd的小例子Q这些例子覆?/span>JavaFX的各U特性和功能。主要目的是让你熟悉JavaFX代码?/span>JavaFX应用E序的逻辑。第二个目标是当你需要开发仅仅需要几行代码就会有非常LGUIQ动d好的效果时候你确?/span>JavaFX值得好好研究一下。所有列出的例子介l关?/span>JavaFX的技巧。每一个例子只使用很少的描q处理,所以不要想扑ֈ大量的注释。所有这些可讉K的例子你都是你自己就能运行的Q所以让我们开始吧。当我们需要?/span>System.out.println 打印属性值时候,你可以把它的名字放进含有引用的字W串Q象源码列表2中所C的那样?/span>

源码列表2

//带有应用文本的表辑ּ

import java.lang.System;
var mynumber:Number = 10;
System.out.println("
数字?/span>: {mynumber}");

 

l果: 数字?/span>: 10
JavaFX
支持变量的计数这样一个有用的功能。这个功能利用下面的三个操作W实玎ͼ

·                     ?: 可选的(可能?/span> null)

·                     +: 1或多?/span>

·                     *: 0或多?/span>

源码列表3

//变量计数

import java.lang.System;
var mynumbers:Number* = [1,2,7];
System.out.println("
数字?/span>: {mynumbers}");

 

l果: 数字?/span>: 1 2 7
?/span>JavaFX?/span>, 在声明部分不指定变量的类型是可能的?/span> q不会生错误,因ؓJavaFX 在该变量的使用中自动发现它的类型?/span>

源码列表 4

//变量cd是可选的

import java.lang.System;
var days = ["Monday,","Friday,","Sunday"];
System.out.println("
你必d?/span>: {days}");


l果: 你必d?/span>: Monday, Friday, Sunday
你可以?/span>sizeof 操作W得C个数l的大小Q?/span>

源码列表 5

//得到一个数l的大小

import java.lang.System;
var lotto = [21,30,11,40,5,6];
System.out.println("
数组大小:{sizeof lotto}");

 

l果: 数组大小: 6

您能使用 [] 操作W得到满x定条件的子数l。条件放?/span> [] 中作为布判?/span> 。这个与XPath 谓词怼.

源码列表 6

//使用[] 操作W?/span> -?/span> XPath

import java.lang.System;
var mynumbers = [1,2,7,3,30,15,14,6,4];
var numbers = mynumbers[n|n < 10];
System.out.println("
10的数字ؓ: {numbers}");

 

l果: 10的数字ؓ: 1 2 7 3 6 4
你可以?/span>indexof 操作W得到指定序C|的数组中一个元?em>Q?/em>

源码列表 7

//q回指定序数位置的数l中的元?/span>

import java.lang.System;

var mynumbers = [1,2,7,3,30,15,14,6,4];
var number_four = mynumbers[indexof . == 4];
System.out.println("
数字4:{number_four}");

 

l果: 数字4: 30

当您惌向一个数l中插入一个元素时Q你可以使用下列 insert 语句中的一?/span>:

·                     as first: 在第一个位|插?/span>

·                     as last:在最后一个位|?/span>(默认)插入

·                     before: 在前一个位|插?/span>

·                     after:在下一个位|插?/span>

你可以?/span> delete 语句从一个数l中删除一个元?/span>.

源码列表8

//插入和删除语?/span>
import java.lang.System;
var mynumbers = [1,2,7];
System.out.println("Before inserting anything: {mynumbers}");
insert 10 into mynumbers;
System.out.println("After inserting at the end the \"10\" value:{mynumbers}");
insert [8,6,90] as first into mynumbers;
System.out.println("After inserting at the first positions the \"8,6,90\" values:{mynumbers}");
insert 122 as last into mynumbers;
System.out.println("After inserting at the end the \"122\" value:{mynumbers}");
insert 78 before mynumbers[3];
insert 11 after mynumbers[3];
System.out.println("After inserting the \"78\" and \"11\" values before/after the 3rd element:{mynumbers}");
delete mynumbers[. == 122];
System.out.println("After deleting:{mynumbers}");

l果:
Before inserting anything: 1 2 7
After inserting the 10 value at the end: 1 2 7 10
After inserting the 8, 6, and 90 values at the first positions: 8 6 90 1 2 7 10
After inserting the 122 value at the end: 8 6 90 1 2 7 10 122
After inserting the 78 and 11 values before/after the 3rd element: 8 6 90 78 11 1 2 7 10 122
After deleting: 8 6 90 78 11 1 2 7 10

JavaFX中的一个非常好的功能是list。这个功能?/span> select ?/span> foreach 操作W实现。这有两个例子(一个?/span> select 和?/span> foreach) 得到指定间隔的奇数?/span>

源码列表9

//JavaFX中的 select ?/span> foreach 操作W?/span>

import java.lang.System;
function odd(p:Number)
{ return select i from i in [1.0 ..p]
 where (i%2 == 0.0);
}

var result = odd(10.0);
System.out.println("Odd numbers:{result}");

l果: Odd numbers: 2.0 4.0 6.0 8.0 10.0

源码列表10 (?/span> 源码列表 9相同, 但是?/span> foreach)

//JavaFX中的select ?/span> foreach 操作W?/span>

import java.lang.System;
function odd(p:Number) {
       return foreach (i in [1.0 ..p]
     where (i%2 == 0.0)) i;
     }
var result = odd(10.0);
System.out.println("Odd numbers:{result}");

q个例子昄?/span> foreach 对于创徏好的效果非常有用?/span>

源码列表11

//JavaFX中的 select ?/span> foreach 操作W?/span>

import java.lang.*;
import javafx.ui.*;
import javafx.ui.canvas.*;
Frame {
centerOnScreen: true
visible: true
height: 500
width: 500
title: "Foreach demo..."
onClose: operation() {
System.exit(0);
}
content: ScrollPane {
background: white
view: Canvas {
 content: bind
foreach (i in [1..8], j in [1..8])
Rect { x: i*30 y: j*30 width:30 height:30 fill: Color {red: (100+i) green: (100+j) blue: (100+(i*j))
}
stroke:white
strokeWidth:1 } }

}

}

 Running listing 11
囑֛. q行源码列表 11

使用双箭头括号引用ؓJavaFX关键字的变量名或者属性名Q如下所C?/span>

源码列表 12

//标志W引?/span>

import java.lang.System;

for (<<for>> in [0..3]) {

System.out.println("for = {<<for>>}");

}

l果: for = 0 for = 1 for = 2 for = 3

当你需要开?/span>Swing接口ӞJavaFX 是一个伟大的工具Q因?/span> JavaFX 考虑了非常多用来降低代码量和?/span>javax.swing.*?/span>q存友好。在上一节(使用NetBeans5.5中的JavaFX插g试Hello World应用E序Q,你看C创徏一个窗体是如何Ҏ。这有两个更好的例子Q创建按钮和文本框?/span>

源码列表 13

import javafx.ui.*;

import java.lang.System;

Frame{

content: Button { text: "Exit" action: operation() { System.exit(0); } }

visible: true

}

  Running listing 13
图五. q行源码 13

源码列表14

import javafx.ui.*;

Frame {

content: GroupPanel { var myRow = Row { alignment: BASELINE }

var label_col = Column { alignment: TRAILING }

var field_col = Column { alignment: LEADING }

rows: [myRow] columns: [label_col, field_col]

content: [SimpleLabel { row: myRow column: label_col text: "Type your text here:" }, TextField { row: myRow column: field_col columns: 50 }] }

visible: true

};

 Running listing 14
囑օ. q行源码 14

Java.net 也有使用JavaFx创徏 Swing接口的教E?/span>

 


 



草儿 2007-08-07 11:49 发表评论
]]>
ZStruts1.2.9框架的登录页面的处理q程http://www.aygfsteel.com/mlh123caoer/archive/2007/08/03/134201.html草儿草儿Fri, 03 Aug 2007 03:36:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/03/134201.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/134201.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/08/03/134201.html#Feedback0http://www.aygfsteel.com/mlh123caoer/comments/commentRss/134201.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/134201.htmlStruts Web框架是现在构建Web应用必须的开发框架之一。以下是我们学习Struts框架旉常都会看到的登录页面程序的处理程分析Q希望和q大博友交流Q?/p>

ZStruts框架dE序应用的UML序?br>Struts交互?src="http://www.aygfsteel.com/images/blogjava_net/mlh123caoer/24610/r_struts%e4%ba%a4%e4%ba%92%e5%9b%be.jpg"

处理步骤Q?/p>

1、客户从览器客L向Web服务器发求,服务器将h转发到Web容器Q比如:TomcatQ根据请求\径URL扑ֈActionServletQWeb容器调用Servlet的servic()ҎQ根据请求参数的不同调用doGet()或者doPost()Ҏ?/p>

2、而ActionServlet的doGet()或者doPost()Ҏ调用process()Ҏ处理h和响应,生成RequestProcess对象处理配置文gstruts-config.xml中的配置信息Q依ơ调用processMapping()-查找处理此次h的Action信息q返回ActionMapping对象QprocessActionForm()--创徏此次h的ActionForm对象QprocessActionCreate()--创徏处理此次h的Action实例QLoginAction对象Q;processActionPerform()--执行Action实例的execute()Ҏ?/p>

3、通过调用execute()Ҏ获取LoginForm存储的用户和密码{数据信息,其中ActionForm Bean、ActionMapping、request、response对象传递给LoginAction对象QAction实例Q;执行完必要的逻辑处理比如查询数据库后Q返回一个ActionForward对象Q由该对象调用RequestProcess对象中的processForwardConfig()Ҏ解析配置文g中蟩转参敎ͼ转发到相应的View面success.jsp或者failure.jsp?/p>



草儿 2007-08-03 11:36 发表评论
]]>
JSP在TOMCAT中的处理生命周期http://www.aygfsteel.com/mlh123caoer/archive/2007/07/14/130271.html草儿草儿Sat, 14 Jul 2007 06:43:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/07/14/130271.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/130271.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/07/14/130271.html#Feedback2http://www.aygfsteel.com/mlh123caoer/comments/commentRss/130271.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/130271.html1、将WEB应用部v到TOMCAT容器Q容器启动读取应用的部v文gweb.xml,但不?jsp文g做Q何处理请求?/div>
2、客L击连接请求某?jsp文gQ容器开始将.jsp文g转换Z个servrletcȝ.java源代码。查看指令,得到转换的可能需要的信息。创Z个HttpServlet子类Q对于Tomcat5所生成的servlet会扩展org.apache.jasper.runtime.HttpJspBasecR若有一个page指o有import属性,生成的类文g的最上面会写入import语句。例如在Tomcat5中加入包语句Qpackage org.apache.jspQ若有声明容器将q些声明写道cLӞ通常攑֜服务Ҏ的下面。Tomca5声明了自q一个静态方法和一个实例方法。然后徏立服务方法,Ҏ名ؓ_jspService()。所生成的servlet会覆盖servlet类的service()Ҏ。_jspService()直接由service()调用Q要接收HttpServletRequest和HttpServletResponse参数。在建立q个Ҏ的时候,容器会声明ƈ初始化所有的隐式对象。将普通的HTMLQ模板文Ӟ、scrptlet和表辑ּ攑ֈ服务Ҏ里,q行格式化,q写至PrintWrite响应输出?/div>
3、容器尝试将q个servlet.java源文件编译ؓ.class文g?/div>
4、容器家在新生成的servletcR?/div>
5、容器实例化servletQƈDservlet的jspInit()Ҏq行。对象现在已成ؓ一个完整的servlet准备qAQ接受客Lh?/div>
6、容器创Z个新U程来处理客戯求,servlet的service()Ҏq行。以后的处理同普通的servlet处理q程。最lservlet向客戯回一个响应?/div>
需要注意的是:在JSP生命周期中,JSP的{换和~译q程只发生一ơ。一旦第一ơ编译完成,以后的调用同普通的servlet一栗大多数容器开发商提供预{化和~译的办法,是这些工作提前完成?/div>

草儿 2007-07-14 14:43 发表评论
]]>一个Servlet生命周期QTomcat处理h中)http://www.aygfsteel.com/mlh123caoer/archive/2007/07/07/128789.html草儿草儿Sat, 07 Jul 2007 08:04:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/07/07/128789.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/128789.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/07/07/128789.html#Feedback0http://www.aygfsteel.com/mlh123caoer/comments/commentRss/128789.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/128789.html1、客户发求?gt;Web 服务器{发到Web容器TomcatQ?br>2、TomcatȝE对转发来用Lh做出响应创徏两个对象QHttpServletRequest和HttpServletResponseQ?br>3、从h中的URL中找到正ServletQTomcat为其创徏或者分配一个线E,同时?创徏的两个对象传递给该线E;
4、Tomcat调用Servlet的servic()ҎQ根据请求参数的不同调用doGet()或者doPost()ҎQ?br>5、假设是HTTP GEThQdoGet()Ҏ生成静态页面,q组合到响应对象里;
6、ServletU程l束QTomcat响应对象{换ؓHTTP响应发回l客P同时删除h和响应对象?br>从该q程中,我们可以理解Servlet的生命周期:Servletcd载(对应3步)QServlet实例化(对应3步)Q调用initҎQ对?步)Q调用service()ҎQ对??步)Q;调用destroy()ҎQ对?步)?img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/128789.html" width = "1" height = "1" />

草儿 2007-07-07 16:04 发表评论
]]>
Adobe Flex2http://www.aygfsteel.com/mlh123caoer/archive/2007/07/06/128519.html草儿草儿Fri, 06 Jul 2007 02:59:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/07/06/128519.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/128519.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/07/06/128519.html#Feedback1http://www.aygfsteel.com/mlh123caoer/comments/commentRss/128519.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/128519.html
Flex2应用E序在无所不在的轻量虚拟机Flash播放?跨^台运行。该q_包括以下技术:
1、一U基于XML的MXML语言Q它支持面对设计者的GUIlg声明式编E;
2、标准的OOP语言Q基于最新的ECMASript规范的AS3Q?br>3、用FDSQFlex Data ServicesQ方式进行服务端集成Q是客户端程序能够对J2EE世界透明讉KQ?br>4、图表组Ӟ
5、基于Eclipse功能强大的IDEQ拥有自动化部vQ调试,代码跟踪能力?br>Flex2q_易于扩展也对服务端技术例如JAVAQColdFusionQPHPQRubyQASP{等实现集成。即发布的Adobe Apollo版允许基于Flash PlayerQFlexQPDF和HTML桌面E序的构建?br>SWF文g格式是开攄Q有W三方开源品象Laszlopȝ的OpenLaszlo为构建RIAE序提供工具Q程序用Flash Player发布?br>与上一个版本相反,Flex2提供一U不会招致授权协议纠U构建RIA的方式。以下都免费得到Q?br>1、MXMLQ基于XML声明式用来构建GUI的编E语aQ?br>2、ActionScript3.0Q与JAVA怼的OOP语言Q?br>3、Flash Player9Q运行在WEB览器占有很内存的虚拟机,q行你编译的二进制代码(.SWFQ?
4、命令行~译器和调试器;
5、Flex 框架Q包含设计良好的GUIlg库:按钮Qtab目录Q数据网|树控Ӟ动画效果{等很多?br>6、Flex数据服务预览版:部v在J2EE服务器WEBE序与运行在Flash Player上的ActionScript客户端程序通信模板。FDS预览版只能运行在单CPU上ƈ且不支持在(24*7Q高可访问性配|模式下使用?/p>

构徏一个基本的Flex2E序步骤有:
1、通过增加XMLlg例如下面按钮来构个程序:
<mx:Button label="Place Order" click="processOrder(event)"/>
若用收费的开发工具Flex Builder IDEQ你可以用拖拉技术了。当Ӟ你也可以手写MXML文本?br>2、写按照业务逻辑ActionScript代码Q例如:
private function processOrder (event:Event):void{
//业务逻辑代码
}
3、编译代码。Flex~译器自动的把MXML转换为ActionScript代码q以SWF格式字节码输出在Flash Player 9或者更高版本运行,如果你用Flex Builder IDEQ你得到更爽的自动化编译过E?br>4、在你选择的WEB服务器中部vSWF文g和封装好的HTML面。如果你用收q那个工具Q这些过E完全透明?br>有一个在UFlex~译器网站,你可以试着写一些Flex代码而不用在你自q电脑上安装Q何东ѝ同时该|站提供了一些示例代码供您修改和q行。还{什么,GOQ?a >http://try.flex.org/



草儿 2007-07-06 10:59 发表评论
]]>
JDOM?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/06/25/126177.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Mon, 25 Jun 2007 10:33:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/06/25/126177.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/126177.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/06/25/126177.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/126177.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/126177.html</trackback:ping><description><![CDATA[<a target=_new><u><font face=Verdana color=#800080>JDOM</font></u></a><font face=Verdana>是一U?</font><a target=_new><u><font face=Verdana color=#0000ff>XML</font></u></a><font face=Verdana> 的独?Java 工具包,用于快速开?XML 应用</font><a target=_new><u><font face=Verdana color=#0000ff>E序</font></u></a><font face=Verdana>。它?/font><a target=_new><u><font face=Verdana color=#0000ff>设计?/font></u></a><font face=Verdana>?Java 语言的语法乃臌义?</font> <p><font face=Verdana>      JDOM是两位著名的 Java 开发h员兼作者,Brett Mclaughlin ?Jason Hunter 的创作成果, 2000 q初?/font><a target=_new><font face=Verdana color=#0000ff><u>c?/u></font></a><font face=Verdana>g Apache 协议的许可下QJDOM 作ؓ一个开放源代码目正式开始研发,JDOM 作ؓ一个开放源代码目正式开始了。它已成长ؓ包含来自q泛?Java 开发h员的投稿、集中反馈及错误修复的系l,q致力于建立一个完整的Z Java q_的解x案,通过 Java 代码来访问、操作ƈ输出 XML 数据?</font></p> <p><font face=Verdana>      虽然许多Java 开发h员每天都在?XMLQSun 却在?XML 整合q?Java q_斚w落后了。因为在 XML 成ؓ从商家对商家集成?Web 站点内容水化等斚w的关键技术之前,Java 2 q_已l非常流行了。Sun 已经使用 JSR q程使之成ؓ现存 XML <a target=_new><u><font color=#0000ff>API</font></u></a> 的E,q一点已被广泛接受。目前最显著的是加入?JAXP Q用?XML 语法分析?Java APIQ,其中包含了三?a target=_new><u><font color=#0000ff>软g?/font></u></a>Q?</font></p> <p><font face=Verdana>      ·org.w3c.dom QW3C 推荐的用?XML 标准规划文档<a target=_new><u><font color=#0000ff>对象</font></u></a>模型?Java 工具 <br>      ·org.xml.sax Q用于对 XML q行语法分析的事仉动的?API <br>      ·javax.xml.parsers Q工厂化工具Q允许应用程序开发h员获得ƈ配置Ҏ的语法分析器工具 JDOM 能够替换 org.w3c.dom <a target=_new><u><font color=#0000ff>软g</font></u></a>包来有计划地操作 XML 文档</font></p> <font face=Verdana> <p><br>      JDOM是一?a target=_new><u><font color=#0000ff>开?/font></u></a>目Q它Z树型l构Q利用纯JAVA的技术对XML文档实现解析、生成、序列化以及多种操作?/p> <p>      JDOM 直接为JAVA~程服务。它利用更ؓ强有力的JAVA语言的诸多特性(Ҏ重蝲、集合概念以及映)Q把SAX和DOM的功能有效地l合h?/p> <p>      Jdom是用Java语言诅R写、操作XML的新API函数。Jason Hunter ?Brett McLaughlin公开发布了它?.0版本。在直觉、简单和高效的前提下Q这些API函数被最大限度的优化。在接下来的幅里将介绍怎么用Jdom去读写一个已l存在的XML文档?/p> <p><br>      在用设计上可能地隐藏原来使用XMLq程中的复杂性。利用JDOM处理XML文档是一件轻松、简单的事?/p> <p>      JDOM ?000q的春天被Brett McLaughlin和Jason Hunter开发出来,以I补DOM及SAX在实际应用当中的不之处?/p> <p>      q些不之处主要在于SAX没有文档修改、随问以及输出的功能Q而对于DOM来说QJAVAE序员在使用时来用v来总觉得不太方ѝ?/p> <p>      DOM的缺点主要是来自于由于Dom是一个接口定义语aQIDLQ?它的d是在不同语言实现中的一个最低的通用标准Qƈ不是为JAVA特别设计的。JDOM的最新版本ؓJDOM Beta 9。最qJDOM被收录到JSR-102内,q标志着JDOM成ؓ了JAVAq_l成的一部分?/p> <p>      ?JDOM 中,XML 元素是 Element 的实例,XML 属性就?Attribute 的实例,XML 文档本n是 Document 的实例?/p> <p>      因ؓ JDOM 对象是?Document、Element ?Attribute q些cȝ直接实例Q因此创Z个新 JDOM 对象如?Java 语言中?new 操作W一样容易。JDOM 的用是直截了当的?/p> <p>      JDOM 使用标准?Java ~码<a target=_new><u><font color=#0000ff>模式</font></u></a>。只要有可能Q它使用 Java new 操作W而不故弄玄虚使用复杂的工厂化模式Q对象操作即便对于初学用户也很方便?/p> <p><br><strong>一、JDOM包概?/strong></p> <p>JDOM是由以下几个包组成的</p> <p>org.jdom包含了所有的xml文档要素的javac?br>org.jdom.adapters包含了与dom适配的javac?br>org.jdom.filter包含了xml文档的过滤器c?br>org.jdom.input包含了读取xml文档的类<br>org.jdom.output包含了写入xml文档的类<br>org.jdom.transform包含了将jdomxml文档接口转换为其他xml文档接口<br>org.jdom.xpath包含了对xml文档xpath操作的类</p> <p><strong>二、JDOMc说?/strong></p> <p>      1、org.JDOMq个包里的类是你J解析xml<a target=_new><u><font color=#0000ff>文g</font></u></a>后所要用到的所有数?a target=_new><u><font color=#0000ff>cd</font></u></a>?/p> <p>Attribute<br>CDATA<br>Coment<br>DocType<br>Document<br>Element<br>EntityRef<br>Namespace<br>ProscessingInstruction<br>Text</p> <p>      2、org.JDOM.transform在涉及xslt格式转换时应使用下面?个类</p> <p>JDOMSource<br>JDOMResult<br>org.JDOM.input</p> <p>      3、输入类Q一般用于文档的创徏工作</p> <p>SAXBuilder<br>DOMBuilder<br>ResultSetBuilder</p> <p>      4、org.JDOM.output输出c,用于文档转换输出</p> <p>XMLOutputter<br>SAXOutputter<br>DomOutputter<br>JTreeOutputter</p> <p>      使用前注意事:</p> <p>      1.JDOM对于JAXP以及TRax的支?/p> <p>      JDOM支持JAXP1.1Q你可以在程序中使用M的parser工具c?默认情况下是JAXP的parser?br>制定特别的parser可用如下形式<br>SAXBuilderparser<br>=newSAXBuilder("org.apache.crimson.parser.XMLReaderImpl");<br>Documentdoc=parser.build("http://www.cafeconleche.org/");<br>//workwiththedocument...<br>JDOM也支持TRaXQXSLT可通过JDOMSource以及JDOMResultcL转换Q参见以后章节)</p> <p>      2.注意在JDOM里文档(DocumentQ类由org.JDOM.Document来表C。这要与org.w3c.dom中的Document区别开Q这2U格式如何{换在后面会说明?br>      以下如无Ҏ均指JDOM里的Document?/p> <p><strong>三、JDOM主要使用Ҏ</strong></p> <p>1.Ducumentc?/p> <p>(1)Document的操作方法:</p> <p>Elementroot=newElement("GREETING");<br>Documentdoc=newDocument(root);<br>root.setText("HelloJDOM!");<br>或者简单的使用Documentdoc=newDocument(newElement("GREETING").setText("HelloJDOM!t"));<br>q点和DOM不同。Dom则需要更为复杂的代码Q如下:<br>DocumentBuilderFactoryfactory=DocumentBuilderFactory.newInstance();<br>DocumentBuilderbuilder=factory.newDocumentBuilder();<br>Documentdoc=builder.newDocument();<br>Elementroot=doc.createElement("root");<br>Texttext=doc.createText("Thisistheroot");<br>root.appendChild(text);<br>doc.appendChild(root);<br>注意事项QJDOM不允许同一个节点同时被2个或多个文档相关联,要在W?个文档中使用原来老文档中的节点的话。首先需要用detach()把这个节点分开来?/p> <p>(2)从文件、流、系lID、URL得到Document对象Q?/p> <p>DOMBuilderbuilder=newDOMBuilder();<br>Documentdoc=builder.build(newFile("jdom_test.xml"));<br>SAXBuilderbuilder=newSAXBuilder();<br>Documentdoc=builder.build(url);<br>在新版本中DOMBuilder已经Deprecated掉DOMBuilder.builder(url)Q用SAX效率会比较快?br>q里举一个小例子Qؓ了简单v见,使用String对象直接作ؓxml数据源:<br>PublicjdomTest(){<br>StringtextXml=null;<br>textXml="";<br>textXml=textXml+<br>"aaabbbcccddd";<br>textXml=textXml+"";<br>SAXBuilderbuilder=newSAXBuilder();<br>Documentdoc=null;<br>Readerin=newStringReader(textXml);<br>try{<br>doc=builder.build(in);<br>Elementroot=doc.getRootElement();<br>Listls=root.getChildren();//注意此处取出的是root节点下面的一层的Element集合<br>for(Iteratoriter=ls.iterator();iter.hasNext();){<br>Elementel=(Element)iter.next();<br>if(el.getName().equals("to")){<br>System.out.println(el.getText());<br>}<br>}<br>}<br>catch(IOExceptionex){<br>ex.printStackTrace();<br>}<br>catch(JDOMExceptionex){<br>ex.printStackTrace();<br>}<br>}<br>(3)DOM的document和JDOM的Document之间的相互{换用方法,单!<br>DOMBuilderbuilder=newDOMBuilder();<br>org.jdom.DocumentjdomDocument=builder.build(domDocument);<br>DOMOutputterconverter=newDOMOutputter();//workwiththeJDOMdocument…<br>org.w3c.dom.DocumentdomDocument=converter.output(jdomDocument);<br>//workwiththeDOMdocument…</p> <p>2.XML文档输出</p> <p>XMLOutPutterc:<br>JDOM的输出非常灵z?支持很多Uio格式以及风格的输?br>Documentdoc=newDocument(...);<br>XMLOutputteroutp=newXMLOutputter();<br>outp.output(doc,fileOutputStream);//Rawoutput<br>outp.setTextTrim(true);//Compressedoutput<br>outp.output(doc,socket.getOutputStream());<br>outp.setIndent("");//Prettyoutput<br>outp.setNewlines(true);<br>outp.output(doc,System.out);<br>详细请参阅最新的JDOMAPI手册</p> <p>3.Elementc:</p> <p>(1)览Element?br>Elementroot=doc.getRootElement();//获得根元素element<br>ListallChildren=root.getChildren();//获得所有子元素的一个list<br>ListnamedChildren=root.getChildren("name");//获得指定名称子元素的list<br>Elementchild=root.getChild("name");//获得指定名称的第一个子元素<br>JDOMl了我们很多很灵zȝ使用Ҏ来管理子元素Q这里的List是java.util.ListQ?br>ListallChildren=root.getChildren();<br>allChildren.remove(3);//删除W四个子元素<br>allChildren.removeAll(root.getChildren("jack"));//删除?#8220;jack”的子元素<br>root.removeChildren("jack");//便捷写法<br>allChildren.add(newElement("jane"));//加入<br>root.addContent(newElement("jane"));//便捷写法<br>allChildren.add(0,newElement("first"));</p> <p>(2)UdElements:<br>在JDOM里很?br>Elementmovable=newElement("movable");<br>parent1.addContent(movable);//place<br>parent1.removeContent(movable);//remove<br>parent2.addContent(movable);//add<br>在Dom?br>Elementmovable=doc1.createElement("movable");<br>parent1.appendChild(movable);//place<br>parent1.removeChild(movable);//remove<br>parent2.appendChild(movable);//出错!<br>补充Q纠错?br>JDOM的Element构造函敎ͼ以及它的其他函数Q会查element是否合法?br>而它的add/removeҎ会检查树l构Q检查内容如下:<br>1.在Q何树中是否有回环节点<br>2.是否只有一个根节点<br>3.是否有一致的命名I间QNamespacesQ?/p> <p>(3)Element的text内容d</p> <p>Acooldemo</p> <p>//Thetextisdirectlyavailable<br>//Returns"\nAcooldemo\n"<br>Stringdesc=element.getText();<br>//There'saconvenientshortcut<br>//Returns"Acooldemo"<br>Stringdesc=element.getTextTrim();<br>(4)Elment内容修改<br>element.setText("Anewdescription");<br>3.可正解释特D字W?br>element.setText("</p> <p><strong>四、JDOM的应?/strong></p> <p>Q一Q、XML文档创徏</p> <p>      我们由零开始利用JDOM生成一个XML文档。最后的l果(h文档)看v来象q样Q?/p> <p><br>kingwong</p> <p>87654321</p> <p>1.?MyInfo 为根元素创徏文档</p> <p>Element rootElement = new Element("MyInfo");//所有的XML元素都是 Element 的实例。根元素也不例外Q)<br>Document myDocument = new Document(rootElement);//以根元素作ؓ参数创徏Document对象。一个Document只有一个根Q即root元素?/p> <p>2.l根元素d属?/p> <p>Attribute rootAttri = new Attribute("comment","introduce myself");//创徏名ؓ commnet,gؓ introduce myself 的属性?br>rootElement.setAttribute(rootAttri);//刚创徏的属性添加到根元素?br>q两行代码你也可以合成一行来写,象这P<br>rootElement.setAttribute(new Attribute("comment","introduce myself"));<br>或?br>rootElement.setAttribute("comment","introduce myself");</p> <p>3.d元素和子元素</p> <p>JDOM里子元素是作?contentQ内容)d到父元素里面ȝ,所谓content是cM上面h文档中之间的东东Q即kingwong。罗嗦了Ҏ吧:Q?br>Element nameElement = new Element("name");//创徏 name 元素<br>nameElement.addContent("kingwong");//kingwong作ؓcontentd到name元素<br>rootElement.addContent(nameElement);//name元素作ؓcontentd到根元素</p> <p>q三行你也可以合Z句,象这P<br>rootElement.addContent((Content)(new Element("name").addContent("kingwong")));//因ؓaddContent(Content child)Ҏq回的是一个Parent接口Q而Elementcd时承了Contentcd实现了Parent接口Q所以我们把它造型成Content?/p> <p>我们用同LҎd带属性的子元?br>rootElement.addContent(new Element("sex").setAttribute("value","male"));//注意q里不需要{型,因ؓaddAttribute(String name,String value)q回值就是一?Element?/p> <p>同样的,我们d元素到根元素下,用法上一P只是E微复杂了一些:<br>rootElement.addContent((Content)(new Element("contact").addContent((Content)(new Element("telephone").addContent("87654321")))));<br>如果你对q种写Ş式还不太习惯Q你完全可以分步来做Q就象本节刚开始的时候一栗事实上如果层次比较多,写成分步的Ş式更清晰些,也不Ҏ出错?/p> <p>4.删除子元?/p> <p>q个操作比较单:<br>rootElement.removeChild("sex");//该方法返回一个布?/p> <p>到目前ؓ止,我们学习了一下JDOM文档生成操作。上面徏立了一个样本文档,可是我们怎么知道对不对呢Q因此需要输出来看一下。我们将JDOM生成的文档输出到控制収ͼ使用 JDOM ?XMLOutputter cR?/p> <p>5. ?JDOM 转化?XML 文本</p> <p>XMLOutputter xmlOut = new XMLOutputter(" ",true);<br>try {<br>xmlOut.output(myDocument,System.out);<br>} catch (IOException e) {<br>e.printStackTrace();<br>}<br>XMLOutputter 有几个格式选项。这里我们已指定希望子元素从父元素羃q两个空|q且希望元素间有I?br>new XMLOutputter(java.lang.String indent, boolean newlines)q个Ҏ在最新版本中已经不徏议用。JDOM有一个专门的用来定义格式化输出的c:org.jdom.output.FormatQ如果你没有Ҏ的要求,有时候用里面的几个静态方法(应该可以说是预定义格式)?getPrettyFormat()可以了。我们把上面的输出格式稍微改一下,pq样Q?br>XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat()); </p> <p>6.JDOM文档转化为其他Ş?/p> <p>XMLOutputter q可输出?Writer ?OutputStream。ؓ了输出JDOM文档C个文本文Ӟ我们可以q样做:<br>FileWriter writer = new FileWriter("/some/directory/myFile.xml");<br>outputter.output(myDocument, writer);<br>writer.close();</p> <p>XMLOutputter q可输出到字W串,以便E序后面q行再处?<br>Strng outString = xmlOut.outputString(myDocument);</p> <p>当然Q在输出的时候你不一定要输出所有的整个文档Q你可以选择元素q行输出Q?br>xmlOut.output(rootElement.getChild("name"),System.out);<br>一句话QJDOM非常灉|方便Q如果你惌一步研IJDOMQ请到官方网站去看一看:http://www.jdom.org</p> <p>本节CZ源码Q?br>package com.cyberobject.study;</p> <p>import java.io.IOException;</p> <p>import org.jdom.Attribute;<br>import org.jdom.Content;<br>import org.jdom.Document;<br>import org.jdom.Element;<br>import org.jdom.output.Format;<br>import org.jdom.output.XMLOutputter;</p> <p>/**<br>* @author kingwong<br>*<br>* TODO To change the template for this generated <a target=_new><u><font color=#0000ff>type</font></u></a> comment go to<br>* Window - Preferences - Java - Code Style - Code Templates<br>*/<br>public <a target=_new><u><font color=#0000ff>class</font></u></a> TestJDOM {</p> <p>public static void main(String[] args)<br>{<br>Element rootElement = new Element("MyInfo");<br>Document myDocument = new Document(rootElement);</p> <p>// Attribute rootAttri = new Attribute("comment","introduce myself");<br>// rootElement.setAttribute(rootAttri);</p> <p>rootElement.setAttribute("comment","introduce myself");<br>//rootElement.setAttribute(new Attribute("comment","introduce myself"));<br>// Element sexElement = new Element("sex");<br>// rootElement.addContent(sexElement);</p> <p>// Element nameElement = new Element("name");<br>// nameElement.addContent("kingwong");<br>// rootElement.addContent(nameElement);</p> <p>rootElement.addContent((Content)(new Element("name").addContent("kingwong")));<br>rootElement.addContent(new Element("sex").setAttribute("value","male"));<br>rootElement.addContent((Content)(new Element("contract").addContent((Content)(new Element("telephone").addContent("87654321")))));</p> <p>rootElement.removeChild("sex");</p> <p>XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());<br>try {<br>xmlOut.output(myDocument,System.out);<br>//xmlOut.output(rootElement.getChild("name"),System.out);<br>//String outString = xmlOut.outputString(myDocument);<br>} catch (IOException e) {<br>e.printStackTrace();<br>}<br>}<br>}</p> <p><br>Q二Q、XML文档解析</p> <p>JDOM 不光可以很方便的建立XML文档Q它的另一个用处是它能够读取ƈ操作现有?XML 数据?br>JDOM的解析器在org.jdom.input.*q个包里Q其中的DOMBuilder的功能是DOM模型的Document解析成JDOM模型的DocumentQSAXBuilder的功能是从文件或中解析出符合JDOM模型的XML树。由于我们经常要从一个文仉d数据Q因此我们应该采用后者作析工兗?br>解析一个xml文档Q基本可以看成以下几个步骤:</p> <p>1.实例化一个合适的解析器对?/p> <p>本例中我们用SAXBuilder:<br>SAXBuilder sb = new SAXBuilder();</p> <p>2.以包含XML数据的文件ؓ参数Q构Z个文档对象myDocument</p> <p>Document myDocument = sb.build(/some/directory/myFile.xml);</p> <p>3.获到根元?/p> <p>Element rootElement = myDocument.getRootElement();</p> <p>一旦你获取了根元素Q你可以很方便地对它下面的子元素进行操作了Q下面对Element对象的一些常用方法作一下简单说明:<br>getChild("childname") q回指定名字的子节点,如果同一U有多个同名子节点,则只q回W一个;如果没有q回null倹{?br>getChildren("childname") q回指定名字的子节点List集合。这样你可以遍历所有的同一U同名子节点?<br>getAttributeValue("name") q回指定属性名字的倹{如果没有该属性则q回null,有该属性但是gؓI,则返回空字符丌Ӏ?br>getChildText("childname") q回指定子节点的内容文本倹{?br>getText() q回该元素的内容文本倹{?/p> <p>q有其他没有|列出来的方法,如果需要的话,可以随时查阅JDOM的在U文档:http://www.jdom.org/docs/apidocs/index.html。当然你可以在你需要的地方d、删除元素操作,q记得上面的创徏XML的方法吗Q呵呵~~~</p> <p>学习C东还是从实例学v最为快P下面单D个例子,׃上面的XMLh代码来学习JDOM的XML解析。本例中d了样本XML文g里一些属性和contentQ最后我们还在contact元素里插入了一个新元素wanghua@cyberobject.com" />。尽我们实C对于XML的基本操作,l心的朋友可能会<br>有疑问:如果XML文档的层ơ稍微复杂一些,如果嵌套多达几十上百层的话(开个玩W)Q如果靠q样从根元素一U一U地通过getChild("childname")来访问子元素的话Q将会非常痛苦!是的Q的是q样Q但是我们有另一个有力的工具XPathQؓ什么不用呢Q这是后话!先卖个关子(手敲累啦Q下回吧Q呵呵)?/p> <p>/*<br>* Created on 2004-8-21<br>*<br>* TODO To change the template for this generated file go to<br>* Window - Preferences - Java - Code Style - Code Templates<br>*/<br>package com.cyberobject.study;</p> <p>import org.jdom.Document;<br>import org.jdom.Element;<br>import org.jdom.input.SAXBuilder;<br>import org.jdom.output.Format;<br>import org.jdom.output.XMLOutputter;</p> <p>/**<br>* @author kingwong<br>*<br>* TODO To change the template for this generated type comment go to<br>* Window - Preferences - Java - Code Style - Code Templates<br>*/<br>public class TestJDOM2 {<br>public static void main(String[] args){<br>SAXBuilder sb = new SAXBuilder();<br>try<br>{ <br>Document doc = sb.build("myFile.xml");<br>Element root = doc.getRootElement();</p> <p>String str1 = root.getAttributeValue("comment");<br>System.out.println("Root Element's comment attribute is : " + str1);<br>String str2 = root.getChild("sex").getAttributeValue("value");<br>System.out.println("sex Element's value attribute is : " + str2);<br>String str3 = root.getChildText("name");<br>System.out.println("name Element's content is :" + str3);<br>String str4 = root.getChild("contact").getChildText("telephone");<br>System.out.println("contact Element's telephone subelement content is : " + str4 + "\n");<br>Element inputElement = root.getChild("contact"); <br>inputElement.addContent(new Element("email").setAttribute("value","wanghua@cyberobject.com"));</p> <p>XMLOutputter xmlOut = new XMLOutputter(Format.getPrettyFormat());<br>String outStr = xmlOut.outputString(root);<br>System.out.println(outStr);<br>}<br>catch(Exception e)<br>{<br>e.printStackTrace();<br>}<br>}<br>}</p> <p> </p> <p></font></p><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/126177.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-06-25 18:33 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/06/25/126177.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>GroovyQ?一个属于JAVAq_的动态开发语aQ与JAVA 的异?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/06/06/122454.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Wed, 06 Jun 2007 13:31:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/06/06/122454.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/122454.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/06/06/122454.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/122454.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/122454.html</trackback:ping><description><![CDATA[<div id="wmqeeuq" class=content style="PADDING-TOP: 3mm"> <p>Groovy tries to be as natural as possible for Java developers. We've tried to follow the principle of least surprise when designing Groovy, particularly for developers learning Groovy who've come from a Java background.</p> <p>Here we list all the major differences between Java and Groovy.</p> <div id="wmqeeuq" class=section_2> <h2><a name=DifferencesfromJava-Defaultimports></a>Default imports</h2> <p>All these packages and classes are imported by default, i.e. you do not have to use an explicit <tt>import</tt> statement to use them:</p> <ul> <li>java.io.* <li>java.lang.* <li>java.math.BigDecimal <li>java.math.BigInteger <li>java.net.* <li>java.util.* <li>groovy.lang.* <li>groovy.util.* </li> </ul> </div> <div id="wmqeeuq" class=section_2> <h2><a name=DifferencesfromJava-Commongotchas></a>Common gotchas</h2> <p>Here we list the common things you might trip over if you're a Java developer starting to use Groovy.</p> <ul> <li>== means equals on all types. In Java there's a wierd part of the syntax where == means equality for primitive types and == means identity for objects. Since we're using autoboxing this would be very confusing for Java developers (since x == 5 would be mostly false if x was 5 <img class=emoticon height=20 alt="" src="http://docs.codehaus.org/images/icons/emoticons/smile.gif" width=20 align=absMiddle border=0></img>. So for simplicity == means equals() in Groovy. If you really need the identity, you can use the method "is" like foo.is(bar). This does not work on null, but you can still use == here: foo==null. <li>in is a keyword. So don't use it as a variable name. <li>When declaring array you can't write <div id="wmqeeuq" class=code> <div id="wmqeeuq" class=codeContent> <pre class=code-java><span id="wmqeeuq" class=code-object><font color=#910091>int</font></span>[] a = {1,2,3};</pre> </div> </div> <p>you need to write</p> <div id="wmqeeuq" class=code> <div id="wmqeeuq" class=codeContent> <pre class=code-java><span id="wmqeeuq" class=code-object><font color=#910091>int</font></span>[] a = [1,2,3]</pre> </div> </div> <li>If you were used to write a for loop which looked like <div id="wmqeeuq" class=code> <div id="wmqeeuq" class=codeContent> <pre class=code-java><span id="wmqeeuq" class=code-keyword><font color=#000091>for</font></span> (<span id="wmqeeuq" class=code-object><font color=#910091>int</font></span> i =0; i < len; i++)</pre> </div> </div> <p>in groovy you need to write</p> <div id="wmqeeuq" class=code> <div id="wmqeeuq" class=codeContent> <pre class=code-java><span id="wmqeeuq" class=code-keyword><font color=#000091>for</font></span> (i in 0..len-1)</pre> </div> </div> <p>or</p> <div id="wmqeeuq" class=code> <div id="wmqeeuq" class=codeContent> <pre class=code-java><span id="wmqeeuq" class=code-keyword><font color=#000091>for</font></span> (i in 0..<len)</pre> </div> </div> </li> </ul> </div> <div id="wmqeeuq" class=section_2> <h2><a name=DifferencesfromJava-Thingstobeawareof></a>Things to be aware of</h2> <ul> <li>semicolon is optional. Use them if you like (though you must use them to put several statements on one line). <li>the return keyword is optional. <li>you can use the <em>this</em> keyword inside static methods (which refers to this class). <li>methods and classes are public by default. <li>protected in Groovy is the equivalent of both package-protected and protected in Java. i.e. you can have friends in the same package - or derived classes can also see protected members. <li>inner classes are not supported at the moment. In most cases you can use <a title=Closures ><font color=#2266cc>closures</font></a> instead. <li>the throws clause in method heads is not checked by the Groovy compiler, because there is no difference between checked and unchecked exceptions. </li> </ul> </div> <div id="wmqeeuq" class=section_2> <h2><a name=DifferencesfromJava-UncommonGotchas></a>Uncommon Gotchas</h2> <p>Java programmers are used to semicolons terminating statements and not having <a title=Closures ><font color=#2266cc>closures</font></a>. Also there are instance initializers in class definitions. So you might see something like:</p> <div id="wmqeeuq" class=code> <div id="wmqeeuq" class=codeContent> <pre class=code-java>class Trial { <span id="wmqeeuq" class=code-keyword><font color=#000091>private</font></span> <span id="wmqeeuq" class=code-keyword><font color=#000091>final</font></span> Thing thing = <span id="wmqeeuq" class=code-keyword><font color=#000091>new</font></span> Thing ( ) ; { thing.doSomething ( ) ; } }</pre> </div> </div> <p>Many Groovy programmers eschew the use of semicolons as distracting and redundant (though others use them all the time - it's a matter of coding style). A situation that leads to difficulties is writing the above in Groovy as:</p> <div id="wmqeeuq" class=code> <div id="wmqeeuq" class=codeContent> <pre class=code-java>class Trial { <span id="wmqeeuq" class=code-keyword><font color=#000091>private</font></span> <span id="wmqeeuq" class=code-keyword><font color=#000091>final</font></span> thing = <span id="wmqeeuq" class=code-keyword><font color=#000091>new</font></span> Thing ( ) { thing.doSomething ( ) } }</pre> </div> </div> <p>This will probably be a compile error!</p> <p>The issue here is that in this situation the newline is not a statement terminator so the following block is treated as a <a title=Closures ><font color=#2266cc>closures</font></a>that is a parameter to the Thing constructor. Bizarre to many, but true. If you want to use instance initializers in this sort of way, it is effectively mandatory to have a semicolon:</p> <div id="wmqeeuq" class=code> <div id="wmqeeuq" class=codeContent> <pre class=code-java>class Trial { <span id="wmqeeuq" class=code-keyword><font color=#000091>private</font></span> <span id="wmqeeuq" class=code-keyword><font color=#000091>final</font></span> thing = <span id="wmqeeuq" class=code-keyword><font color=#000091>new</font></span> Thing ( ) ; { thing.doSomething ( ) }</pre> </div> </div> <p>This way the block following the initialized definition is clearly an instance initializer.</p> </div> <div id="wmqeeuq" class=section_2> <h2><a name=DifferencesfromJava-NewfeaturesaddedtoGroovynotavailableinJava></a>New features added to Groovy not available in Java</h2> <ul> <li><span id="wmqeeuq" class=nobr><a ><font color=#2266cc>closures</font></a></span> <li>native <span id="wmqeeuq" class=nobr><a ><font color=#2266cc>syntax</font></a></span> for lists and maps </li> </ul> <ul> <li><span id="wmqeeuq" class=nobr><a ><font color=#2266cc>GroovyMarkup</font></a></span> and GPath support <li>native support for <span id="wmqeeuq" class=nobr><a ><font color=#2266cc>regular expressions</font></a></span> <li>polymorphic <span id="wmqeeuq" class=nobr><a ><font color=#2266cc>iteration</font></a></span> and powerful <span id="wmqeeuq" class=nobr><a ><font color=#2266cc>switch statement</font></a></span> </li> </ul> <ul> <li>dynamic and static typing is supported - so you can omit the type declarations on methods, fields and variables <li>you can embed expressions inside <span id="wmqeeuq" class=nobr><a ><font color=#2266cc>strings</font></a></span> <li>lots of new helper methods added to the <span id="wmqeeuq" class=nobr><a ><font color=#2266cc>JDK</font></a></span> <li>simpler syntax for writing <span id="wmqeeuq" class=nobr><a ><font color=#2266cc>beans</font></a></span> for both properties and adding event listeners </li> </ul> <ul> <li><span id="wmqeeuq" class=nobr><a ><font color=#2266cc>safe navigation</font></a></span>using the ?. operator, e.g. "variable?.field" and "variable?.method()" - no more nested ifs to check for null clogging up your code </li> </ul> </div> </div><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/122454.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-06-06 21:31 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/06/06/122454.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>生成一个java~制的可执行文g[1]http://www.aygfsteel.com/mlh123caoer/archive/2007/05/01/114944.html草儿草儿Tue, 01 May 2007 09:04:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/05/01/114944.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/114944.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/05/01/114944.html#Feedback0http://www.aygfsteel.com/mlh123caoer/comments/commentRss/114944.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/114944.htmljava~织?class后,如果只是用java 命o来执行总觉得不是太q瘾Q找个办法生成像exe文g一L鼠标双击便可执行的文Ӟ应该是很有趣的啊。本文主要介l了一U生成java可执行程序的Ҏ?

q里我用了一个名字叫做exe4j的免费小软gQ感觉不错。下面我我把java?class文g生成可执行文件的程讲一下?

首先Q将你要选择好你卛_发布?class文g׃用细说了Q下面是创徏jar文gQ这里我用一个名字叫做test.class的文件来举例Q另外注意还要编写一个确定main_class的文件manifest.mfQ在q里mainfest.mf和test.class是在同一个目录下Q然后用如下命?

jar cvfm test.jar manifest.mf test

q样Q一个test.jar文gq成了Q这里我׃l说jar的具体功能了。但Z保成功Q我们可以再用下面的指o执行一下刚刚生成的test.jarQ?

java -jar test.jar

怎么P是不是可以很利的进行?如果是,那我们就可以开始进行可执行文g的创Z?

下面打开exe4jQ它的开始一个界面是q样的:

http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-291439280.jpg
单击NEXT键,选择”JAR in EXE”mod按钮Q单击NEXTQ?

http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-291439282.jpg
出现下面画面Q填写短名和文g输出的\径然后点击NEXTl箋
http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-291439284.jpg
你又会看C面的画面Q在q里你可以选择你要生成的可执行文g的类型,以及生成的可执行文g名称、可执行文g的图标等Q我们在q里选择GUI applicationQ名字就Ҏ自己的需要取一个,图标你可以自己在你的图标库里选一个你喜欢的,然后再NEXT再l;

 

http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-291439286.jpg
下一个画面如下,在这里填写Main class的名字,单击下面的绿?选择所需?jar文g,如果没有Ҏ要求我们可以再l箋了;

 

http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-291439288.jpg
接下来是选择版本的画面,填写好自q最大最版本然后再l箋
http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-2914392810.jpg
下面q个画面可以帮助你设一下你的文件执行的片头Q增加其观效果Q选择自己喜欢的图片,写自己想写的文字Qƈ可以Ҏ需要调整文字的位置Q再l箋


http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-2914392812.jpg
下面是一个选择语言版本的界面选好后再l箋
http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-2914392814.jpg
下面是一个短暂的{待
http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-2914392816.jpg
然后大功告成了Q一个java写成的可执行文gpL成了
http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-2914392818.jpg
M下看看效果,q面而来的是自己讄的开头效果,感觉怎么?
http://dev.csdn.net/Develop/ArticleImages/21/21845/CSDN_Dev_Image_2003-10-2914392820.png



草儿 2007-05-01 17:04 发表评论
]]>
java 面试?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/03/09/102792.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Fri, 09 Mar 2007 04:56:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/03/09/102792.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/102792.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/03/09/102792.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/102792.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/102792.html</trackback:ping><description><![CDATA[     摘要: 一、Java基础知识1.Java有那些基本数据类型,String是不是基本数据类型,他们有何区别?.字符串的操作Q?写一个方法,实现字符串的反{Q如Q输入abcQ输出cba  写一个方法,实现字符串的替换Q如Q输入bbbwlirbbbQ输出bbbhhtccc?.数据cd之间的{换?如何数值型字符转换为数字(IntegerQDoubleQ?如何数字{换ؓ字符  如何取小数点前两位,q四...  <a href='http://www.aygfsteel.com/mlh123caoer/archive/2007/03/09/102792.html'>阅读全文</a><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/102792.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-03-09 12:56 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/03/09/102792.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Eclipse 快捷?指南http://www.aygfsteel.com/mlh123caoer/archive/2007/03/09/102790.html草儿草儿Fri, 09 Mar 2007 04:46:00 GMThttp://www.aygfsteel.com/mlh123caoer/archive/2007/03/09/102790.htmlhttp://www.aygfsteel.com/mlh123caoer/comments/102790.htmlhttp://www.aygfsteel.com/mlh123caoer/archive/2007/03/09/102790.html#Feedback0http://www.aygfsteel.com/mlh123caoer/comments/commentRss/102790.htmlhttp://www.aygfsteel.com/mlh123caoer/services/trackbacks/102790.html阅读全文

草儿 2007-03-09 12:46 发表评论
]]>
Set up an SQL realm with DB2 Express-C, Eclipse WTP, and WebSphere Application Server Community Edition V1.1Q?Q?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/01/12/93456.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Fri, 12 Jan 2007 07:33:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/01/12/93456.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/93456.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/01/12/93456.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/93456.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/93456.html</trackback:ping><description><![CDATA[<p> <span id="wmqeeuq" class="atitle">Conclusion</span> </p> <a name="conclusion"> <p>This tutorial showed you how to create an SQL realm and deploy a Web application that uses the realm. In this example, you used DB2 Express-C as the database and the Eclipse Web Tools Platform for the development environment to create an application and deploy it to WebSphere Application Server Community Edition for hosting the application.</p> <p> <a name="N1064E"> <b>Acknowledgements</b> </a> </p> <p>The author would like to thank Manu T. George (WebSphere Application Server Community Edition L3 Support) and Anitha Krishnasamy (WebSphere Application Server Community Edition Business Development) for reviewing this tutorial and providing their valuable comments.</p> <p> <span id="wmqeeuq" class="atitle"> <a name="download">Download</a> </span> </p> <p> </p> <table class="data-table-1" cellspacing="0" cellpadding="0" width="70%" border="0"> <tbody> <tr> <th>Description</th> <th>Name</th> <th align="right">Size</th> <th>Download method</th> </tr> <tr> <td class="tb-row">Sample code for this tutorial</td> <td nowrap="">sample-db2-realm.zip</td> <td nowrap="" align="right">28KB</td> <td nowrap=""> <a class="fbox" > <b> <font color="#002c99">HTTP</font> </b> </a> </td> </tr> </tbody> </table> <br /> <p> <a name="resources"> <span id="wmqeeuq" class="atitle">Resources</span> </a> </p> <p> <b>Learn</b> <br /> </p> <ul> <li> <a > <font color="#002c99">Kick-start your Java apps</font> </a> <br /> <br /> </li> <li> <a > <font color="#002c99">WebSphere Application Server Community Edition resources</font> </a> </li> </ul> <p> <br /> <b>Get products and technologies</b> <br /> </p> <ul> <li> <a > <font color="#002c99">Download WebSphere Application Server Community Edition V1.1</font> </a> <br /> <br /> </li> <li> <a > <font color="#002c99">Download DB2 Express-C</font> </a> <br /> <br /> </li> <li> <a > <font color="#002c99">Download Eclipse</font> </a> <br /> <br /> <p> <a name="author"> <span id="wmqeeuq" class="atitle">About the author</span> </a> </p> <table cellspacing="0" cellpadding="0" width="70%" border="0"> <tbody> <tr> <td colspan="3"> <img height="5" alt="" src="https://www.ibm.com/i/c.gif" width="100%" /> </td> </tr> <tr valign="top" align="left"> <td> <p> <img height="80" alt="" src="http://www.ibm.com/developerworks/i/p-kbalachandar.jpg" width="64" align="left" /> </p> </td> <td> <img height="5" alt="" src="https://www.ibm.com/i/c.gif" width="4" /> </td> <td width="100%"> <p> <b>Krishnakumar Balachandar</b> is a senior staff software engineer at IBM Software labs in Bangalore, India. He is part of the support team for Geronimo and WebSphere Community Edition. </p> </td> </tr> </tbody> </table> </li> </ul> </a><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/93456.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-01-12 15:33 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/01/12/93456.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Set up an SQL realm with DB2 Express-C, Eclipse WTP, and WebSphere Application Server Community Edition V1.1Q一Q?/title><link>http://www.aygfsteel.com/mlh123caoer/archive/2007/01/12/93407.html</link><dc:creator>草儿</dc:creator><author>草儿</author><pubDate>Fri, 12 Jan 2007 05:37:00 GMT</pubDate><guid>http://www.aygfsteel.com/mlh123caoer/archive/2007/01/12/93407.html</guid><wfw:comment>http://www.aygfsteel.com/mlh123caoer/comments/93407.html</wfw:comment><comments>http://www.aygfsteel.com/mlh123caoer/archive/2007/01/12/93407.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/mlh123caoer/comments/commentRss/93407.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/mlh123caoer/services/trackbacks/93407.html</trackback:ping><description><![CDATA[<p> <a > <font color="#5c81a7">Krishnakumar Balachandar</font> </a> (<a href="mailto:krishnakumarb@in.ibm.com?subject=Set up an SQL realm with DB2 Express-C, Eclipse WTP, and WebSphere Application Server Community Edition V1.1"><font color="#5c81a7">krishnakumarb@in.ibm.com</font></a>), Software Engineer, WebSphere Application Server Community Edition Support Team, IBM<br /></p> <p>20 Sep 2006</p> <blockquote>This tutorial shows you how to set up an SQL realm to implement database security for a Web application using the no-charge Java kick-start package.</blockquote> <!--START RESERVED FOR FUTURE USE INCLUDE FILES--> <script language="JavaScript" type="text/javascript"> <!-- if (document.referrer&&document.referrer!="") { // document.write(document.referrer); var q = document.referrer; var engine = q; var isG = engine.search(/google\.com/i); var searchTerms; //var searchTermsForDisplay; if (isG != -1) { var i = q.search(/q=/); var q2 = q.substring(i+2); var j = q2.search(/&/); j = (j == -1)?q2.length:j; searchTerms = q.substring(i+2,i+2+j); if (searchTerms.length != 0) { searchQuery(searchTerms); document.write("<div class="wmqeeuq" id=\"contents\"></div>"); } } } //--> </script> <!--END RESERVED FOR FUTURE USE INCLUDE FILES--> <p> <span id="wmqeeuq" class="atitle">Before you start</span> </p> <p>When implementing security in a Web application, a JAAS module is required to specifically handle user authentication and authorization. WebSphere Application Server Community Edition provides a SQL realm that can connect to a database for obtaining user credentials. In this tutorial, you will see how to set up tables for creating an SQL realm in DB2 Express-C, how to set up a development environment using the Eclipse Web Tooling Platform to create a Web application, and how to deploy the Web application to WebSphere Application Server Community Edition from Eclipse.</p> <p>All Web applications should employ some level of security for user authentication and authorization to verify a user’s identity and enable access to application functions that are applicable to the user's role.</p> <p>Web applications can use LDAP, database, file system, Kerberos, or other such systems to provide authentication and authorization. To access security data from the selected method or system, an SQL realm is set up by creating tables in a database and configuring a Java Authentication and Authorization Service (JAAS) module to access these tables from an application server. </p> <p>Figure 1 shows different components in WebSphere Application Server Community Edition (hereafter referred to as Community Edition) used to provide an SQL realm. The Web application uses an SQL realm that connects to the database using a pool or driver. The user credentials are stored in tables in the database and are fetched when calls are made using the JAAS SQL realm.</p> <br /> <a name="fig1"> <b>Figure 1. Components of an SQL realm</b> </a> <br /> <img height="236" alt="Figure 1. Components of an SQL realm" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure1.gif" width="474" /> <br /> <table cellspacing="0" cellpadding="0" width="40%" align="right" border="0"> <tbody> <tr> <td width="10"> <img height="1" alt="" src="https://www.ibm.com/i/c.gif" width="10" /> </td> <td> <table cellspacing="0" cellpadding="5" width="100%" border="1"> <tbody> <tr> <td bgcolor="#eeeeee">Java Authentication and Authorization Service (JAAS) is a set of APIs that enables Java applications to access authentication and access control services without being tied to the service it is using. Using JAAS, the Java application can plug into security mechanisms like LDAP, Kerberos, databases, and so on, providing a layer between our application and the security mechanism being used.</td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <p> <a name="N100BF"> <span id="wmqeeuq" class="smalltitle"> <strong> <font face="Arial">Setting up a database realm</font> </strong> </span> </a> </p> <p>Setting up a database realm involves performing these general steps: </p> <ul> <li>Create tables for users and groups in DB2 Express-C. </li> <li>Deploy a database pool in Community Edition, if the realm is going to use a pool to connect to the database. </li> <li>Deploy the SQL realm plan in Community Edition. </li> <li>Configure and deploy the Web application that uses the SQL realm. </li> </ul> <p> </p> <p>The remainder of this tutorial explains these tasks in detail.<br /></p> <p> <span id="wmqeeuq" class="atitle">Setting up a database</span> </p> <a name="setdb"> <p>In this section, you will see how to set up the database and database tables required for the SQL realm. You can create database and tables either by using the Control Center or by running an SQL script.</p> <p> <a name="N100EA"> <span id="wmqeeuq" class="smalltitle"> <strong> <font face="Arial">Using the Control Center</font> </strong> </span> </a> </p> <p> <a name="N100F1"> <strong>Create the database</strong> </a> </p> <ol> <li>In DB2 Express-C, open the Control Center. </li> <li>Right-click <b>All Databases</b>, then select <b>Create Database</b> => <b>Standard</b>. </li> <li>For Database name, enter <code>WASCE</code>. </li> <li>Click <b>Finish</b>. </li> </ol> <p>You just created a new database called WASCE and should see it listed under All Databases (Figure 2).</p> <p> <br /> <a name="fig2"> <b>Figure 2. New database created</b> </a> <br /> <img height="375" alt="Figure 2. New database created" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure2.jpg" width="500" /> <br /> <br /> </p> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td> <img height="1" alt="" src="https://www.ibm.com/i/v14/rules/blue_rule.gif" width="100%" /> </td> </tr> </tbody> </table> <table class="no-print" cellspacing="0" cellpadding="0" align="right"> <tbody> <tr align="right"> <td> <table cellspacing="0" cellpadding="0" border="0"> <tbody> <tr> <td valign="center"> <img height="16" alt="" src="https://www.ibm.com/i/v14/icons/u_bold.gif" width="16" border="0" /> <br /> </td> <td valign="top" align="right"> <a class="fbox" > <b> <font color="#996699" size="2">Back to top</font> </b> </a> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> <br /> <br /> <p> <a name="N10129"> <span id="wmqeeuq" class="smalltitle"> <strong> <font face="Arial">Create tables</font> </strong> </span> </a> </p> <p>Now, create the tables for users (USERS) and groups (GROUPS) in the new WASCE database: </p> <ol> <li>Under WASCE in the directory listing, right-click <b>Tables</b>, then select <b>Create</b>. </li> <li>For Table name, enter <code>USERS</code>, then click <b>Next</b>. </li> <li>Add a column: <ol type="a"><li>Select <b>Add</b> to add a column to the new table. </li><li>For Column name, enter <code>USERNAME</code>. </li><li>For Data type, select <b>VARCHAR</b>. </li><li>For Nullable or not, select <b>No</b>. </li><li>Click <b>Apply</b>. </li></ol></li> <li>Repeat step 3 to add an <code>EMAIL</code> column and a <code>PASSWORD</code> column to the USERS table, with the values shown in Figure 3. When finished, click <b>OK</b>. </li> <li>Repeat steps 1 through 4 to create a new <code>GROUPS</code> table with two columns: <code>GROUPNAME</code> and <code>USERNAME</code>. </li> <li>Click <b>Next => Next => Next</b> to get to the Define keys on new table panel. </li> <li>Select <b>Add Primary</b>. From the available columns, select which column is to be the primary key for each table: <ol type="a"><li>For the USERS table, select <b>USERNAME</b>, and for the GROUPS table, select <b>USERNAME/GROUPNAME </b>as the primary key. </li><li>For the GROUPS table, select <b>Add foreign => USERNAME</b>. Click the <b>></b> button to move it to foreign key. Select <b>USERNAME</b> as the primary key in the Parent table (Schema/Name - ADMINISTRATOR/USERS). </li></ol></li> <li>Click <b>Finish</b> and the table is created. </li> </ol> <p> </p> <p>Use the steps above and the schema definitions shown in Figures 3 and 4 to create the USERS and GROUPS tables. For the USERS table, USERNAME is the primary key. For the GROUPS table, GROUPNAME and USERNAME are primary keys, and USERNAME is a foreign key (referring to USERNAME in the USERS table). </p> <p> <br /> <a name="fig3"> <b>Figure 3. USERS schema</b> </a> <br /> <img height="375" alt="Figure 3. USERS schema" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure3.jpg" width="500" /> <br /> <br /> <a name="fig4"> <b>Figure 4. GROUPS schema</b> </a> <br /> <img height="375" alt="Figure 4. GROUPS schema" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure4.jpg" width="500" /> <br /> </p> <p>In the steps shown above, the USERS and GROUPS tables are created under the ADMINISTRATOR schema. Had you logged in as db2admin, the tables would be created under the DB2ADMIN schema.</p> <p> <a name="N101DB"> <b>Populate tables with values</b> </a> </p> <ol> <li>Select <b>WASCE => Tables => USERS</b>. </li> <li>Right-click on the <b>USERS</b> table, then select <b>Open => Add row</b>. </li> <li>Enter test values for each field in the database record, then select <b>Commit</b>. </li> <li>Repeat steps 2 and 3 for each test record you wish to create, then <b>Close</b>. </li> <li>Repeat steps 1 through 4 for the GROUPS table (Figure 5). </li> </ol> <p> <br /> <a name="fig5"> <b>Figure 5. Create test data records</b> </a> <br /> <img height="462" alt="Figure 5. Create test data records" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure5.jpg" width="500" /> <br /> </p> <p> <a name="N10212"> <b>Using scripts</b> </a> </p> <p>As an alternative to using the DB2 Control Center, you can create the database, tables, and test data using an SQL script. The download file included with this tutorial contains a sanmple script file, db2_realm.sql. Execute this script from DB2 command line to create the database and tables: </p> <ol> <li>Open a Windows command window or run the DB2 batch file <code>/<i><db2 install directory></i>bin/db2cw.bat</code>. </li> <li>Execute the sample script file with this command: <code>db2 -tvfdb2-realm.sql</code>. </li> </ol> <p> </p> <p>If there are no errors, success messages will be generated for the SQL (Figure 6).</p> <p> <br /> <a name="fig6"> <b>Figure 6. Create database, tables, and test data using script</b> </a> <br /> <img height="462" alt="Figure 6. Create database, tables, and test data using script" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure6.jpg" width="500" /> <br /> </p> <p> <span id="wmqeeuq" class="atitle">Creating the Web application</span> </p> <a name="webapp"> <p>In this section, you will use the Eclipse Web Tools Platform (WTP) to create a simple Web application. Before you begin with the application, though, you will need to define a new server in Eclipse (to which the new application will be deployed) and create a Java Runtime Environment (JRE). After that, you can use Eclipse WTP to create the application components (like the WAR and EAR files). The download file included with this tutorial contains a source EAR file of a sample application that you can import into Eclipse WTP.</p> <p> <a name="N10251"> <b>Define a new server</b> </a> </p> <p>To deploy an application, you need to define a server in Eclipse: </p> <ol> <li>In Eclipse, right-click the <b>Server</b> tab, and select <b>New Server</b> to open the New Server wizard (Figure 7). <br /><br /><a name="fig7"><b>Figure 7. Define new server</b></a><br /><img height="529" alt="Figure 7. Define new server" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure7.jpg" width="496" /><br /><br /></li> <li>Select <b>WebSphere Application Server Community v1.1 Server</b>, then press <b>Next.</b></li> <li>Enter values for all fields, as shown in Figure 8, then <b>Finish</b>. <br /><br /><a name="fig8"><b>Figure 8. New server parameters</b></a><br /><img height="329" alt="Figure 8. New server parameters" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure8.jpg" width="498" /><br /><br /></li> </ol> <p> </p> <p> <a name="N10294"> <b>Create a JRE</b> </a> </p> <p>To build application for supported Java Runtime Environment (JRE), in this case the IBM JRE, you need to configure the JRE in Eclipse WTP: </p> <ol> <li>In Eclipse, select <b>Window => Preferences</b>. </li> <li>Select <b>Java => Installed JREs</b>. </li> <li>Click <b>Add. . . </b></li> <li>On the Add JRE dialog, enter values for all fields, as shown in Figure 9. <br /><br /><a name="fig9"><b>Figure 9. Add JRE </b></a><br /><img height="375" alt="Figure 9. Add JRE" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure9.jpg" width="500" /><br /><br /></li> <li>Be sure this JRE is selected as the default JRE. </li> <li>Next, you need to make sure that the IBM JRE will run the new server that you created earlier. Right-click on the new server, then select <b>Open</b> (Figure 10). <br /><br /><a name="fig10"><b>Figure 10. Open new server</b></a><br /><img height="375" alt="Figure 10. Open new server" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure10.jpg" width="500" /><br /><br /></li> <li>Next to Runtime, select <b>Edit</b>. </li> <li>For JRE, select <b>IBM</b> (Figure 11), then <b>Finish.</b><br /><br /><a name="fig11"><b>Figure 11. Select IBM JRE </b></a><br /><img height="375" alt="Figure 11. Select IBM JRE " src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure11.jpg" width="500" /><br /><br /></li> </ol> <p> </p> <p> <a name="N102FB"> <b>Develop an application</b> </a> </p> <p>The Web application will contain pages for the application (in a WAR file) and will be added to an enterprise application (in an EAR file). For the purposes of this tutorial, you can either use an application you develop from scratch, or you can use the sample application included in the download file.</p> <p> <a name="N10305"> <b>Create a new application in Eclipse WTP</b> </a> </p> <ol> <li>Run Eclipse WTP either by double-clicking eclipse.exe from the location where you extracted the WTP platform, or by executing eclipse.exe from a command line. </li> <li>Select <b>File => New => Project => Web =>Dynamic Web Project</b>. </li> <li>On the Dynamic Web Project dialog, enter or select the following values: <ul><li>Project name: <code>SQLRealmWeb</code></li><li>Target runtime: <b>WebSphere Community Edition v1.1</b></li><li>EAR membership: <code>SQLRealmApp</code></li></ul></li> <li>If you need to create a WebSphere Application Server Community Edition V1.1 runtime option (Figure 12): <ol type="a"><li>Click the <b>New</b> button next to Target Runtime. </li><li>Select <b>WebSphere Application Server Community Edition v1.1</b>, then <b>Next</b>. </li><li>Select <b>IBM</b> for JRE, and browse to the appropriate Application Server Install Directory, then click <b>Finish</b>. <br /><br /><a name="fig12"><b>Figure 12. Create Community Edition runtime</b></a><br /><img height="375" alt="Figure 12. Create Community Edition runtime" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure12.jpg" width="500" /><br /><br /></li></ol></li> <li>Click <b>Next</b> on the next two panels. </li> <li>For Context Root, enter <code>/SQLRealmWeb</code>, then <b>Next</b>. </li> <li>Configure the Geronimo deployment plan by entering these values: <ul><li>Group ID: <code>wasce</code></li><li>Artifact ID: <code>sqlrealm</code></li><li>Version: <code>1.0</code></li><li>Artifact Type: WAR </li></ul></li> <li>Click <b>Finish</b> (Figure13). <br /><br /><a name="fig13"><b>Figure 13. Server setup complete</b></a><br /><img height="375" alt="Figure 13. Server setup complete" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure13.jpg" width="500" /><br /><br /></li> </ol> <p> <a name="N103A3"> <b>Import sample application into Eclipse WTP</b> </a> </p> <p>If you choose to import the sample project, the <a ><font color="#5c81a7">download file</font></a> included with this tutorial contains an EAR file you can import into the Eclipse WTP workspace: </p> <ol> <li>In Eclipse, select <b>File => Import => J2EE</b>. </li> <li>For Source File, enter <code>SQLRealmAppSrc</code>.ear, then click <b>Next</b>. </li> <li>Enter or select the following values: <ul><li>EAR Project: <code>SQLRealmApp</code></li><li>Web Project: <code>SQLRealmWeb</code></li><li>Target Runtime: <b>WebSphere Community Edition v1.1</b></li></ul></li> <li>If you need to create a WebSphere Application Server Community Edition V1.1 runtime option (Figure 12): <ol type="a"><li>Click the <b>New</b> button next to Target Runtime. </li><li>Select <b>WebSphere Application Server Community Edition v1.1</b>, then <b>Next</b>. </li><li>Select <b>IBM</b> for JRE, and browse to the appropriate Application Server Install Directory, then click <b>Finish</b>. </li></ol></li> <li>Click <b>Finish</b>. </li> </ol> <p> <span id="wmqeeuq" class="atitle">Deploying the application</span> </p> <a name="deploy"> <p>With the application created, you can deploy it to the Community Edition runtime environment. However, for the application to run, you need a database pool and realm plan:</p> <p> <a name="N10412"> <b>Deploy the database pool</b> </a> </p> <p>To connect to DB2, you need a database pool, which you can create by deploying a database pool plan with the wizard that is available from the Community Edition administrative console: </p> <ol> <li>Logon to the Community Edition administrative console by starting the server. To start the server, right-click on the new server you created above, and select <b>Start</b>. Once the server is started, the status changes to green and shows "Started". You can now launch the console by right-clicking on the started server and selecting <b>Launch Community Edition Console</b>. Enter your username and password as <code>system</code> and <code>manager</code>. </li> <li>Under Services, select <b>Database Pools</b> => <b>Using Geronimo PoolsWizard</b>. </li> <li>For Database Pools, enter <code>Db2Realm</code>, then <b>Next</b>. </li> <li>On the Select Driver, JAR, Parameters panel, enter or select the values shown for all fields in Figure 14. When finished, click <b>Next</b>. <br /><br /><a name="fig14"><b>Figure 14. Enter database pool parameters</b></a><br /><img height="349" alt="Figure 14. Enter database pool parameters" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure14.jpg" width="500" /><br /><br /></li> <li>Test the connection for errors by selecting <b>Test connection</b>. If there are no errors, you will see the message: <code>Test Result: Connected to DB2/NT SQL09000 in the console.</code></li> <li>Once you deploy the pool, it is started and running (Figure 15). <br /><br /><a name="fig15"><b>Figure 15. Database pool deployed</b></a><br /><img height="375" alt="Figure 15. Database pool deployed" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure15.jpg" width="500" /><br /><br /></li> </ol> <p> </p> <p> <a name="N10474"> <b>Deploy the realm plan</b> </a> </p> <p>Community Edition connects to SQL databases using JAAS, by default, to provide an SQL realm to applications deployed in the server. You can make this connection by using a JDBC driver that connects directly to the database, or by using a database pool that gets a connection from a pool to connect to the database.</p> <p>The realm plan (see <a ><font color="#996699">Listings 1</font></a> and <a ><font color="#996699">2</font></a>) is used to deploy an SQL realm that connects to the database. The realm plan contains Geronimo GBeans required to create an SQL realm. The GBean "sql-login" has attributes that you use to specify the realm type, <code>loginModuleClass = org.apache.geronimo.security.realm.providers.SQLLoginModule</code>, and options where you specify the JDBC properties required to connect to the database. You can use this plan to connect to any JDBC database. For this exercise, you can specify either the JDBC driver or the DataSource name to connect to the database.</p> <p> <a name="N1048D"> <b>Using the JDBC driver</b> </a> </p> <p>Listing 1 shows an SQL realm plan that uses the JDBC driver to connect to database. The plan is contained in the download file as sqlplan.xml. In the statements that are bold in Listing 1, replace ADMINISTRATORS with the schema name in which the tables have been created.</p> <p> <br /> <a name="listing1"> <b>Listing 1. SQL realm plan using JDBC driver</b> </a> <br /> </p> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"> <pre class="displaycode"> <module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1"> <environment> <moduleId> <groupId>db2</groupId> <artifactId>realm</artifactId> <version>1.0</version> <type>car</type> </moduleId> <dependencies> <dependency> <groupId>geronimo</groupId> <artifactId>j2ee-security</artifactId> <version>1.1</version> <type>car</type> </dependency> <dependency> <groupId>console.dbpool</groupId> <artifactId>DB2Realm</artifactId> <version>1.0</version> <type>rar</type> </dependency> </dependencies> <hidden-classes/> <non-overridable-classes/> </environment> <gbean name="sql-login" class="org.apache.geronimo.security.jaas.LoginModuleGBean"> <attribute name="loginModuleClass">org.apache.geronimo. security.realm.providers.SQLLoginModule</attribute> <attribute name="serverSide">true</attribute> <attribute name="options">jdbcUser=db2admin jdbcPassword=db2admin jdbcURL=jdbc:db2:WASCE jdbcDriver=com.ibm.db2.jcc.DB2Driver userSelect=select username, password from ADMINISTRATOR.USERS groupSelect=select groupname, username from ADMINISTRATOR.GROUPS</attribute> <attribute name="loginDomainName">sql-realm</attribute> </gbean> <gbean name="sql-realm" class="org.apache.geronimo.security.realm.GenericSecurityRealm"> <attribute name="realmName">sql-realm</attribute> <reference name="LoginModuleConfiguration"> <name>sql-login</name> </reference> <reference name="ServerInfo"> <name>ServerInfo</name> </reference> <!--Add--> <reference name="LoginService"> <name>JaasLoginService</name> </reference> </gbean> <gbean name="sql-login" class="org.apache.geronimo.security.jaas.JaasLoginModuleUse"> <attribute name="controlFlag">REQUIRED</attribute> <reference name="LoginModule"> <name>sql-login</name> </reference> </gbean> <gbean name="sqltest" class="org.apache.geronimo.security.jaas.ServerRealmConfigurationEntry"> <attribute name="applicationConfigName">sqltest</attribute> <attribute name="realmName">sql-realm</attribute> <reference name="LoginService"> <name>JaasLoginService</name> </reference> </gbean> </module></pre> </td> </tr> </tbody> </table> <br /> <p> <a name="N104A4"> <b>Using database pool</b> </a> </p> <p>Listing 2 shows an SQL realm plan that uses a database pool (DB2Realm) that was deployed using the console wizard. The plan is contained in the <a ><font color="#5c81a7">download file</font></a> as sqlpoolplan.xml.</p> <p> <br /> <a name="listing2"> <b>Listing 2. SQL realm plan using database pool</b> </a> <br /> </p> <table cellspacing="0" cellpadding="0" width="100%" border="0"> <tbody> <tr> <td class="code-outline"> <pre class="displaycode"> <module xmlns="http://geronimo.apache.org/xml/ns/deployment-1.1"> <environment> <moduleId> <groupId>db2</groupId> <artifactId>pool-realm</artifactId> <version>1.0</version> <type>car</type> </moduleId> <dependencies> <dependency> <groupId>geronimo</groupId> <artifactId>j2ee-security</artifactId> <version>1.1</version> <type>car</type> </dependency> <dependency> <groupId>console.dbpool</groupId> <artifactId>DB2Realm</artifactId> <version>1.0</version> <type>rar</type> </dependency> </dependencies> <hidden-classes/> <non-overridable-classes/> </environment> <gbean name="sqlpool-login" class="org.apache.geronimo.security.jaas.LoginModuleGBean"> <attribute name="loginModuleClass">org.apache.geronimo.security.realm. providers.SQLLoginModule</attribute> <attribute name="serverSide">true</attribute> <attribute name="options"> userSelect=select username, password from ADMINISTRATOR.USERS groupSelect=select groupname, username from ADMINISTRATOR.GROUPS dataSourceName=DB2Realm</attribute> <attribute name="loginDomainName">sqlpool-realm</attribute> </gbean> <gbean name="sqlpool-realm" class="org.apache.geronimo.security.realm.GenericSecurityRealm"> <attribute name="realmName">sqlpool-realm</attribute> <reference name="LoginModuleConfiguration"> <name>sqlpool-login</name> </reference> <reference name="ServerInfo"> <name>ServerInfo</name> </reference> <!--Add--> <reference name="LoginService"> <name>JaasLoginService</name> </reference> </gbean> <gbean name="sqlpool-login" class="org.apache.geronimo.security.jaas.JaasLoginModuleUse"> <attribute name="controlFlag">REQUIRED</attribute> <reference name="LoginModule"> <name>sqlpool-login</name> </reference> </gbean> <gbean name="sqlpooltest" class="org.apache.geronimo.security.jaas.ServerRealmConfigurationEntry"> <attribute name="applicationConfigName">sqlpooltest</attribute></pre> </td> </tr> </tbody> </table> <br /> <p> <a name="N104BF"> <b>Deploy the realm</b> </a> </p> <p>You can deploy the realms to the server using the administrative console: </p> <ol> <li>Start the Community Edition server from Eclipse WTP. In Eclipse, select the server you created earlier by right-clicking on the <b>Server</b> tab, then select <b>Start</b> (Figure 16). <br /><br /><a name="fig16"><b>Figure 16. Start server</b></a><br /><img height="375" alt="Figure 16. Start server" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure16.jpg" width="500" /><br /><br /></li> <li>Login to the Community Edition administrative console. </li> <li>Deploy the SQL realm plan that uses JDBC Driver (sqlplan.xml shown in <a ><font color="#996699">Listing 1</font></a>) by selecting <b>Deploy New</b> on the console (Figure 17). <br /><br /><a name="fig17"><b>Figure 17. Deploy database realm</b></a><br /><img height="375" alt="Figure 17. Deploy database realm" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure17.jpg" width="500" /><br /><br /></li> <li>Deploy the SQL database realm plan that uses the database pool (sqlpoolplan.xml shown in Listing 2). </li> <li>Check to see that these two plans are deployed successfully by selecting <b>Systems Modules</b> under Applications in the console (Figure 18). <br /><br /><a name="fig18"><b>Figure 18. Check successful real deployment</b></a><br /><img height="375" alt="Figure 18. Check successful real deployment" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure18.jpg" width="500" /><br /><br /></li> </ol> <p> </p> <p> <a name="N10518"> <b>Deploy the application</b> </a> </p> <p>With the application and server configuration defined in Eclipse, and the database realm deployed, you can now deploy the application to the server. </p> <ol> <li>In Community Edition, select <b>Server</b> tab, right-click on the server you created earlier, and then select <b>Add and Remove Projects</b>. </li> <li>Select the <b>SQLRealmApp</b> from the Available projects list and click Add > to move it over to the Configured projects list (Figure 19). </li> <li>Click <b>Finish</b>. <br /><br /><a name="fig19"><b>Figure 19. Add to configured projects</b></a><br /><img height="374" alt="Figure 19. Add to configured projects" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure19.jpg" width="477" /><br /><br /></li> <li>Start the server. From the <b>Server</b> tab, right-click again on your server and select <b>Start</b>. The application will run on the server you selected. </li> <li>To launch the console for the server, right-click on the Community Edition server, then select <b>Launch Community Edition Console</b>. Enter the login ID and password: <code>system</code> and <code>manager</code>, respectively (Figure 20). <br /><br /><a name="fig20"><b>Figure 20. Launch administrative consoles</b></a><br /><img height="375" alt="Figure 20. Launch administrative console" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure20.jpg" width="500" /> <br /><p><span id="wmqeeuq" class="atitle">Running the application</span></p><a name="runapp"><p>In the prior sections, you created and deployed the Web application to the server from Eclipse WTP. Next, you can use the application, following the instructions in this section to test authentication, authorization, and access to the database pool. The application referred to in this section is the sample application provided in the <a ><font color="#5c81a7">download file</font></a>.</p><p><a name="N10582"><b>Access the application</b></a></p><p>To access the Web application: </p><ol><li>From the Eclipse Navigator, right-click the Web application <b>SQLRealmWeb</b>, then select <b>Run As => Run on Server</b>. </li><li>Select <b>WebSphere Application Server Community Edition 1.1</b>, which is the server you defined earlier. </li><li>The project should already be added. Select <b>Next</b> and <b>Finish</b>. </li><li>The application should now be available at http://localhost:8080/SQLRealmWeb/ (Figure 21). <br /><br /><a name="fig21"><b>Figure 21. Test the application</b></a><br /><img height="375" alt="Figure 21. Test the application" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure21.jpg" width="500" /><br /><br /></li></ol><p></p><p><a name="N105B9"><b>Test the authentication</b></a></p><p>Included with this sample application are several valid user ID and password combinations (for testing authentication) with different roles (for testing authorization). Test the authentication by logging in. Using a correct user ID and password will log you in. An incorrect user ID and password will display the error page shown in Figure 22.</p><p>Valid user ID/password values are as follows:</p><p><code>system/manager<br />admin/admin123<br />user1/user1123<br />user2/user2123<br />guest1/guest1123<br />guest2/guest2123</code></p><br /><a name="fig22"><b>Figure 22. Application error page</b></a><br /><img height="375" alt="Figure 22. Application error page" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure22.jpg" width="500" /><br /><p><a name="N105E6"><b>Test authorization</b></a></p><p>Once authenticated and inside the application, the user is allowed access to areas of Web application based on the user's business role, as defined in the deployment descriptor. The sample application is defined with three roles: admin, user, and guest. A user with an admin role has access to all accounts in the sample application, but a user with a guest role will only be able to access pages defined for the guest. Test this by entering the application with different user IDs and passwords with admin, user, and guest roles. Figure 23 shows a user logged in as admin, but who is able to view the guest pages.</p><br /><a name="fig23"><b>Figure 23. Admin user viewing Guest page</b></a><br /><img height="375" alt="Figure 23. Admin user viewing Guest page" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure23.jpg" width="500" /><br /><p>In the case of unauthorized access (for example, if a guest user attempts to access a page authorized for admin users only), an HTTP 403 status error occurs (Figure 24) and prevents access to the page.</p><br /><a name="fig24"><b>Figure 24. Authorization error</b></a><br /><img height="375" alt="Figure 24. Authorization error" src="https://www6.software.ibm.com/developerworks/education/websphere/0609_balachandar/images/figure24.jpg" width="500" /><br /><p><a name="N10611"><b>Using the database pool</b></a></p><p>The default Web application is configured to use SQL realm that uses the JDBC driver. You can change this so that it uses the database pool by changing the realm name in the geronimo-web.xml file as <code><security-realm-name>sqlpool-realm</security-realm-name></code>, and republishing the server. Verify if this works by stopping the db2/realm/1.0/car configuration in the server.</p><p><a name="N1061F"><b>Contents of the download file</b></a></p><p>The download file included with this tutorial, <a ><font color="#5c81a7">sample-db2-realm.zip</font></a>, contains the following files: </p><ul><li>db2-realm.sql - SQL script file to create database and tables </li><li>db2-plan.xml - Plan to deploy a DB2 database pool. </li><li>sqlplan.xml - SQL realm plan that uses JDBC driver. </li><li>sqlpoolplan.xml - SQL realm plan that uses a database pool. </li><li>SQLRealmAppSrc.ear - Source for sample Web application. </li></ul></a></li> </ol> </a> </a> </a><img src ="http://www.aygfsteel.com/mlh123caoer/aggbug/93407.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/mlh123caoer/" target="_blank">草儿</a> 2007-01-12 13:37 <a href="http://www.aygfsteel.com/mlh123caoer/archive/2007/01/12/93407.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">ʩ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ͷ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ַ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʯ</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank">ƽ½</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʡ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʷ</a>| <a href="http://" target="_blank">᯹</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʮ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ζ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>