﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-beyond duke!-随笔分类-编程随笔</title><link>http://www.blogjava.net/beyondduke/category/4174.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 12 Mar 2008 13:00:14 GMT</lastBuildDate><pubDate>Wed, 12 Mar 2008 13:00:14 GMT</pubDate><ttl>60</ttl><item><title>初学flex</title><link>http://www.blogjava.net/beyondduke/archive/2008/03/12/185689.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Wed, 12 Mar 2008 06:28:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2008/03/12/185689.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/185689.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2008/03/12/185689.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/185689.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/185689.html</trackback:ping><description><![CDATA[<p>&nbsp;&nbsp;&nbsp;&nbsp; 上大学的时候，看到好多精彩炫丽的flash，学习了一些flash的知识。那个时候不怎么会写脚本，就用动画的概念一帧一帧的拼出一个flash。后来工作以后，给客户在线演示产品，有接触了Captivate。2006年末的时候，客户要求开发一个在线产品展示平台，我偶然搜到了adobe用flex开发的网上购物演示，就体会到如果用flex来实现这个产品展示平台将是很动人的事情，由于某种原因最终未能如愿。最近在做一个通用视频培训平台时又用到了FLV播放器，也是用Flex开发的，最终效果和土豆、优酷非常类似。这些场景使我对flash的展现效果情有独钟，况且有adobe这样的公司在运作flash，如果可能的话应该在合适的场合来把flex集成到我们现在开发的应用中，比如图表功能、表单功能、打印功能等等。基于以上的经历和思路，决定花功夫学习一下flex还是值得的。<br />
&nbsp;&nbsp;&nbsp; 首先，到adobe官方网站下载flex builder 3（当前最新版本）并安装。安装完毕后会看到一些入门文章中提到的Flex SDK已经在builder中存在了，所以初学仅下载个builder就够了。<br />
&nbsp;&nbsp;&nbsp; 然后，打开builder发现它就是基于eclipse开发的，我想这个IDE对于大多数java开发着再熟悉不过了。首次进入时会有一个欢迎界面和初学者向导，我比较习惯看看这些东西，点击下载提供的入门工程Flex3GSEIII_a_WorkingWithData_JSP，并导入builder中。看看工程结构跟我们平时的JAVAEE工程有了一些不同。多了bin-debug和html-template文件夹，文件类型主要是*.mxml、*.as。在工程的左侧视图右键*.mxml运行（类似与运行java文件），会有一个编译过程，过后弹出一个html，html中运行的正式flash。当时比较好奇，一个mxml是如何经过编译产生html和flash的，打开刚才提到的bin-debug发现两个文件生成到了这个文件夹。仔细读一下mxml的代码发现跟XHTML基本类似，其中的一些function都是AS写的。至此我分析得到如下结论：mxml+as--&gt;swf,中间的转换是adobe集成在builder中的转换工具完成的。如此跟我们以往HTML+JS的编程习惯很类似了，并且XHTML与AS的结合更紧密一些。由于初学原理性的知识我就理解至此了。<br />
&nbsp;&nbsp; 最后，我们关心的是用flex都能实现哪些控件，并且控件的效果如何。我没有迫不及待的去google，而是又深入到builder的安装目录下，在D:\Flex Builder 3\sdks\3.0.0发现了好东西，别的我不关心，先看samples，子目录下有一个explorer，其中包含一个build.bat。看到这个bat我更加确定了我以上的结论。于是运行bat，开始编译其下的mxml文件逐一生成swf文件。花一段时间生成完毕，打开类似于index的swf文件，sdk中提供的样例控件就都尽收眼底了。<br />
&nbsp;&nbsp; 后续：有源文件，有开发工具，你可以随意摆弄这些代码，熟悉语法，熟悉开发环境，熟悉对象属性，拼拼凑凑完成自己的一个组合界面了。</p>
<img src ="http://www.blogjava.net/beyondduke/aggbug/185689.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2008-03-12 14:28 <a href="http://www.blogjava.net/beyondduke/archive/2008/03/12/185689.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数据库常见的三种join方式（收藏）</title><link>http://www.blogjava.net/beyondduke/archive/2006/05/18/46745.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Thu, 18 May 2006 01:43:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2006/05/18/46745.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/46745.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2006/05/18/46745.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/46745.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/46745.html</trackback:ping><description><![CDATA[
		<p>数据库常见的join方式有三种：inner join, left outter join, right outter join(还有一种full join，因不常用，本文不讨论)。这三种连接方式都是将两个以上的表通过on条件语句，拼成一个大表。以下是它们的共同点：</p>
		<p>  1. 关于左右表的概念。左表指的是在SQL语句中排在left join左边的表，右表指的是排在left join右边的表。<br />  2. 在拼成的大表中，左表排在左边，右表排在右边。<br />  3. on条件语句最好用=号对两表相应的主外键进行连接。当然，也可以用其他操作符，如&gt;, &lt;, 来连接两表的任一字段，此时的关系将非常复杂，连接后的记录数也随之而变得不确定。如果在一些特殊的场合中需要用到这种方式，必须通过简单的实例加以确认，否则，连接结果很可能不是我们所想要的！<br />  4. on条件语句不能省略。<br />  5. 可以连锁使用join，每次使用join都令另一表与当前的表或连接的结果相连接。</p>
		<p>
				<br />在下文中，用到了两个表，"部门"表与"组织"表，其中，"部门"表有一名为"组织编号"的外键，指向"组织"表中的主键"编号"。</p>
		<p>
				<strong>
						<font size="4">inner join</font>
				</strong>
		</p>
		<p>  格式：select * from 部门 inner join 组织 on 部门.组织编号 = 组织.编号</p>
		<p>  目的：将两表中符合on条件的所有记录都找出来。</p>
		<p>  规律：</p>
		<p>    1. 拼出的大表记录不会增加。<br />    2. 如果左边与右表的关系是一对多的关系，在选出的任一记录中，假若右表有多个记录与其对应，那么，连接后的左表，主键将不再唯一。</p>
		<p>  典型应用：将存在多关系的引用表放在左表，将存在一关系的被引用表放在右表，通过=号将主外键进行连接，通过对右表设定过滤条件，选出相应的且主键唯一的左表记录。</p>
		<p>  备注：inner join 是默认的连接方式，可缩写为join。</p>
		<p>  转化为where子句：</p>
		<p>    select * from 部门, 组织 where 部门.组织编号 = 组织.编号</p>
		<p> </p>
		<p>
				<strong>
						<font size="4">left outter join</font>
				</strong>
		</p>
		<p>  格式: select * from 部门 left join 组织 on 部门.组织编号 = 组织.编号</p>
		<p>  格式: select * from 组织 left join 部门 on 组织.编号 = 部门.组织编号</p>
		<p>  目的：将左表的所有记录列出，右表中只要符合on条件的，与左表记录相拼合，不符合条件的，填以null值。</p>
		<p>  规律：</p>
		<p>    1. 选出所有符合条件的左表，如果左边与右表的关系是一对一的关系，则拼成的大表记录不会改变。<br />       如果左边与右表的关系是多对一的关系，则拼成的大表记录也不会改变。<br />       如果左边与右表的关系是一对多的关系，则拼成的大表记录会增加。对于每一具有一对多关系的左表记录，如果左表1：N与右表对应，那么会多出N-1条记录。例如，如果左表第一条记录1：3对应于右表，多出2条记录。如果左表第二条记录1：2对应于右表，则再多出1条记录。这样，总共多出3条记录。其他类推。<br />    2. 如果左边与右表的关系是一对多的关系，在选出的任一记录中，假若右表有多个记录与其对应，那么，连接后的左表，主键将不再唯一。<br />    3. 如果左边与右表的关系是一对多的关系，对于左表任一记录，如果右表没有记录与其相对应，则全部填以null值。</p>
		<p>  典型应用：将存在多关系的引用表放在左表，将存在一关系的被引用表放在右表，通过对右表设定过滤条件，选出相应的且主键唯一的左表记录。</p>
		<p>  备注：left outter join可用left join代替。在有些数据库中，如HSqlDb, 只能使用left join而不能使用left outter join。</p>
		<p>  转化为where子句：</p>
		<p>    select * from 部门, 组织 where 部门.组织编号 = 组织.编号</p>
		<p>
				<br />
				<strong>
						<font size="4">right outter join</font>
				</strong>
		</p>
		<p>  格式: select * from 部门 right join 组织 on 部门.组织编号 = 组织.编号</p>
		<p>  格式: select * from 组织 right join 部门 on 部门.组织编号 = 组织.编号</p>
		<p>  目的：将右表的所有记录列出，左表中只要符合on条件的，与右表记录相拼合，不符合条件的，填以null值。</p>
		<p>  规律：(与left outter join相反)</p>
		<p>  典型应用：可转化成left outter join。例如</p>
		<p>    select * from 组织 right join 部门 on 部门.组织编号 = 组织.编号<br />    与<br />    select * from 部门 left join 组织 on 部门.组织编号 = 组织.编号<br />    的效果一样</p>
		<p>  备注：right outter join可用right join代替。在有些数据库中，如HSqlDb, 没有实现right join功能。</p>
		<p>  转化为where子句：</p>
		<p>    select * from 部门, 组织 where 部门.组织编号 = 组织.编号</p>
<img src ="http://www.blogjava.net/beyondduke/aggbug/46745.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2006-05-18 09:43 <a href="http://www.blogjava.net/beyondduke/archive/2006/05/18/46745.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>递归小程序</title><link>http://www.blogjava.net/beyondduke/archive/2006/03/29/37965.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Wed, 29 Mar 2006 01:31:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2006/03/29/37965.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/37965.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2006/03/29/37965.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/37965.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/37965.html</trackback:ping><description><![CDATA[递归<img src ="http://www.blogjava.net/beyondduke/aggbug/37965.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2006-03-29 09:31 <a href="http://www.blogjava.net/beyondduke/archive/2006/03/29/37965.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>程序员的方向</title><link>http://www.blogjava.net/beyondduke/archive/2006/03/25/37317.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Sat, 25 Mar 2006 03:21:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2006/03/25/37317.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/37317.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2006/03/25/37317.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/37317.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/37317.html</trackback:ping><description><![CDATA[转眼做程序已经1年半了，现在的工作似乎很不可思议，自己也搞不清是否真正属于一个程序员。每天面对msn上几十个客户（大多数都是程序员），忙得不亦乐乎，总是不断的switch workspace，客户的问题你要能重现才行。也许这也是一种锻炼吧，需要十足的耐心，千万不能浮躁，一旦出现问题还要不断的debug！<img src ="http://www.blogjava.net/beyondduke/aggbug/37317.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2006-03-25 11:21 <a href="http://www.blogjava.net/beyondduke/archive/2006/03/25/37317.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>linux 下配置java环境（jdk和tomcat)</title><link>http://www.blogjava.net/beyondduke/archive/2006/02/14/30573.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Tue, 14 Feb 2006 04:34:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2006/02/14/30573.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/30573.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2006/02/14/30573.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/30573.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/30573.html</trackback:ping><description><![CDATA[<P><STRONG><FONT size=4>JDK的配置：</FONT></STRONG><BR><BR>&nbsp;&nbsp;&nbsp; 1,&nbsp; 下载j2sdk-linux-i386-rpm.bin<BR>&nbsp;&nbsp; &nbsp;2，运行命令：<FONT style="BACKGROUND-COLOR: #d3d3d3" color=#0000ff>chmod +x j2sdk-linux-i386-rpm.bin&nbsp;&nbsp;&nbsp;&nbsp; <FONT style="BACKGROUND-COLOR: #ffffff" color=#000000>（修改成可执行权限）<BR></FONT></FONT>&nbsp; &nbsp; 3，执行<FONT style="BACKGROUND-COLOR: #d3d3d3" color=#0000ff>：./ j2sdk-1_3_1-linux-i386-rpm.bin&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT style="BACKGROUND-COLOR: #ffffff" color=#000000>(执行后生成rpm安装包j2sdk-linux-i386.rpm)</FONT></FONT><BR>&nbsp; &nbsp; 4，<FONT style="BACKGROUND-COLOR: #d3d3d3" color=#0000ff>rpm -ivh j2sdk-1_3_1-linux-i386-rpm&nbsp;&nbsp;&nbsp;&nbsp;<FONT style="BACKGROUND-COLOR: #ffffff"> (<FONT color=#000000>安装成功后，jdk将被安装在/usr/java/目录下)<BR>&nbsp;&nbsp;&nbsp; 5,&nbsp;&nbsp; vi当前用户（例root目录下）的.bash_profile文件，添加内容如下：</P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=3><SPAN style="COLOR: #008080">1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">export&nbsp;JAVA_HOME</SPAN><SPAN style="COLOR: #000000">=/</SPAN><SPAN style="COLOR: #000000">usr</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">java</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">j2sdk1</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #800000">4</SPAN><SPAN style="COLOR: #000000">.</SPAN></FONT><FONT size=3><SPAN style="COLOR: #000000">2_10<BR></SPAN><SPAN style="COLOR: #008080">2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>export&nbsp;CLASSPATH</SPAN><SPAN style="COLOR: #000000">=.:</SPAN><SPAN style="COLOR: #800080">$JAVA_HOME</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">lib</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">dt</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #000000">jar</SPAN><SPAN style="COLOR: #000000">:</SPAN><SPAN style="COLOR: #800080">$JAVA_HOME</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">lib</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">tools</SPAN><SPAN style="COLOR: #000000">.</SPAN></FONT><FONT size=3><SPAN style="COLOR: #000000">jar<BR></SPAN><SPAN style="COLOR: #008080">3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>export&nbsp;PATH</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #800080">$PATH</SPAN><SPAN style="COLOR: #000000">:</SPAN><SPAN style="COLOR: #800080">$JAVA_HOME</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">bin</SPAN></FONT></DIV>
<P></FONT></FONT></FONT><FONT style="BACKGROUND-COLOR: #d3d3d3" color=#0000ff><FONT style="BACKGROUND-COLOR: #ffffff"><FONT color=#000000>&nbsp;&nbsp; &nbsp; 6，java命令，验证环境是否配置成功。<BR><BR><STRONG>TOMCAT的配置：<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR></STRONG>&nbsp;&nbsp;&nbsp;&nbsp; 1，下载jakarta-tomcat-5.0.28.tar.gz<BR>&nbsp;&nbsp;&nbsp;&nbsp; 2， <FONT style="BACKGROUND-COLOR: #d3d3d3" color=#0000ff>tar zxvf jakarta-tomcat.tar.gz<BR></FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3， 转换路径cd到tomcat/bin目录下<FONT style="BACKGROUND-COLOR: #d3d3d3" color=#0000ff>：./startup.sh</FONT> (启动tomcat)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4， 在ie浏览器输入<A href="http://servername:port">http://servername:port</A>&nbsp;&nbsp; （验证tomcat是否启动成功）<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;<BR></P></FONT></FONT></FONT><img src ="http://www.blogjava.net/beyondduke/aggbug/30573.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2006-02-14 12:34 <a href="http://www.blogjava.net/beyondduke/archive/2006/02/14/30573.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JDBC实现oracle blob 出库入库</title><link>http://www.blogjava.net/beyondduke/archive/2006/02/14/30542.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Tue, 14 Feb 2006 01:23:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2006/02/14/30542.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/30542.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2006/02/14/30542.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/30542.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/30542.html</trackback:ping><description><![CDATA[1，首先建一个足够简单的表imageTable<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;varchar（20）<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; image&nbsp;&nbsp; blob<BR>2，blob入库<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;拷贝Sunset.jpg图片在C盘根目录下&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <SPAN style="COLOR: #000000">DriverManager.registerDriver(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;oracle.jdbc.driver.OracleDriver());&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connection&nbsp;conn&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;DriverManager.getConnection(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">jdbc:oracle:thin:@localhost:1521:beyondduke</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">duke</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">duke</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.setAutoCommit(</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BLOB&nbsp;blob&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PreparedStatement&nbsp;pstmt&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;conn.prepareStatement(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">insert&nbsp;into&nbsp;imageTable(id,image)&nbsp;values(?,empty_blob())</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt.setString(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">10001</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt.executeUpdate();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt.close();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;conn.prepareStatement(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">select&nbsp;content&nbsp;from&nbsp;imageTable&nbsp;where&nbsp;id=&nbsp;?&nbsp;for&nbsp;update</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt.setString(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">10001</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ResultSet&nbsp;rs&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;pstmt.executeQuery();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(rs.next())&nbsp;blob&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(BLOB)&nbsp;rs.getBlob(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String&nbsp;fileName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">c://Sunset.jpg</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File&nbsp;f&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;File(fileName);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileInputStream&nbsp;fin&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;FileInputStream(f);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">file&nbsp;size&nbsp;=&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;fin.available());&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;conn.prepareStatement(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">update&nbsp;imageTable&nbsp;set&nbsp;image=?&nbsp;where&nbsp;id=?</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OutputStream&nbsp;out&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;blob.getBinaryOutputStream();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">byte</SPAN><SPAN style="COLOR: #000000">[]&nbsp;data&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">byte</SPAN><SPAN style="COLOR: #000000">[(</SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">)fin.available()];&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin.read(data);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.write(data);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">22</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.close();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">23</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fin.close();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">25</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt.setBlob(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,blob);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">26</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt.setString(</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">fankai</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">27</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">28</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt.executeUpdate();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">29</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pstmt.close();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">30</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">31</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.commit();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">32</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;conn.close();&nbsp;</SPAN></DIV>浏览数据库的数据，发现image项中数据大小与图片大小一致，说明入库了！<BR>&nbsp;3，blob出库<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp; <SPAN style="COLOR: #000000">DriverManager.registerDriver(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;oracle.jdbc.driver.OracleDriver());<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;Connection&nbsp;conn&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;DriverManager.getConnection(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">jdbc:oracle:thin:@localhost:1521:beyondduke</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">duke</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">duke</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; conn.setAutoCommit(</SPAN><SPAN style="COLOR: #0000ff">false</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;Statement&nbsp;stmt&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;conn.createStatement();<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_254_267_Open_Image onclick="this.style.display='none'; Codehighlighter1_254_267_Open_Text.style.display='none'; Codehighlighter1_254_267_Closed_Image.style.display='inline'; Codehighlighter1_254_267_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_254_267_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_254_267_Closed_Text.style.display='none'; Codehighlighter1_254_267_Open_Image.style.display='inline'; Codehighlighter1_254_267_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_254_267_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_254_267_Open_Text><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000">&nbsp;查询BLOB对象&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp; ResultSet&nbsp;rs&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;stmt.executeQuery(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">SELECT&nbsp;content&nbsp;FROM&nbsp;javatest&nbsp;WHERE&nbsp;id='1001'</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_369_765_Open_Image onclick="this.style.display='none'; Codehighlighter1_369_765_Open_Text.style.display='none'; Codehighlighter1_369_765_Closed_Image.style.display='inline'; Codehighlighter1_369_765_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_369_765_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_369_765_Closed_Text.style.display='none'; Codehighlighter1_369_765_Open_Image.style.display='inline'; Codehighlighter1_369_765_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">&nbsp;(rs.next())&nbsp;</SPAN><SPAN id=Codehighlighter1_369_765_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_369_765_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_371_385_Open_Image onclick="this.style.display='none'; Codehighlighter1_371_385_Open_Text.style.display='none'; Codehighlighter1_371_385_Closed_Image.style.display='inline'; Codehighlighter1_371_385_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_371_385_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_371_385_Closed_Text.style.display='none'; Codehighlighter1_371_385_Open_Image.style.display='inline'; Codehighlighter1_371_385_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_371_385_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_371_385_Open_Text><SPAN style="COLOR: #008000">/*</SPAN><SPAN style="COLOR: #008000">&nbsp;取出此BLOB对象&nbsp;</SPAN><SPAN style="COLOR: #008000">*/</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; oracle.sql.BLOB&nbsp;blob&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(oracle.sql.BLOB)&nbsp;rs.getBlob(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">image</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_450_463_Open_Image onclick="this.style.display='none'; Codehighlighter1_450_463_Open_Text.style.display='none'; Codehighlighter1_450_463_Closed_Image.style.display='inline'; Codehighlighter1_450_463_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_450_463_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_450_463_Closed_Text.style.display='none'; Codehighlighter1_450_463_Open_Image.style.display='inline'; Codehighlighter1_450_463_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;BufferedOutputStream&nbsp;out&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BufferedOutputStream(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;FileOutputStream(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">d://Sunset.jpg</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BufferedInputStream&nbsp;in&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;BufferedInputStream(blob&nbsp;&nbsp;&nbsp;&nbsp;.getBinaryStream());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp; </SPAN><SPAN style="COLOR: #0000ff">int</SPAN><SPAN style="COLOR: #000000">&nbsp;c;<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_677_698_Open_Image onclick="this.style.display='none'; Codehighlighter1_677_698_Open_Text.style.display='none'; Codehighlighter1_677_698_Closed_Image.style.display='inline'; Codehighlighter1_677_698_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_677_698_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_677_698_Closed_Text.style.display='none'; Codehighlighter1_677_698_Open_Image.style.display='inline'; Codehighlighter1_677_698_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">while</SPAN><SPAN style="COLOR: #000000">&nbsp;((c&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;in.read())&nbsp;</SPAN><SPAN style="COLOR: #000000">!=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_677_698_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_677_698_Open_Text><SPAN style="COLOR: #000000">{&nbsp;out.write(c);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp; }</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp; in.close();<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp; out.close();<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;rs.close();<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp; stmt.close();<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp; conn.close();<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN></DIV></SPAN>检查D盘根目录，会发现Sunset.jpg文件，跟C盘下是一样的，说明入库出库成功！<img src ="http://www.blogjava.net/beyondduke/aggbug/30542.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2006-02-14 09:23 <a href="http://www.blogjava.net/beyondduke/archive/2006/02/14/30542.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跨平台的JAVA调不跨平台的C--（JNI在Win32&amp;&amp;Linux下的使用）</title><link>http://www.blogjava.net/beyondduke/archive/2005/12/21/24983.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Wed, 21 Dec 2005 10:54:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2005/12/21/24983.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/24983.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2005/12/21/24983.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/24983.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/24983.html</trackback:ping><description><![CDATA[<FONT size=2>&nbsp;&nbsp; 由于java程序需要调用C或C++的代码，不得不使用JNI。C的代码在Win32和Linux下都有相同功能的不同实现，就像JDK分几种平台版本（win32，linux，solaris等）。<BR>&nbsp;&nbsp;&nbsp;<STRONG>首先，看一看首先，看一看win32下调用dll文件。<BR></STRONG>&nbsp;&nbsp; &nbsp;1， 新建HelloWorld.java<BR></FONT>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;HelloWorld<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_24_281_Open_Image onclick="this.style.display='none'; Codehighlighter1_24_281_Open_Text.style.display='none'; Codehighlighter1_24_281_Closed_Image.style.display='inline'; Codehighlighter1_24_281_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_24_281_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_24_281_Closed_Text.style.display='none'; Codehighlighter1_24_281_Open_Image.style.display='inline'; Codehighlighter1_24_281_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_24_281_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_24_281_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_37_220_Open_Image onclick="this.style.display='none'; Codehighlighter1_37_220_Open_Text.style.display='none'; Codehighlighter1_37_220_Closed_Image.style.display='inline'; Codehighlighter1_37_220_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_37_220_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_37_220_Closed_Text.style.display='none'; Codehighlighter1_37_220_Open_Image.style.display='inline'; Codehighlighter1_37_220_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_37_220_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_37_220_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">try</SPAN></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_51_120_Open_Image onclick="this.style.display='none'; Codehighlighter1_51_120_Open_Text.style.display='none'; Codehighlighter1_51_120_Closed_Image.style.display='inline'; Codehighlighter1_51_120_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_51_120_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_51_120_Closed_Text.style.display='none'; Codehighlighter1_51_120_Open_Image.style.display='inline'; Codehighlighter1_51_120_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_51_120_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_51_120_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">此处即为本地方法所在链接库名</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.loadLibrary(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">HelloWorld</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_150_216_Open_Image onclick="this.style.display='none'; Codehighlighter1_150_216_Open_Text.style.display='none'; Codehighlighter1_150_216_Closed_Image.style.display='inline'; Codehighlighter1_150_216_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_150_216_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_150_216_Closed_Text.style.display='none'; Codehighlighter1_150_216_Open_Image.style.display='inline'; Codehighlighter1_150_216_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></FONT></SPAN><FONT size=2><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">(UnsatisfiedLinkError&nbsp;e)</SPAN><SPAN id=Codehighlighter1_150_216_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_150_216_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.err.println(&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">不能加载dll文件:\n&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">e.toString()&nbsp;);<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></FONT></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;}</SPAN></FONT></SPAN><FONT size=2><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">end&nbsp;static</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">native</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;SayHello(String&nbsp;strName);<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></FONT></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></DIV><FONT size=2>&nbsp; 2,&nbsp;&nbsp;编译java文件生成HelloWorld.class文件<BR>&nbsp; 3，在命令行下，javah -jni HelloWorld 生成 HelloWorld.h&nbsp;文件<BR>&nbsp;&nbsp; </FONT>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG id=Codehighlighter1_0_52_Open_Image onclick="this.style.display='none'; Codehighlighter1_0_52_Open_Text.style.display='none'; Codehighlighter1_0_52_Closed_Image.style.display='inline'; Codehighlighter1_0_52_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_0_52_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_0_52_Closed_Text.style.display='none'; Codehighlighter1_0_52_Open_Image.style.display='inline'; Codehighlighter1_0_52_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN id=Codehighlighter1_0_52_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_0_52_Open_Text><SPAN style="COLOR: #008080">/*</SPAN><SPAN style="COLOR: #008080">&nbsp;DO&nbsp;NOT&nbsp;EDIT&nbsp;THIS&nbsp;FILE&nbsp;-&nbsp;it&nbsp;is&nbsp;machine&nbsp;generated&nbsp;</SPAN><SPAN style="COLOR: #008080">*/</SPAN></SPAN></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#include&nbsp;</SPAN><SPAN style="COLOR: #808080">&lt;</SPAN><SPAN style="COLOR: #000000">jni.h</SPAN><SPAN style="COLOR: #808080">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_71_103_Open_Image onclick="this.style.display='none'; Codehighlighter1_71_103_Open_Text.style.display='none'; Codehighlighter1_71_103_Closed_Image.style.display='inline'; Codehighlighter1_71_103_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_71_103_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_71_103_Closed_Text.style.display='none'; Codehighlighter1_71_103_Open_Image.style.display='inline'; Codehighlighter1_71_103_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_71_103_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN><SPAN id=Codehighlighter1_71_103_Open_Text><SPAN style="COLOR: #008080">/*</SPAN><SPAN style="COLOR: #008080">&nbsp;Header&nbsp;for&nbsp;class&nbsp;HelloWorld&nbsp;</SPAN><SPAN style="COLOR: #008080">*/</SPAN></SPAN></FONT><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"><FONT size=2>&nbsp;4</FONT></SPAN><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#ifndef&nbsp;_Included_HelloWorld<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#define&nbsp;_Included_HelloWorld<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#ifdef&nbsp;__cplusplus<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>extern&nbsp;"C"&nbsp;{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#endif<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_203_291_Open_Image onclick="this.style.display='none'; Codehighlighter1_203_291_Open_Text.style.display='none'; Codehighlighter1_203_291_Closed_Image.style.display='inline'; Codehighlighter1_203_291_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_203_291_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_203_291_Closed_Text.style.display='none'; Codehighlighter1_203_291_Open_Image.style.display='inline'; Codehighlighter1_203_291_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_203_291_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</SPAN></FONT><SPAN id=Codehighlighter1_203_291_Open_Text><SPAN style="COLOR: #008080"><FONT size=2>/*</FONT></SPAN><SPAN style="COLOR: #008080"><BR></SPAN><SPAN style="COLOR: #008080"><FONT size=2>11</FONT></SPAN><FONT size=2><SPAN style="COLOR: #008080"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;*&nbsp;Class:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloWorld<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN></FONT><FONT size=2><SPAN style="COLOR: #008080"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;*&nbsp;Method:&nbsp;&nbsp;&nbsp;&nbsp;SayHello<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN></FONT><FONT size=2><SPAN style="COLOR: #008080"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;*&nbsp;Signature:&nbsp;(Ljava/lang/String;)<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #008080"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;</SPAN><SPAN style="COLOR: #008080">*/</SPAN></FONT></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"><FONT size=2>15</FONT></SPAN><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>JNIEXPORT&nbsp;void&nbsp;JNICALL&nbsp;Java_HelloWorld_SayHello<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;(JNIEnv&nbsp;</SPAN><SPAN style="COLOR: #808080">*</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">,&nbsp;jobject,&nbsp;jstring);<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">18</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#ifdef&nbsp;__cplusplus<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>}<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#endif<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#endif<BR></SPAN><SPAN style="COLOR: #008080">22</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></DIV><FONT size=2>&nbsp; 4,&nbsp;&nbsp; 编写HelloWorld.cpp<BR></FONT>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">#include&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">windows.h</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#include&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">HelloWorld.h</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>#include&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">stdio.h</SPAN><SPAN style="COLOR: #000000">&gt;</SPAN></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">与Hello.h中函数声明相同</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">JNIEXPORT&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;JNICALL&nbsp;Java_HelloWorld_SayHello&nbsp;(JNIEnv&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;env,&nbsp;jobject&nbsp;arg,&nbsp;jstring&nbsp;instring)<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_176_427_Open_Image onclick="this.style.display='none'; Codehighlighter1_176_427_Open_Text.style.display='none'; Codehighlighter1_176_427_Closed_Image.style.display='inline'; Codehighlighter1_176_427_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_176_427_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_176_427_Closed_Text.style.display='none'; Codehighlighter1_176_427_Open_Image.style.display='inline'; Codehighlighter1_176_427_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_176_427_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_176_427_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">从instring字符串取得指向字符串UTF编码的指针</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">const</SPAN><SPAN style="COLOR: #000000">&nbsp;jbyte&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">str&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">const</SPAN><SPAN style="COLOR: #000000">&nbsp;jbyte&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">)env</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">GetStringUTFChars(&nbsp;instring,&nbsp;JNI_FALSE&nbsp;);<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>printf(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">HelloWorld,%s\n</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">,str);<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">通知虚拟机本地代码不再需要通过str访问Java字符串。</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">env</SPAN><SPAN style="COLOR: #000000">-&gt;</SPAN><SPAN style="COLOR: #000000">ReleaseStringUTFChars(&nbsp;instring,&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">const</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">char</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">)str&nbsp;);<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">return</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">;<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></FONT></SPAN><FONT size=2><SPAN style="COLOR: #000000">&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">int</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;WINAPI&nbsp;DllMain&nbsp;(HINSTANCE&nbsp;hInstance,&nbsp;DWORD&nbsp;fdwReason,&nbsp;PVOID&nbsp;pvReserved)<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_506_526_Open_Image onclick="this.style.display='none'; Codehighlighter1_506_526_Open_Text.style.display='none'; Codehighlighter1_506_526_Closed_Image.style.display='inline'; Codehighlighter1_506_526_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_506_526_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_506_526_Closed_Text.style.display='none'; Codehighlighter1_506_526_Open_Image.style.display='inline'; Codehighlighter1_506_526_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top></SPAN><SPAN id=Codehighlighter1_506_526_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_506_526_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;TRUE&nbsp;;<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></FONT></SPAN></DIV><FONT size=2>5,&nbsp;&nbsp;在vc6下新建dll工程HelloWorld,加载HelloWorld.h和HelloWorld.cpp,编译生成HelloWorld.dll文件，最关键的是引用JAVAHOME\include\和JAVAHOME\include\win32的.h文件。<BR>6，设置classpath为dll文件所在路径，新建一个测试类TestHelloWorldDLL.java<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">1</SPAN><IMG id=Codehighlighter1_24_134_Open_Image onclick="this.style.display='none'; Codehighlighter1_24_134_Open_Text.style.display='none'; Codehighlighter1_24_134_Closed_Image.style.display='inline'; Codehighlighter1_24_134_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_24_134_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_24_134_Closed_Text.style.display='none'; Codehighlighter1_24_134_Open_Image.style.display='inline'; Codehighlighter1_24_134_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">&nbsp;HelloWorld&nbsp;</SPAN><SPAN id=Codehighlighter1_24_134_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_24_134_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">2</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_64_132_Open_Image onclick="this.style.display='none'; Codehighlighter1_64_132_Open_Text.style.display='none'; Codehighlighter1_64_132_Closed_Image.style.display='inline'; Codehighlighter1_64_132_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_64_132_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_64_132_Closed_Text.style.display='none'; Codehighlighter1_64_132_Open_Image.style.display='inline'; Codehighlighter1_64_132_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">static</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;main(String&nbsp;args[])</SPAN><SPAN id=Codehighlighter1_64_132_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_64_132_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HelloWorld&nbsp;hw&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;HelloWorld();<BR></SPAN><SPAN style="COLOR: #008080">4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hw.SayHello(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Christmas</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;&nbsp;&nbsp;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080">6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>}</SPAN></SPAN></DIV><BR>7,&nbsp;&nbsp;输出结果: HelloWorld Christmas<BR>=======================================================================================================<BR><BR>&nbsp;<STRONG>接下来，在linux下调用so试一试。<BR></STRONG>&nbsp;因为linux下不能用vc所以gcc，如下命令：<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #008000">#</SPAN><SPAN style="COLOR: #008000">gcc&nbsp;-I/usr/java/include&nbsp;-shared&nbsp;-o&nbsp;libHelloWorld.so&nbsp;HelloWorld.cpp&nbsp;</SPAN></DIV>&nbsp;&nbsp;&nbsp; 运行测试程序，发现不能导入.so文件，提示no&nbsp;HelloWorld &nbsp;in java.library.path，所以需要设置java.library.path。<BR>&nbsp;
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">java&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">Djava</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #000000">library</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #000000">path</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">`pwd`&nbsp;</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">cp&nbsp;</SPAN><SPAN style="COLOR: #000000">.</SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;MyNative</SPAN></DIV>注意我把.so文件拷到了当前路径，其他路径设置即可！<BR>再执行，ok了，输出正确结果！<BR>&nbsp;<BR><STRONG>最后，总结一下：<BR></STRONG>&nbsp; jni的使用很简单，麻烦的是抽象出所调用dll或so文件的接口封装成native方法。另外就是生成so或dll文件以后的路径很不好控制。最重要的一点Java 的C调用通常不能移植到其他平台上，失去了“write once，run anywhere ”的美誉！但没违反重用性的规则。再者，需求来了，不这样实现能行吗？</FONT><img src ="http://www.blogjava.net/beyondduke/aggbug/24983.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2005-12-21 18:54 <a href="http://www.blogjava.net/beyondduke/archive/2005/12/21/24983.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WebService总结</title><link>http://www.blogjava.net/beyondduke/archive/2005/12/17/24345.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Sat, 17 Dec 2005 05:11:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2005/12/17/24345.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/24345.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2005/12/17/24345.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/24345.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/24345.html</trackback:ping><description><![CDATA[<FONT color=#000080>I&nbsp; <FONT style="BACKGROUND-COLOR: #ffffff"><STRONG>什么是</STRONG></FONT><FONT style="BACKGROUND-COLOR: #ffffff"><STRONG>WebService<BR></STRONG><FONT color=#0000ff>&nbsp;&nbsp;&nbsp;&nbsp; <FONT size=2>1，Web Service</FONT></FONT><FONT size=2><FONT color=#000000> 是一种新的web应用程序分支，他们是自包含、自描述、模块化的应用，可以发布、定位、通过web调用。Web Service可以执行从简单的请求到复杂商务处理的任何功能。一旦部署以后，其他Web Service应用程序可以发现并调用它部署的服务。 Web Service是一种应用程序，它可以使用标准的互联网协议，像超文本传输协议(HTTP)和XML，将功能纲领性地体现在互联网和企业内部网上。可将Web服务视作Web上的组件编程。&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2，web广泛用到的技术：&nbsp;<BR>&nbsp;&nbsp; ◆ TCP/IP：通用网络协议，被各种设备使用&nbsp;<BR>&nbsp;&nbsp; ◆ HTML：通用用户界面，可以使用HTML标签显示数据&nbsp;<BR>&nbsp;&nbsp; ◆ Java：写一次可以在任何地方运行的通用编程语言&nbsp;<BR>&nbsp;&nbsp; ◆ XML ：通用数据表达语言，在web上传送机构化数据的容易方法&nbsp;<BR>他们的特点是其开放性，跨平台性，开放性正是Web services的基础。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3，webService的作用<BR>&nbsp;&nbsp; ◆ 内容更加动态：一个web service必须能合并从多个不同源来的内容，可以包括股票，天气，新闻等，在传统环境中的内容，如存货水平，购物订单或者目录信息等，都从后端系统而来 <BR>&nbsp;&nbsp; ◆ 带宽更加便宜：web services可以分发各种类型的内容（音频，视频流等） <BR>&nbsp;&nbsp; ◆ 存储更便宜: web services必须能聪明地处理大量数据，意味着要使用数据库，LDAP目录，缓冲，和负载平衡软件等技术保持可扩展能力 <BR>&nbsp;&nbsp; ◆普遍式计算更重要：web services不能要求客户使用某一版本的windows的传统浏览器，必须支持各种设备，平台，浏览器类型，各种内容类型。 <BR>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 4 ， webService的实现<BR>&nbsp;&nbsp; ◆ XML XML是在web上传送结构化数据的伟大方式，Web services要以一种可靠的自动的方式操作数据，HTML不会满足要求，而XML可以使web services十分方便的处理数据，它的内容与表示的分离十分理想 <BR>&nbsp;&nbsp; ◆ SOAP SOAP使用XML消息调用远程方法，这样web services可以通过HTTP协议的post和get方法与远程机器交互，而且，SOAP更加健壮和灵活易用。 <BR>其他象UDDI和WSDL技术与XML和SOAP技术紧密结合用于服务发现。</T<DIV style="DISPLAY: none"><BR>&nbsp;&nbsp; <BR><FONT color=#000080 size=3><STRONG>II&nbsp; 什么时候用WebService<BR><BR></STRONG><FONT color=#000000 size=2>&nbsp;&nbsp; ◆&nbsp; 跨越防火墙的通信<BR></FONT><FONT color=#000000 size=2>&nbsp;&nbsp;&nbsp;&nbsp;如果你的应用程序有成千上万的用户，而且他们都分布在世界各地，那么客户端和服务器之间的通信将是一个棘手的问题。那是因为客户端和服务器之间通常都会有防火墙或者代理服务器。在这种情况下，你想使用DCOM就不是那么简单了，而且，通常你也不愿意把你的客户端程序发布到如此庞大数量的每一个用户手中。于是，你最终选择了用浏览器作为客户端，写下一堆ASP页面，把应用程序的中间层暴露给最终用户。结果呢？运气好的话，只是开发难度大了一些，运气不好的话，就会得到一个根本无法维护的应用程序。想象一下你应该怎么在你的应用程序里面加入一个新的页面：你必须先建立好用户界面(Web页面)，以及在这个页面后面，包含相应商业逻辑的中间层组件。这还不够，你还要再建立至少一个ASP页面，用来接受用户输入的信息，调用中间层组件，把结果格式化为HTML形式，最后还要把"结果页"送回浏览器。要是客户端代码不再如此依赖于HTML表单，客户端的编程不就简单多了吗？还有，建立ASP页面的那一步可以省略掉吗？&nbsp;当然。如果你的中间层组件是Webservice的话，你完全可以从用户界面直接调用中间层组件，从而省掉建立ASP页面的那一步。要调用Webservice，你可以直接使用MicrosoftSOAPToolkit或.NET这样的SOAP客户端，也可以使用你自己开发的SOAP客户端，然后把它和你的应用程序连接起来。这样做，不仅可以缩短开发周期，还可以减少代码的复杂度，并增强整个应用程序的可维护性。同时，你的应用程序也不再需要在每次调用中间层组件时，都跳转到相应的"结果页"了。以我的经验来看，在一个用户界面和中间层有较多交互的应用程序中，使用Webservice这种结构，可以轻松的节省花在用户界面编程上的20%的开发时间。这样做还有另一个好处，就是你将得到一个由Webservice组成的中间层，这一层是完全可以在应用程序集成或其他场合下被重用的。最后，通过Webservice把你的应用程序的逻辑和数据暴露出来，还可以让其它平台上的客户重用你的应用程序。<BR></FONT><FONT color=#000000><FONT size=2>&nbsp;◆ 应用程序集成<BR>&nbsp;&nbsp;&nbsp;&nbsp;企业级的应用程序开发者都知道，企业里经常都要把用不同语言写成的在不同平台上运行的各种程序集成起来，而这种集成将花费很大的开发的力量。你的应用程序经常都需要从运行在古老的IBM主机上的程序中获取数据；或者再把数据发送到主机或UNIX应用程序中去。即使是在同一个平台上，不同的软件厂商生产的各种软件也常常需要集成起来。通过Webservice，应用程序可以用标准的方法把功能和数据暴露出来，供其它的应用程序使用。例如，你有一个订单登录程序，用于登录从客户来的新订单，包括客户信息、发货地址、数量、价格和付款方式等信息。同时，你还有一个订单执行程序，用于实际货物发送的管理。这两个程序是来自不同软件厂商的。一份新订单进来之后，订单登录程序需要通知订单执行程序发送货物。通过在订单执行程序上面增加一层Webservice，订单执行程序可以把"AddOrder"函数暴露出来。这样，每当有新订单到来时，订单登录程序就可以调用这个函数来发送货物了。进而通过Webservice集成应用程序<BR></FONT></FONT><FONT color=#000000><FONT size=2>&nbsp; ◆ B2B的集成<BR>&nbsp;用Webservice集成应用程序，可以使你公司内部的商务处理更加自动化。但当交易跨越了你的供应商和客户，突破了公司的界线时又会怎么样呢？跨公司的商务交易集成通常叫做B2B集成。Webservice是B2B集成成功的关键。通过Webservice，你的公司可以把关键的商务应用暴露给指定的供应商和客户。例如，把你的电子下单系统和电子发票系统暴露出来，你的客户就可以以电子的方式向你发送购货订单，而你的供应商则可以以电子的方式把原料采购的发票发送给你。当然，这并不是一个新的概念：电子文档交换(EDI)早就是这样了。Webservice和EDI之间的主要区别在于，Webservice的实现要比EDI简单得多，而且Webservice是运行在Internet上的，在世界任何地方都可轻易实现，这样其运行成本就相对较低。不过，Webservice并不像EDI那样，是文档交换或B2B集成的一套完整的解决方案。Webservice只是B2B集成的一个关键部分，还需要许多其它的部分才能完成这个集成。用Webservice来实现B2B集成的最大好处在于可以轻易实现互操作性。只要把你的商务逻辑暴露出来，成为Webservice，你就可以让任何指定的合作伙伴轻松的调用你的商务逻辑，而不管他们的系统在什么平台上运行，使用的是什么开发语言。这样就大大减少了花在B2B集成的上的时间和成本。这样的低成本让许多原本无法承受EDI的投资成本的中小企业也能实现B2B集成。<BR></FONT></FONT><FONT color=#000000><FONT size=2>&nbsp;◆ 软件重用<BR>&nbsp;&nbsp; 软件重用是一个很大的主题，它有很多的形式和程度。最基本的形式是源代码模块或者类一级的重用。另一种形式是二进制形式的组件重用。当前，像表格控件或用户界面控件这样的可重用软件组件在市场上都占有很大的份额。但这类软件的重用都有一个很严重的限制：重用仅限于代码，而数据不能被重用。原因在于你可以很轻易的发布组件甚至源代码，但要发布数据就没那么容易了，除非那些数据都是不会经常变化的静态数据。&nbsp;&nbsp;而Webservice允许你在重用代码的同时，重用代码后面的数据。使用Webservice，你不再像以前那样，要先从第三方购买、安装软件组件，再从你的应用程序中调用这些组件。你只需要直接调用远端的Webservice就可以了。举个例子，你想在你的应用程序中确认用户输入的邮件地址，那么，你只需把这个地址直接发送给相应的Webservice，这个Webservice就会帮你查阅街道地址、城市、省区和邮政编码等信息，确认这个地址的确在相应的邮政编码区域。Webservice的提供商可以按时间或使用次数来对这项服务进行收费。这样的服务要通过组件重用来实现是不现实的，因为那样的话你必须下载并安装好包含街道地址、城市、省区和邮政编码等信息的数据库，而且这个数据库还是不能实时更新的。另一种软件重用的情况是把好几个应用程序的功能集成起来。例如，你想要建立一个局域网上的门户站点应用，让用户既可以查询他们的联邦快递包裹，察看股市行情，又可以管理他们的日程安排，还可以在线购买电影票。现在Web上有很多应用程序供应商，都在其应用中实现了上面的这些功能。一旦他们把这些功能都通过Webservice暴露出来，你就可以非常轻易地把所有这些功能都集成到你的门户站点中，为用户提供一个统一的、友好的界面。<BR>用Webservice来集成各种应用中的功能，为用户提供一个统一的界面<BR>许多应用程序都会利用Webservice，把当前基于组件的应用程序结构扩展为组件和Webservice的混合结构。你也可以在应用程序中使用第三方的Webservice提供的功能。你还可以把你自己的应用程序的功能通过Webservice提供给别人。所有这些情况下，你都可以重用代码和代码后面的数据。总之，Webservice将是软件重用的一种非常有力的形式。</FONT></FONT><BR></FONT><BR><BR><BR></FONT><BR></FONT></FONT></FONT><img src ="http://www.blogjava.net/beyondduke/aggbug/24345.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2005-12-17 13:11 <a href="http://www.blogjava.net/beyondduke/archive/2005/12/17/24345.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>简单EXCEL报表方案：Spring+POI</title><link>http://www.blogjava.net/beyondduke/archive/2005/12/15/23978.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Thu, 15 Dec 2005 02:05:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2005/12/15/23978.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/23978.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2005/12/15/23978.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/23978.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/23978.html</trackback:ping><description><![CDATA[<P>&nbsp;&nbsp;&nbsp; <FONT size=2>近期为完成一个简单的报表模块，需求很简单，从数据库中取出数据导出到已写好的Excel模版中。<BR>&nbsp;&nbsp;&nbsp;&nbsp; 一开始准备用jfreeReport实现，偶然调试spring的demo时发现，countries的例子很好，既有web分页，又有excel，pdf的输出，经分析例子，spring封装了poi实现excel导出，itext实现pdf输出。<BR>&nbsp;&nbsp;&nbsp;&nbsp; 1，先来分析一下poi的一些背景。POI的主页：</FONT><A href="http://jakarta.apache.org/poi"><FONT size=2>http://jakarta.apache.org/poi</FONT></A><FONT size=2>。POI HSSF是当今市面上最强大的处理EXCEL表格的java工具，比韩国人写的那个JExcelApi或其它几种工具都要好。而且它是Apache的开源项目。当然POI HSSF也有缺点：不能直接支持EXCEL图表，API文档粗糙简略，有些类和方法需要引用Apache项目中的其它一些包，包与包之间依赖关系比较复杂等等。<BR>Apache的Jakata项目的POI子项目，目标是处理ole2对象。目前比较成熟的是HSSF接口，处理MS Excel（97-2002）对象。它不象我们仅仅是用csv生成的没有格式的可以由Excel转换的东西，而是真正的Excel对象，你可以控制一些属性如sheet,cell等等。这是一个年轻的项目，所以象HDF这样直接支持Word对象的好东西仍然在设计中。其它支持word格式的纯java方案还有itext，不过也是仍在奋斗中。但是HSSF已经成熟到能够和足够我们使用了。另外，无锡永中Office的实现方案也是纯java的解决方案，不过那也是完全商业的产品，并不是公开代码项目。其实，从开发历史的角度讲，在80年代中期starOffice的原作者在德国成立了StarOffice suite公司，然后到1999年夏天starOffice被sun收购，再到2000年6月starOffice5.2的发布；并且从starOffice6.0开始，starOffice建立在OpenOffice的api的基础上，这个公开代码的office项目已经进行了很长的时间。虽然那是由C++写的，但是POI的代码部分也是由openOffice改过来的。所以，应该对POI充满足够的信心。国内已经有部分公司在他们的办公自动化等Web项目中使用poi了，如日恒的ioffice，海泰的HTOffice等。java当初把核心处理设成Unicode，带来的好处是另代码适应了多语言环境。然而由于老外的英语只有26个字母，有些情况下，一些程序员用8位的byte处理，一不小心就去掉了CJK的高位。或者是由于习惯在程序中采用硬编码，还有多种原因，使得许多java应用在CJK的处理上很烦恼。还好在POI HSSF中考虑到这个问题，可以设置encoding为双字节。编译好的jar主要有这样4个：poi包,poi Browser包,poi hdf包,poi hssf例程包。实际运行时，需要有poi包就可以了。如果用Jakarta ant编译和运行，下载apache Jakarta POI的release中的src包，它里面已经为你生成好了build文件了。只要运行ant就可以了(ant 的安装和使用在此不说了)。如果是用Jbuilder 运行，请在新建的项目中加入poi包。以Jbuilder6为例，选择Tools菜单项的config libraries...选项，新建一个lib。在弹出的菜单中选择poi包，如这个jakarta-poi-1.5.1-final-20020820.jar，把poi添加到jbuilder中。然后，右键点击你的项目，在project的properties菜单中path的required Libraries中，点add，添加刚才加入到jbuilder中的poi到你现在的项目中。如果你仅仅是为了熟悉POI hssf的使用，可以直接看POI的samples包中的源代码，并且运行它。hssf的各种对象都有例程的介绍。hssf提供的例程在org.apache.poi.hssf.usermodel.examples包中，共有14个，生成的目标xls都是workbook.xls。如果你想看更多的例程，可以参考hssf的Junit test cases，在poi的包的源代码中有。hssf都有测试代码。<BR>&nbsp;&nbsp;&nbsp;&nbsp; 2&nbsp;，poi提供了一个不错的tutor，教初学者如何快速上手使用POI HSSF：<U><FONT color=#0000ff>http</FONT></U></FONT><A href="http://jakarta.apache.org/poi/hssf/quick-guide.html"><FONT size=2><FONT color=#0000ff>://jakarta.apache.org/poi/hssf/quick-</FONT><FONT color=#0000ff>guide.html</FONT></FONT></A><BR><FONT size=2>&nbsp;建一个poiDemo的工程，然后把tutor首页的例子运行一遍，入门级别就够了。其中包括：新建excel文件（WorkBook）；新建sheet；开辟cell；设置cell数据类型和格式；设置输出的样式如对齐方式，颜色，字体，边框等；合并单元格；读取已有excel文件；设置打印区域；设置页码和页脚；调用公式；选中sheet；屏幕缩放；绘图；插入图像等等。<BR>&nbsp;&nbsp; 3， spring的对poi的封装。在spring-framework-1.2-rc2\src\org\springframework\web\servlet\view\document下有两个类AbstractExcelView.java和AbstractPdfView.java，其中前者是处理excel的抽象类，继承它的时候，需要实现抽象方法<!--StartFragment -->buildExcelDocument,实例代码如下：</FONT></P>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">protected</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;buildExcelDocument(<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map&nbsp;model,&nbsp;HSSFWorkbook&nbsp;workbook,<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_138_1004_Open_Image onclick="this.style.display='none'; Codehighlighter1_138_1004_Open_Text.style.display='none'; Codehighlighter1_138_1004_Closed_Image.style.display='inline'; Codehighlighter1_138_1004_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_138_1004_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_138_1004_Closed_Text.style.display='none'; Codehighlighter1_138_1004_Open_Image.style.display='inline'; Codehighlighter1_138_1004_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response)&nbsp;</SPAN><SPAN id=Codehighlighter1_138_1004_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_138_1004_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT><FONT size=2><SPAN style="COLOR: #008000">&nbsp;Go&nbsp;to&nbsp;the&nbsp;first&nbsp;sheet.<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN></FONT><FONT size=2><SPAN style="COLOR: #008000">&nbsp;getSheetAt:&nbsp;only&nbsp;if&nbsp;workbook&nbsp;is&nbsp;created&nbsp;from&nbsp;an&nbsp;existing&nbsp;document<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;HSSFSheet&nbsp;sheet&nbsp;=&nbsp;workbook.getSheetAt(0);</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HSSFSheet&nbsp;sheet&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;workbook.createSheet(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Spring</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sheet.setDefaultColumnWidth(</SPAN><SPAN style="COLOR: #000000">12</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Write&nbsp;a&nbsp;text&nbsp;at&nbsp;A1.</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;HSSFCell&nbsp;cell&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;getCell(sheet,&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;setText(cell,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Spring&nbsp;POI&nbsp;test</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">15</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Write&nbsp;the&nbsp;current&nbsp;date&nbsp;at&nbsp;A2.</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;HSSFCellStyle&nbsp;dateStyle&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;workbook.createCellStyle();<BR></SPAN><SPAN style="COLOR: #008080">17</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;dateStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">m/d/yy</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;cell&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;getCell(sheet,&nbsp;</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;cell.setCellValue(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">&nbsp;Date());<BR></SPAN><SPAN style="COLOR: #008080">20</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;cell.setCellStyle(dateStyle);<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">22</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Write&nbsp;a&nbsp;number&nbsp;at&nbsp;A3</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">23</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;getCell(sheet,&nbsp;</SPAN><SPAN style="COLOR: #000000">2</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">).setCellValue(</SPAN><SPAN style="COLOR: #000000">458</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">25</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">&nbsp;Write&nbsp;a&nbsp;range&nbsp;of&nbsp;numbers.</SPAN></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">26</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;HSSFRow&nbsp;sheetRow&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;sheet.createRow(</SPAN><SPAN style="COLOR: #000000">3</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">27</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_946_1001_Open_Image onclick="this.style.display='none'; Codehighlighter1_946_1001_Open_Text.style.display='none'; Codehighlighter1_946_1001_Closed_Image.style.display='inline'; Codehighlighter1_946_1001_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align=top><IMG id=Codehighlighter1_946_1001_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_946_1001_Closed_Text.style.display='none'; Codehighlighter1_946_1001_Open_Image.style.display='inline'; Codehighlighter1_946_1001_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align=top>&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;(</SPAN><SPAN style="COLOR: #0000ff">short</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">;&nbsp;i&nbsp;</SPAN><SPAN style="COLOR: #000000">&lt;</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">10</SPAN><SPAN style="COLOR: #000000">;&nbsp;i</SPAN><SPAN style="COLOR: #000000">++</SPAN><SPAN style="COLOR: #000000">)&nbsp;</SPAN><SPAN id=Codehighlighter1_946_1001_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN></FONT><SPAN id=Codehighlighter1_946_1001_Open_Text><FONT size=2><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">28</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sheetRow.createCell(i).setCellValue(i&nbsp;</SPAN><SPAN style="COLOR: #000000">*</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">10</SPAN></FONT><FONT size=2><SPAN style="COLOR: #000000">);<BR></SPAN><SPAN style="COLOR: #008080">29</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align=top>&nbsp;&nbsp;&nbsp;}</SPAN></FONT></SPAN><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><SPAN style="COLOR: #008080">30</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;}</SPAN></FONT></SPAN></DIV><FONT size=2>4， 通过web程序调用，很多情况需要把生成的excel文件通过网络连接来输出，这些spring已经替你做好了，所以只要按照spring的调用标准就可以，我使用的是spring的mvc，实例代码如下：<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">1</SPAN><IMG id=Codehighlighter1_120_408_Open_Image onclick="this.style.display='none'; Codehighlighter1_120_408_Open_Text.style.display='none'; Codehighlighter1_120_408_Closed_Image.style.display='inline'; Codehighlighter1_120_408_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_120_408_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_120_408_Closed_Text.style.display='none'; Codehighlighter1_120_408_Open_Image.style.display='inline'; Codehighlighter1_120_408_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align=top><SPAN style="COLOR: #0000ff">protected</SPAN><SPAN style="COLOR: #000000">&nbsp;ModelAndView&nbsp;handleRequestInternal(HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;Exception&nbsp;</SPAN><SPAN id=Codehighlighter1_120_408_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.blogjava.net/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_120_408_Open_Text><SPAN style="COLOR: #000000">{<BR></SPAN><SPAN style="COLOR: #008080">2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;List&nbsp;list&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;(List)&nbsp;request.getSession().getAttribute(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">list</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">从session中取数据list</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">3</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Map&nbsp;model</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;HashMap();&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;model.put(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">list</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,list);&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">将list封装传到excelView中</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">5</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ExcelView&nbsp;ev&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">this</SPAN><SPAN style="COLOR: #000000">.getExcelView();</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">ExcelView继承了AbatractExcelView</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">6</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;ModelAndView(ev,model);&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">跳转页面</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">7</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;}</SPAN></SPAN></DIV></FONT>ok,整个简单的过程就完成了，你可以根据自己的需求灵活的在各个环节coding！漂亮的报表会让你兴奋不已！<BR><BR><BR><img src ="http://www.blogjava.net/beyondduke/aggbug/23978.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2005-12-15 10:05 <a href="http://www.blogjava.net/beyondduke/archive/2005/12/15/23978.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>https相关</title><link>http://www.blogjava.net/beyondduke/archive/2005/11/04/18076.html</link><dc:creator>beyondduke</dc:creator><author>beyondduke</author><pubDate>Fri, 04 Nov 2005 01:21:00 GMT</pubDate><guid>http://www.blogjava.net/beyondduke/archive/2005/11/04/18076.html</guid><wfw:comment>http://www.blogjava.net/beyondduke/comments/18076.html</wfw:comment><comments>http://www.blogjava.net/beyondduke/archive/2005/11/04/18076.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/beyondduke/comments/commentRss/18076.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/beyondduke/services/trackbacks/18076.html</trackback:ping><description><![CDATA[<FONT size=2><STRONG>什么是HTTPS？<BR></STRONG>当使用 基于SSL/TLS（通常使用 https:// URL）向站点进行HTTP请求时，从服务器向客户机发送一个证书。客户机使用已安装的公共证书通过这个证书验证服务器的身份，然后检查 IP 名称（机器名）与客户机连接的机器是否匹配。客户机生成一些可以用来生成对话的私钥（称为会话密钥）的随机信息，然后用服务器的公钥对它加密并将它发送到服务器。服务器用自己的私钥解密消息，然后用该随机信息派生出和客户机一样的私有会话密钥。通常在这个阶段使用 RSA 公钥算法。然后，客户机和服务器使用私有会话密钥和私钥算法（通常是 RC4）进行通信。使用另一个密钥的消息认证码来确保消息的完整性。<BR><BR><STRONG>什么是数字签名？</STRONG><BR>所谓数字签名就是信息发送者用其私有密钥对从所传报文中提取出的特征数据（或称数字指纹）进行RSA算法操作，以保证发信人无法抵赖曾发过该信息（即不可抵赖性），同时也确保信息报文在经签名后末被篡改（即完整性）。当信息接收者收到报文后，就可以用发送者的公钥对数字签名进行验证。<BR></FONT><STRONG>Overview of SSL？<BR></STRONG>&nbsp;&nbsp;&nbsp;&nbsp; SSL, or Secure Socket Layer, is a technology which allows web browsers and web servers to communicate over a secured connection. This means that the data being sent is encrypted by one side, transmitted, then decrypted by the other side before processing. This is a two-way process, meaning that both the server AND the browser encrypt all traffic before sending out data.<BR>&nbsp;&nbsp;&nbsp;&nbsp; Another important aspect of the SSL protocol is Authentication. This means that during your initial attempt to communicate with a web server over a secure connection, that server will present your web browser with a set of credentials, in the form of a "Certificate", as proof the site is who and what it claims to be. In certain cases, the server may also request a Certificate from your web browser, asking for proof that <EM>you</EM> are who you claim to be. This is known as "Client Authentication," although in practice this is used more for business-to-business (B2B) transactions than with individual users. Most SSL-enabled web servers do not request Client Authentication.<BR><STRONG>https与Tomcat<BR></STRONG><FONT size=3>&nbsp;&nbsp;</FONT><FONT size=2> <STRONG>The Apache Jakarta Tomcat 5 Servlet/JSP Container</STRONG></FONT><FONT size=2><STRONG> SSL Configuration HOW-TO?<BR></STRONG>利用快速配置：<BR>&nbsp; 1，用jdk中的keytool生成一个tomcat keystore<BR>&nbsp;&nbsp;&nbsp; 在命令行敲入：%JAVA_HOME%\bin\keytool -genkey -alias tomcat -keyalg RSA<BR>&nbsp;&nbsp;&nbsp; 会提示你输入keypassword 和 keystorepassword 以及其它相关信息。按提示确认完成。<BR>&nbsp; 2， 在conf/server.xml中加入：<BR>&nbsp;&nbsp;&nbsp;&nbsp; </FONT><FONT color=#0000ff><CONNECTOR <BR port="8443"><FONT size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; maxThreads="150" minSpareThreads="25" maxSpareThreads="75"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; enableLookups="false" disableUploadTimeout="true"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; acceptCount="100" debug="0" scheme="https" secure="true"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clientAuth="false" keystorePass="password" sslProtocol="TLS" /&gt;<BR>&nbsp; </FONT></FONT><FONT size=2>3，启动tomcat,打开浏览器输入</FONT><A href="https://localhost:8443"><FONT size=2>https://localhost:8443</FONT></A><FONT size=2> 就OK了。<BR>注意：用此方法生成的keystore文件置于C:\Documents and Settings\user下<BR>注释：<CONNECTOR /><BR></FONT><FONT size=3>
<TABLE border=1>
<TBODY>
<TR>
<TH>Attribute</TH>
<TH>Description</TH></TR>
<TR>
<TD><CODE>clientAuth</CODE></TD>
<TD>Set this value to <CODE>true</CODE> if you want Tomcat to require all SSL clients to present a client Certificate in order to use this socket. Set this value to <CODE>want</CODE> if you want Tomcat to request a client Certificate, but not fail if one isn't presented. </TD></TR>
<TR>
<TD><CODE>keystoreFile</CODE></TD>
<TD>Add this attribute if the keystore file you created is not in the default place that Tomcat expects (a file named <CODE>.keystore</CODE> in the user home directory under which Tomcat is running). You can specify an absolute pathname, or a relative pathname that is resolved against the <CODE>$CATALINA_BASE</CODE> environment variable.</TD></TR>
<TR>
<TD><CODE>keystorePass</CODE></TD>
<TD>Add this element if you used a different keystore (and Certificate) password than the one Tomcat expects (<CODE>changeit</CODE>).</TD></TR>
<TR>
<TD><CODE>keystoreType</CODE></TD>
<TD>Add this element if using a PKCS12 keystore. The valid values are <CODE>JKS</CODE> and <CODE>PKCS12</CODE>.</TD></TR>
<TR>
<TD><CODE>sslProtocol</CODE></TD>
<TD>The encryption/decryption protocol to be used on this socket. It is not recommended to change this value if you are using Sun's JVM. It is reported that IBM's 1.4.1 implementation of the TLS protocol is not compatible with some popular browsers. In this case, use the value <CODE>SSL</CODE>.</TD></TR>
<TR>
<TD><CODE>ciphers</CODE></TD>
<TD>The comma separated list of encryption ciphers that this socket is allowed to use. By default, any available cipher is allowed.</TD></TR>
<TR>
<TD><CODE>algorithm</CODE></TD>
<TD>The <CODE>X509</CODE> algorithm to use. This defaults to the Sun implementation (<CODE>SunX509</CODE>). For IBM JVMs you should use the value <CODE>IbmX509</CODE>. For other vendors, consult the JVM documentation for the correct value. </TD></TR>
<TR>
<TD><CODE>truststoreFile</CODE></TD>
<TD>The TrustStore file to use to validate client certificates.</TD></TR>
<TR>
<TD><CODE>truststorePass</CODE></TD>
<TD>The password to access the TrustStore. This defaults to the value of <CODE>keystorePass</CODE>.</TD></TR>
<TR>
<TD><CODE>truststoreType</CODE></TD>
<TD>Add this element if your are using a different format for the TrustStore then you are using for the KeyStore. The valid values are <CODE>JKS</CODE> and <CODE>PKCS12</CODE>.</TD></TR></TBODY></TABLE><BR></FONT><FONT size=2><STRONG>Java keytool工具的作用及使用方法?<BR></STRONG>Keytool 是安全钥匙与证书的管理工具。它管理一个存储了私有钥匙和验证相应公共钥匙的与它们相关联的X.509 证书链的keystore(相当一个数据库)。<BR>Keytool 是一个有效的安全钥匙和证书的管理工具。它能够使用户使用数字签名来管理他们自己的私有/公共钥匙对,管理用来作自我鉴定的相关的证书,管理数据完整性和鉴定服务。它还能使用户在通信时缓存它们的公共钥匙.<BR>一个证书是某一实体(个人,公司等)的数字签名，指出其他实体的公共钥匙(或其他信息)的详细的值.当数据被签名后,这个签名信息被用来检验数据的完整性和真实性.完整性指数据没有被修改和篡改,真实性指数据从任何产生和签名的一方真正的传输到达。<BR>Keytool 把钥匙和证书储存到一个keystore.默任的实现keystore的是一个文件。它用一个密码保护钥匙。而另外的一个工具jarsigner用keystore中的信息产生或检验Java aRchive(jar文件)中的数字签名。<BR>Keystore有两个不同的入口:<BR>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 钥匙入口:保存了非常敏感的加密的钥匙信息,并且是用一个保护的格式存储以防止未被授权的访问.以这种形式存储的钥匙是秘密钥匙,或是一个对应证书链中公有钥匙的私有钥匙.<BR>2.&nbsp;&nbsp;&nbsp; 信任证书入口:包含一个属于其他部分的单一公共钥匙证书.它之所以被称为"信任证书",是因为keystore信任的证书中的公共钥匙真正属于证书所有者的身份识别.<BR>&nbsp;<BR>Keystore的别名:<BR>所有的keystore入口(钥匙和信任证书入口)是通过唯一的别名访问.别名是不区分大小写的。如别名Hugo和hugo指向同一个keystore入口.<BR>可以在加一个入口到keystore的时候使用-genkey参数来产生一个钥匙对(公共钥匙和私有钥匙)时指定别名.也可以用-import参数加一个证书或证书链到信任证书。<BR>&nbsp;<BR>如：keytool -genkey -alias duke -keypass dukekeypasswd<BR>&nbsp;<BR>其中duke为别名,dukekeypasswd为duke别名的密码。这行命令的作用是产生一个新的公共/私有钥匙对. 其中duke为别名,dukekeypasswd为duke别名的密码.这行命令的作用是产生一个新的公共/私有钥匙对.<BR>假如你想修改密码,可以用：<BR>keytool -keypasswd -alias duke -keypass dukekeypasswd -new newpass<BR>将旧密码dukekeypasswd改为newpass.<BR>&nbsp;<BR>Keystore的产生:<BR>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当使用-genkey 或-import或-identitydb命令添加数据到一个keystore,而当这个keystore不存在时,产生一个keystore.默认名是.keystore,存放到user-home目录.<BR>2.&nbsp;&nbsp;&nbsp; 当用-keystore指定时,将产生指定的keystore.<BR>&nbsp;<BR>Keystore的实现:<BR>Keytool 类位于java.security包下,提供一个非常好的接口去取得和修改一个keystore中的信息. 目前有两个命令行:keytool和jarsinger,一个GUI工具Policy 可以实现keystore.由于keystore是公开的,用户可以用它写一些额外的安全应用程序。<BR>Keystore还有一个sun公司提供的內在实现.它把keystore作为一个文件来实现.利用了一个keystore类型(格式)"JKS".它用单独的密码保护每一个私有钥匙.也用可能不同的密码保护整个keystore的完整性.<BR>&nbsp;<BR>支持的算法和钥匙大小:<BR>keytool允许用户指定钥匙对和注册密码服务供应者所提供的签名算法.缺省的钥匙对产生算法是"DSA"。假如私有钥匙是"DSA"类型，缺省签名算法是"SHA1withDSA"，假如私有钥匙是"RSA"类型,缺省算法是"MD5withRSA".<BR>当产生一个DSA钥匙对,钥匙必须在512-1024位之间.对任何算法的缺省钥匙大小是1024位.<BR>&nbsp;<BR>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 证书：一个证书是一个实体的数字签名,指出其他实体的公共钥匙有明确的值。<BR>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 公共钥匙：是同一个详细的实体的数字关联,并有意让所有想同这个实体发生信任关系的其他实体知道，公共钥匙用来检验签名;<BR>3.&nbsp;&nbsp;&nbsp; 数字签名:假如数据已被签名,并用身份存储在一个实体中,一个签名能够证明这个实体知道这个数据.这个数据用实体私有钥匙签名并递交;<BR>4.&nbsp;&nbsp;&nbsp; 身份:知道实体的方法.在一些系统中身份是公共钥匙,其他系统中可以是从一个X.509名字的邮件地址的Unix UID来的任何东西;<BR>5.&nbsp;&nbsp;&nbsp; 签名:一个签名用实体私有钥匙来计算某些加密数据;<BR>6.&nbsp;&nbsp;&nbsp; 私有钥匙:是一些数字,每一个私有钥匙只能被特定的拥有该私有钥匙的实体知道.私有和公共钥匙存在所有用公共钥匙加密的系统的钥匙对中.一个公共钥匙加密(如DSA),一个私有钥匙与一个正确的公共钥匙通信.私有钥匙用来计算签名。<BR>7.&nbsp;&nbsp;&nbsp; 实体:一个实体可以是一个人,一个组织,一个程序,一台计算机,一个商业,一个银行,或其他你想信任的东西.<BR>&nbsp;<BR>Keytool应用实例:<BR>&nbsp;<BR>1.产生一个keystore:<BR>&nbsp;<BR>keytool -genkey -alias User(keystore的别名) -keyalg RSA -validity 7 -keystore keystore(指定keystore).<BR>&nbsp;<BR>运行这个命令,系统提示:<BR>Enter keystore password:yourpassword(输入密码)<BR>&nbsp;<BR>What is your first and last name?<BR>[Unknown]: your name(输入你的名字)<BR>&nbsp;<BR>What is the name of your organizational unit?<BR>[Unknown]:your organizational(输入你所在组织单位的名字)<BR>&nbsp;<BR>What is the name of your organization?<BR>[Unknown]:your organization name (输入你所在组织的名字)<BR>&nbsp;<BR>What is the name of your City or Locality?<BR>[Unknown]:your city name(输入所在城市的名字)<BR>&nbsp;<BR>What is the name of your State or Province?<BR>[Unknown]:your provice name(输入所在省份名字)<BR>&nbsp;<BR>What is the two-letter country code for this unit?<BR>[Unknown]:cn(输入国家名字)<BR>Is CN=your name, OU=your organizaion, O="your organization name",L=your city name, ST=your province name, C=cn correct?<BR>[no]: yes<BR>&nbsp;<BR>3.&nbsp;&nbsp;&nbsp; 检查一个keystore:<BR>keytool -list -v -keystore keystore<BR>Enter keystore password:your password(输入密码)<BR>&nbsp;<BR>将显示keystore內容如:<BR>Keystore type: jks<BR>Keystore provider: SUN<BR>&nbsp;<BR>Your keystore contains 1 entry<BR>Alias name: yourname<BR>Creation date: Dec 20, 2001<BR>Entry type: keyEntry<BR>Certificate chain length: 1<BR>Certificate[1]:<BR>Owner: CN=yourname, OU=your organization, O="your organization name",<BR>L=your city name, ST=your province name, C=CN<BR>Issuer: CN=Duke, OU=Java Software, O="Sun Microsystems, Inc.", L=Palo Alto, ST=CA, C=US<BR>Serial number: 3c22adc1<BR>Valid from: Thu Dec 20 19:34:25 PST 2001 until: Thu Dec 27 19:34:25 PST 2001<BR>Certificate fingerprints:<BR>MD5: F1:5B:9B:A1:F7:16:CF:25:CF:F4:FF:35:3F:4C:9C:F0<BR>SHA1: B2:00:50:DD:B6:CC:35:66:21:45:0F:96:AA:AF:6A:3D:E4:03:7C:74<BR>&nbsp;<BR>3．输出keystore到一个文件:testkey:<BR>keytool -export -alias duke -keystore keystore -rfc -file testkey<BR>系统输出：Enter keystore password:your password(输入密码)<BR>Certificate stored in file <TESTKEY>&lt; td&gt;<BR>&nbsp;<BR>4．输入证书到一个新的truststore:<BR>keytool -import -alias dukecert -file testkey -keystore truststore <BR>Enter keystore password:your new password.(输入truststore新密码)<BR>&nbsp;<BR>&nbsp;<BR>5．检查truststore:<BR>keytool -list -v -keystore truststore <BR>系统将显示truststore的信息.<BR>&nbsp;<BR>现在可以用适当的keystore运行你的应用程序.如: <BR>java -Djavax.net.ssl.keyStore = keystore <BR>-Djavax.net.ssl.keyStorePassword=password Server<BR>&nbsp;<BR>和:<BR>&nbsp;java -Djavax.net.ssl.trustStore=truststore<BR>-Djavax.net.ssl.trustStorePassword=trustword Client<BR></FONT><img src ="http://www.blogjava.net/beyondduke/aggbug/18076.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/beyondduke/" target="_blank">beyondduke</a> 2005-11-04 09:21 <a href="http://www.blogjava.net/beyondduke/archive/2005/11/04/18076.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>