??xml version="1.0" encoding="utf-8" standalone="yes"?>精品乱子伦一区二区三区,日本精品视频一区二区三区,精品福利一区二区三区http://www.aygfsteel.com/wx886104/category/34069.htmlzh-cnSun, 12 May 2013 07:04:20 GMTSun, 12 May 2013 07:04:20 GMT60字W串转换成中文的ҎQ{Q?/title><link>http://www.aygfsteel.com/wx886104/archive/2013/05/12/399169.html</link><dc:creator>勒紧皮带向前?/dc:creator><author>勒紧皮带向前?/author><pubDate>Sun, 12 May 2013 06:46:00 GMT</pubDate><guid>http://www.aygfsteel.com/wx886104/archive/2013/05/12/399169.html</guid><wfw:comment>http://www.aygfsteel.com/wx886104/comments/399169.html</wfw:comment><comments>http://www.aygfsteel.com/wx886104/archive/2013/05/12/399169.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wx886104/comments/commentRss/399169.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wx886104/services/trackbacks/399169.html</trackback:ping><description><![CDATA[<div style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #3e81fa; "><div><h3><span style="font-size: 20px; font-family: 微Y雅黑, 黑体, Arial, Helvetica, sans-serif; "><strong style="background-color: #a0ffff; ">16q制字符串{?/strong>成中文方?</span>  </h3><p clearfix="" nbw-act="" fc06"="" style="zoom: 1; margin: 0px 0px 20px; padding: 0px; line-height: 20px; "><span style="float: left; "><span style="margin: 0px 2px; ">2006-12-28 13:25:49</span><span style="margin: 0px 2px; ">|  分类Q?/span> <a name="baidusnap0"></a><a m2a"="" title="Java~程" style="color: #000000; cursor: pointer; text-decoration: none; "><strong style="background-color: #ffff66; ">Java</strong>~程</a></span><span fc07="" ztag"="" style="float: right; "><span style="margin: 0px 2px; ">|</span><span fc03"="" id="$_fontswitch" style="position: relative; cursor: default; ">字号</span></span><span pnt="" fc03"="" id="$_blog_subscribe" style="cursor: pointer; float: right; "> <a style="cursor: pointer; ">订阅</a></span></p></div></div><div style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #3e81fa; "></div><div style="font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #3e81fa; "></div><div fc05="" fc11="" nbw-blog="" ztag"="" data-find="_10" style="line-height: 25px; word-wrap: break-word; margin: 15px 0px; padding-top: 5px; padding-bottom: 5px; overflow: hidden; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #3e81fa; "><table cellspacing="0" cellpadding="0" width="100%" border="0" style="line-height: 25px; background-color: #666699; width: 771px; background-position: initial initial; background-repeat: initial initial; "><tbody><tr><td style="border: #ece9d8; padding: 0in; background-color: transparent; "><table cellspacing="1" cellpadding="0" width="100%" border="0" style="line-height: 25px; width: 771px; "><tbody><tr><td style="border: #ffffff; padding: 3pt; background-color: white; "><p style="margin: 0in 0in 0pt; padding: 0px; "><span style="line-height: 21px; font-size: 8pt; ">现知道一?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">16</span><span style="line-height: 21px; font-size: 8pt; ">q制的字W串Q比如:</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">"6162B4F36364BCD2657CBAC366"</span><span style="line-height: 21px; font-size: 8pt; ">Q哪位高手能l一个将q个字符串{换成中文的方法啊Q我到百度上搜了半天也没搜到Q即使有也不?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><strong style="background-color: #ffff66; ">java</strong></span><span style="line-height: 21px; font-size: 8pt; ">Ҏ。哪位高抽出宝贵的时间帮忙解决一下啊Q万分感ȀQ!Q{换出来应该是六个字母Q?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">3</span><span style="line-height: 21px; font-size: 8pt; ">个中文,q有一个符P希望高手们把谜底揭开Q关键是写出实现ҎQ谢谢了Q!Q!Q!Q!Q!Q!Q!Q!Q!Q!Q!</span></p></td></tr></tbody></table><p style="margin: 0in 0in 0pt; padding: 0px; "></p></td></tr></tbody></table><p style="margin: 0in 0in 12pt; padding: 0px; "><a rel="nofollow" style="line-height: 21px; font-size: 8pt; font-family: Arial; "> </a></p><table cellspacing="0" cellpadding="0" width="100%" border="0" style="line-height: 25px; background-color: #dddddd; width: 771px; background-position: initial initial; background-repeat: initial initial; "><tbody><tr><td style="border: #ece9d8; padding: 0.75pt; background-color: transparent; "><table cellspacing="1" cellpadding="0" width="100%" border="0" style="line-height: 25px; width: 769px; "><tbody><tr><td style="border: #ffffff; padding: 3pt; background-color: transparent; "><table cellspacing="0" cellpadding="0" width="100%" border="0" style="line-height: 25px; width: 759px; "><tbody><tr><td width="100%" style="border: #ffffff; padding: 0in; width: 759px; background-color: transparent; "><table cellspacing="0" cellpadding="0" width="100%" border="0" style="line-height: 25px; width: 759px; "><tbody><tr><td width="97%" style="border: #ffffff; padding: 0in; width: 608px; background-color: transparent; "><p style="margin: 0in 0in 0pt; padding: 0px; "><strong><span style="line-height: 21px; font-size: 8pt; ">回复</span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">: </span></strong><strong><span style="line-height: 21px; font-size: 8pt; ">求教</span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">!</span></strong><strong><span style="line-height: 21px; font-size: 8pt; ">?/span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">!</span></strong><strong><span style="line-height: 21px; font-size: 8pt; ">哪位高手能将</span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">6162B4F36364BCD2657CBAC366</span></strong><strong><span style="line-height: 21px; font-size: 8pt; ">转换成中?/span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">!</span></strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "> <br /></span><span style="line-height: 21px; font-size: 8pt; ">?/span> <span style="line-height: 21px; font-size: 8pt; ">?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">: <a rel="nofollow" style="color: #000000; text-decoration: none; "><em><span style="color: #3e6b8a; ">ymy7100 </span></em><em></em></a>  <a rel="nofollow" style="color: #000000; text-decoration: none; "><span style="color: #3e6b8a; font-family: 宋体; ">短消?/span></a>   <br /></span><span style="line-height: 21px; font-size: 8pt; ">回复主题</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">: <a title="Posted by: ymy7100" rel="nofollow" style="color: #000000; text-decoration: none; "><span style="color: #3e6b8a; font-family: 宋体; ">求教</span><span style="color: #3e6b8a; ">!</span><span style="color: #3e6b8a; font-family: 宋体; ">?/span><span style="color: #3e6b8a; ">!</span><span style="color: #3e6b8a; font-family: 宋体; ">哪位高手能将</span><span style="color: #3e6b8a; ">6162B4F36364BCD2657CBAC366</span><span style="color: #3e6b8a; font-family: 宋体; ">转换成中?/span><span style="color: #3e6b8a; ">!</span></a></span></p></td><td nowrap="" width="1%" style="border: #ffffff; padding: 0in; width: 121px; background-color: transparent; "><p style="margin: 0in 0in 0pt; padding: 0px; "><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">2006-12-21 </span><span style="line-height: 21px; font-size: 8pt; ">下午</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">1:14  </span></p><p align="center" style="margin: 0in 0in 0pt; padding: 0px; text-align: center; "><span style="line-height: 21px; font-size: 8pt; ">回复</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "> 1 of 4</span></p></td><td width="1%" style="border: #ffffff; padding: 0in; width: 6px; background-color: transparent; "><p style="margin: 0in 0in 0pt; padding: 0px; "><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><a title="回复" rel="nofollow" style="color: #000000; text-decoration: none; "></a></span></p></td><td nowrap="" width="1%" style="border: #ffffff; padding: 0in; width: 24px; background-color: transparent; "><p style="margin: 0in 0in 0pt; padding: 0px; "><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><a title="回复" rel="nofollow" style="color: #000000; text-decoration: none; "><span style="color: #3e6b8a; font-family: 宋体; ">回复</span></a></span></p></td></tr></tbody></table><p style="margin: 0in 0in 0pt; padding: 0px; "></p></td></tr></tbody></table><p style="margin: 0in 0in 0pt; padding: 0px; "></p></td></tr></tbody></table><p style="margin: 0in 0in 0pt; padding: 0px; "></p><table cellspacing="0" cellpadding="0" width="100%" border="0" style="line-height: 25px; background-color: white; width: 769px; background-position: initial initial; background-repeat: initial initial; "><tbody><tr><td style="border: #ffffff; padding: 2.25pt; background-color: transparent; "><p style="margin: 0in 0in 0pt; padding: 0px; "><span style="line-height: 21px; font-size: 8pt; ">晕!</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><br /></span><span style="line-height: 21px; font-size: 8pt; ">没有高手吗?</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><br /></span><span style="line-height: 21px; font-size: 8pt; ">是因<a name="baidusnap6"></a><strong style="color: white; background-color: #00aa00; ">?/strong>别的公司开发的</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">delphi</span><span style="line-height: 21px; font-size: 8pt; ">E序要调用我们的</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><strong style="background-color: #ffff66; ">java</strong></span><span style="line-height: 21px; font-size: 8pt; ">E序Q其?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><strong style="background-color: #ffff66; ">java</strong></span><span style="line-height: 21px; font-size: 8pt; ">中要写个函数Q实现将他们传来的数据显C出来ƈ存到数据库,哪位大虾伸出援手啊!Q!Q!Q?/span></p></td></tr></tbody></table><p style="margin: 0in 0in 0pt; padding: 0px; "></p></td></tr></tbody></table><p style="margin: 0in 0in 0pt; padding: 0px; "><a rel="nofollow" style="line-height: 21px; font-size: 8pt; font-family: Arial; "> </a></p><table cellspacing="0" cellpadding="0" width="100%" border="0" data-find="_9" style="line-height: 25px; background-color: #dddddd; width: 771px; background-position: initial initial; background-repeat: initial initial; "><tbody data-find="_8"><tr data-find="_7"><td data-find="_6" style="border: #ece9d8; padding: 0.75pt; background-color: transparent; "><table cellspacing="1" cellpadding="0" width="100%" border="0" style="line-height: 25px; width: 769px; "><tbody><tr><td style="border: #ffffff; padding: 3pt; background-color: transparent; "><table cellspacing="0" cellpadding="0" width="100%" border="0" style="line-height: 25px; width: 759px; "><tbody><tr><td width="100%" style="border: #ffffff; padding: 0in; width: 759px; background-color: transparent; "><table cellspacing="0" cellpadding="0" width="100%" border="0" style="line-height: 25px; width: 759px; "><tbody><tr><td width="97%" style="border: #ffffff; padding: 0in; width: 608px; background-color: transparent; "><p style="margin: 0in 0in 0pt; padding: 0px; "><strong><span style="line-height: 21px; font-size: 8pt; ">回复</span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">: </span></strong><strong><span style="line-height: 21px; font-size: 8pt; ">求教</span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">!</span></strong><strong><span style="line-height: 21px; font-size: 8pt; ">?/span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">!</span></strong><strong><span style="line-height: 21px; font-size: 8pt; ">哪位高手能将</span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">6162B4F36364BCD2657CBAC366</span></strong><strong><span style="line-height: 21px; font-size: 8pt; ">转换成中?/span></strong><strong><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">!</span></strong> <span style="line-height: 21px; font-size: 8pt; color: red; font-family: Arial; ">[</span><span style="line-height: 21px; font-size: 8pt; color: red; ">得分</span><span style="line-height: 21px; font-size: 8pt; color: red; font-family: Arial; ">:50]</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "> <br /></span><span style="line-height: 21px; font-size: 8pt; ">?/span> <span style="line-height: 21px; font-size: 8pt; ">?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">: <a rel="nofollow" style="color: #000000; text-decoration: none; "><em><span style="color: #3e6b8a; ">rehte </span></em><em></em></a>  <a rel="nofollow" style="color: #000000; text-decoration: none; "><span style="color: #3e6b8a; font-family: 宋体; ">短消?/span></a>   <br /></span><span style="line-height: 21px; font-size: 8pt; ">回复主题</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">: <a title="Posted by: ymy7100" rel="nofollow" style="color: #000000; text-decoration: none; "><span style="color: #3e6b8a; font-family: 宋体; ">求教</span><span style="color: #3e6b8a; ">!</span><span style="color: #3e6b8a; font-family: 宋体; ">?/span><span style="color: #3e6b8a; ">!</span><span style="color: #3e6b8a; font-family: 宋体; ">哪位高手能将</span><span style="color: #3e6b8a; ">6162B4F36364BCD2657CBAC366</span><span style="color: #3e6b8a; font-family: 宋体; ">转换成中?/span><span style="color: #3e6b8a; ">!</span></a></span></p></td><td nowrap="" width="1%" style="border: #ffffff; padding: 0in; width: 121px; background-color: transparent; "><p style="margin: 0in 0in 0pt; padding: 0px; "><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">2006-12-21 </span><span style="line-height: 21px; font-size: 8pt; ">下午</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">2:42  </span></p><p align="center" style="margin: 0in 0in 0pt; padding: 0px; text-align: center; "><span style="line-height: 21px; font-size: 8pt; ">回复</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "> 2 of 4</span></p></td><td width="1%" style="border: #ffffff; padding: 0in; width: 6px; background-color: transparent; "><p style="margin: 0in 0in 0pt; padding: 0px; "><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><a title="回复" rel="nofollow" style="color: #000000; text-decoration: none; "></a></span></p></td><td nowrap="" width="1%" style="border: #ffffff; padding: 0in; width: 24px; background-color: transparent; "><p style="margin: 0in 0in 0pt; padding: 0px; "><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><a title="回复" rel="nofollow" style="color: #000000; text-decoration: none; "><span style="color: #3e6b8a; font-family: 宋体; ">回复</span></a></span></p></td></tr></tbody></table><p style="margin: 0in 0in 0pt; padding: 0px; "></p></td></tr></tbody></table><p style="margin: 0in 0in 0pt; padding: 0px; "></p></td></tr></tbody></table><p style="margin: 0in 0in 0pt; padding: 0px; "></p><table cellspacing="0" cellpadding="0" width="100%" border="0" data-find="_5" style="line-height: 25px; background-color: white; width: 769px; background-position: initial initial; background-repeat: initial initial; "><tbody data-find="_4"><tr data-find="_3"><td data-find="_2" style="border: #ffffff; padding: 2.25pt; background-color: transparent; "><p data-find="_1" style="margin: 0in 0in 0pt; padding: 0px; "><span style="line-height: 21px; font-size: 8pt; ">晕,帮帮?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><br /></span><span style="line-height: 21px; font-size: 8pt; ">应该是:</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">ab</span><span style="line-height: 21px; font-size: 8pt; ">?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">cd</span><span style="line-height: 21px; font-size: 8pt; ">?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">e|</span><span style="line-height: 21px; font-size: 8pt; ">?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">f<br /></span><span style="line-height: 21px; font-size: 8pt; ">首先要知道编码,中国<a name="baidusnap7"></a><strong style="color: white; background-color: #886800; ">汉字</strong>一般?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">GBK</span><span style="line-height: 21px; font-size: 8pt; ">或?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">gb2312</span><span style="line-height: 21px; font-size: 8pt; ">Q?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">gb2312</span><span style="line-height: 21px; font-size: 8pt; ">?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">GBK</span><span style="line-height: 21px; font-size: 8pt; ">的子集,因此安全赯使用</span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; ">GBK</span><span style="line-height: 21px; font-size: 8pt; ">一般就行了Q?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><br /><br />public class Decoder {<br />public static void main(String[]args){<br />String result=decodeString(args[0], "GBK");<br />System.out.println(result);<br />} <br />private static String decodeString(String string, String encoding) {<br />try {<br />byte[]data=string2Bytes(string);<br />return new String(data, encoding);<br />} catch (UnsupportedEncodingException ex) {<br />ex.printStackTrace();<br />return null;<br />}<br />} <br />private static byte[] string2Bytes(String string) {<br />int blen=string.length()/2;<br />byte[]data=new byte[blen];<br />for(int i=0;i<blen;i++){<br />String bStr=string.substring(2*i,2*(i+1));<br />data[i]=(byte)Integer.parseInt(bStr,16);<br />}<br />return data;<br />}<br />}<br /><br /></span><span style="line-height: 21px; font-size: 8pt; ">q行Q?/span><span style="line-height: 21px; font-size: 8pt; font-family: Arial; "><br /><strong style="background-color: #ffff66; ">java</strong> Decoder 6162B4F36364BCD2657CBAC366</span></p></td></tr></tbody></table></td></tr></tbody></table></div><img src ="http://www.aygfsteel.com/wx886104/aggbug/399169.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wx886104/" target="_blank">勒紧皮带向前?/a> 2013-05-12 14:46 <a href="http://www.aygfsteel.com/wx886104/archive/2013/05/12/399169.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA 取得当前目录的\??及PShttp://www.aygfsteel.com/wx886104/archive/2012/03/26/372680.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Mon, 26 Mar 2012 01:34:00 GMThttp://www.aygfsteel.com/wx886104/archive/2012/03/26/372680.htmlhttp://www.aygfsteel.com/wx886104/comments/372680.htmlhttp://www.aygfsteel.com/wx886104/archive/2012/03/26/372680.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/372680.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/372680.html阅读全文

]]>
axis安装与配|?/title><link>http://www.aygfsteel.com/wx886104/archive/2010/10/29/336492.html</link><dc:creator>勒紧皮带向前?/dc:creator><author>勒紧皮带向前?/author><pubDate>Fri, 29 Oct 2010 07:15:00 GMT</pubDate><guid>http://www.aygfsteel.com/wx886104/archive/2010/10/29/336492.html</guid><wfw:comment>http://www.aygfsteel.com/wx886104/comments/336492.html</wfw:comment><comments>http://www.aygfsteel.com/wx886104/archive/2010/10/29/336492.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wx886104/comments/commentRss/336492.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wx886104/services/trackbacks/336492.html</trackback:ping><description><![CDATA[     摘要: axis安装与配|时的一些问题和解决Ҏ  <a href='http://www.aygfsteel.com/wx886104/archive/2010/10/29/336492.html'>阅读全文</a><img src ="http://www.aygfsteel.com/wx886104/aggbug/336492.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wx886104/" target="_blank">勒紧皮带向前?/a> 2010-10-29 15:15 <a href="http://www.aygfsteel.com/wx886104/archive/2010/10/29/336492.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>解决 java.util.MissingResourceException: Can't find bundle for base name com...config, locale zh_CN 错误 http://www.aygfsteel.com/wx886104/archive/2010/10/27/336248.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Wed, 27 Oct 2010 01:37:00 GMThttp://www.aygfsteel.com/wx886104/archive/2010/10/27/336248.htmlhttp://www.aygfsteel.com/wx886104/comments/336248.htmlhttp://www.aygfsteel.com/wx886104/archive/2010/10/27/336248.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/336248.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/336248.html阅读全文

]]>
解决java.lang.UnsupportedClassVersionError问题http://www.aygfsteel.com/wx886104/archive/2010/10/26/336207.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Tue, 26 Oct 2010 11:21:00 GMThttp://www.aygfsteel.com/wx886104/archive/2010/10/26/336207.htmlhttp://www.aygfsteel.com/wx886104/comments/336207.htmlhttp://www.aygfsteel.com/wx886104/archive/2010/10/26/336207.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/336207.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/336207.html  阅读全文

]]>
java 加密解密工具c?/title><link>http://www.aygfsteel.com/wx886104/archive/2009/04/30/268360.html</link><dc:creator>勒紧皮带向前?/dc:creator><author>勒紧皮带向前?/author><pubDate>Thu, 30 Apr 2009 07:07:00 GMT</pubDate><guid>http://www.aygfsteel.com/wx886104/archive/2009/04/30/268360.html</guid><wfw:comment>http://www.aygfsteel.com/wx886104/comments/268360.html</wfw:comment><comments>http://www.aygfsteel.com/wx886104/archive/2009/04/30/268360.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wx886104/comments/commentRss/268360.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wx886104/services/trackbacks/268360.html</trackback:ping><description><![CDATA[<div style="border-bottom: #cccccc 1px solid; border-left: #cccccc 1px solid; padding-bottom: 4px; background-color: #eeeeee; padding-left: 4px; width: 98%; padding-right: 5px; font-size: 13px; word-break: break-all; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; padding-top: 4px"><span style="color: #008080"> 1</span><img id="Codehighlighter1_0_62_Open_Image" onclick="this.style.display='none'; Codehighlighter1_0_62_Open_Text.style.display='none'; Codehighlighter1_0_62_Closed_Image.style.display='inline'; Codehighlighter1_0_62_Closed_Text.style.display='inline';" align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" alt="" /><img style="display: none" id="Codehighlighter1_0_62_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_0_62_Closed_Text.style.display='none'; Codehighlighter1_0_62_Open_Image.style.display='inline'; Codehighlighter1_0_62_Open_Text.style.display='inline';" align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" alt="" /><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_0_62_Closed_Text">/** */</span><span id="Codehighlighter1_0_62_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000">  <br /> </span><span style="color: #008080"> 2</span><span style="color: #008000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" /> * </span><span style="color: #808080">@param</span><span style="color: #008000"> input  <br /> </span><span style="color: #008080"> 3</span><span style="color: #008000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" /> * </span><span style="color: #808080">@return</span><span style="color: #008000">  <br /> </span><span style="color: #008080"> 4</span><span style="color: #008000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" /> * </span><span style="color: #808080">@throws</span><span style="color: #008000"> Exception  <br /> </span><span style="color: #008080"> 5</span><span style="color: #008000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000">  <br /> </span><span style="color: #008080"> 6</span><span style="color: #000000"><img id="Codehighlighter1_130_648_Open_Image" onclick="this.style.display='none'; Codehighlighter1_130_648_Open_Text.style.display='none'; Codehighlighter1_130_648_Closed_Image.style.display='inline'; Codehighlighter1_130_648_Closed_Text.style.display='inline';" align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" alt="" /><img style="display: none" id="Codehighlighter1_130_648_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_130_648_Closed_Text.style.display='none'; Codehighlighter1_130_648_Open_Image.style.display='inline'; Codehighlighter1_130_648_Open_Text.style.display='inline';" align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> String encryptData(String input) </span><span style="color: #0000ff">throws</span><span style="color: #000000"> Exception </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_130_648_Closed_Text"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_130_648_Open_Text"><span style="color: #000000">{   <br /> </span><span style="color: #008080"> 7</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    SecureRandom sr </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SecureRandom();   <br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">byte</span><span style="color: #000000"> rawKeyData[] </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">ABCDEFGH</span><span style="color: #000000">"</span><span style="color: #000000">.getBytes();   <br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    DESKeySpec dks </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> DESKeySpec(rawKeyData);   <br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">12</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    SecretKeyFactory keyFactory </span><span style="color: #000000">=</span><span style="color: #000000"> SecretKeyFactory.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">DES</span><span style="color: #000000">"</span><span style="color: #000000">);   <br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    SecretKey key </span><span style="color: #000000">=</span><span style="color: #000000"> keyFactory.generateSecret(dks);   <br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    Cipher c </span><span style="color: #000000">=</span><span style="color: #000000"> Cipher.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">DES</span><span style="color: #000000">"</span><span style="color: #000000">);   <br /> </span><span style="color: #008080">16</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    c.init(Cipher.ENCRYPT_MODE, key, sr);   <br /> </span><span style="color: #008080">17</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] cipherByte </span><span style="color: #000000">=</span><span style="color: #000000"> c.doFinal(input.getBytes());   <br /> </span><span style="color: #008080">18</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    String dec </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> BASE64Encoder().encode(cipherByte);   <br /> </span><span style="color: #008080">19</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> dec;   <br /> </span><span style="color: #008080">20</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">21</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000">   <br /> </span><span style="color: #008080">22</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" />  <br /> </span><span style="color: #008080">23</span><span style="color: #000000"><img id="Codehighlighter1_656_718_Open_Image" onclick="this.style.display='none'; Codehighlighter1_656_718_Open_Text.style.display='none'; Codehighlighter1_656_718_Closed_Image.style.display='inline'; Codehighlighter1_656_718_Closed_Text.style.display='inline';" align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" alt="" /><img style="display: none" id="Codehighlighter1_656_718_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_656_718_Closed_Text.style.display='none'; Codehighlighter1_656_718_Open_Image.style.display='inline'; Codehighlighter1_656_718_Open_Text.style.display='inline';" align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" alt="" /></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_656_718_Closed_Text">/** */</span><span id="Codehighlighter1_656_718_Open_Text"><span style="color: #008000">/**</span><span style="color: #008000">  <br /> </span><span style="color: #008080">24</span><span style="color: #008000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" /> * </span><span style="color: #808080">@param</span><span style="color: #008000"> input  <br /> </span><span style="color: #008080">25</span><span style="color: #008000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" /> * </span><span style="color: #808080">@return</span><span style="color: #008000">  <br /> </span><span style="color: #008080">26</span><span style="color: #008000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" /> * </span><span style="color: #808080">@throws</span><span style="color: #008000"> Exception  <br /> </span><span style="color: #008080">27</span><span style="color: #008000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" /> </span><span style="color: #008000">*/</span></span><span style="color: #000000">  <br /> </span><span style="color: #008080">28</span><span style="color: #000000"><img id="Codehighlighter1_786_1318_Open_Image" onclick="this.style.display='none'; Codehighlighter1_786_1318_Open_Text.style.display='none'; Codehighlighter1_786_1318_Closed_Image.style.display='inline'; Codehighlighter1_786_1318_Closed_Text.style.display='inline';" align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" alt="" /><img style="display: none" id="Codehighlighter1_786_1318_Closed_Image" onclick="this.style.display='none'; Codehighlighter1_786_1318_Closed_Text.style.display='none'; Codehighlighter1_786_1318_Open_Image.style.display='inline'; Codehighlighter1_786_1318_Open_Text.style.display='inline';" align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> String decryptData(String input) </span><span style="color: #0000ff">throws</span><span style="color: #000000"> Exception </span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="Codehighlighter1_786_1318_Closed_Text"><img src="http://www.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_786_1318_Open_Text"><span style="color: #000000">{   <br /> </span><span style="color: #008080">29</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] dec </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> BASE64Decoder().decodeBuffer(input);   <br /> </span><span style="color: #008080">30</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">31</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    SecureRandom sr </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> SecureRandom();   <br /> </span><span style="color: #008080">32</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">byte</span><span style="color: #000000"> rawKeyData[] </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #000000">"</span><span style="color: #000000">ABCDEFGH</span><span style="color: #000000">"</span><span style="color: #000000">.getBytes();   <br /> </span><span style="color: #008080">33</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">34</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    DESKeySpec dks </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> DESKeySpec(rawKeyData);   <br /> </span><span style="color: #008080">35</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">36</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    SecretKeyFactory keyFactory </span><span style="color: #000000">=</span><span style="color: #000000"> SecretKeyFactory.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">DES</span><span style="color: #000000">"</span><span style="color: #000000">);   <br /> </span><span style="color: #008080">37</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">38</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    SecretKey key </span><span style="color: #000000">=</span><span style="color: #000000"> keyFactory.generateSecret(dks);   <br /> </span><span style="color: #008080">39</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">40</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    Cipher c </span><span style="color: #000000">=</span><span style="color: #000000"> Cipher.getInstance(</span><span style="color: #000000">"</span><span style="color: #000000">DES</span><span style="color: #000000">"</span><span style="color: #000000">);   <br /> </span><span style="color: #008080">41</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    c.init(Cipher.DECRYPT_MODE, key, sr);   <br /> </span><span style="color: #008080">42</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">byte</span><span style="color: #000000">[] clearByte </span><span style="color: #000000">=</span><span style="color: #000000"> c.doFinal(dec);   <br /> </span><span style="color: #008080">43</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">44</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />    </span><span style="color: #0000ff">return</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> String(clearByte);   <br /> </span><span style="color: #008080">45</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" alt="" />  <br /> </span><span style="color: #008080">46</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" alt="" />}</span></span><span style="color: #000000">  <br /> </span><span style="color: #008080">47</span><span style="color: #000000"><img align="top" src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" alt="" /></span></div> 注:转自 http://jlusdy.javaeye.com/blog/145803 <img src ="http://www.aygfsteel.com/wx886104/aggbug/268360.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wx886104/" target="_blank">勒紧皮带向前?/a> 2009-04-30 15:07 <a href="http://www.aygfsteel.com/wx886104/archive/2009/04/30/268360.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>js 日期控ghttp://www.aygfsteel.com/wx886104/archive/2009/03/27/262465.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Fri, 27 Mar 2009 09:03:00 GMThttp://www.aygfsteel.com/wx886104/archive/2009/03/27/262465.htmlhttp://www.aygfsteel.com/wx886104/comments/262465.htmlhttp://www.aygfsteel.com/wx886104/archive/2009/03/27/262465.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/262465.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/262465.html阅读全文

]]>
初用org.apache.commons.beanutils.ConvertUtils http://www.aygfsteel.com/wx886104/archive/2009/03/04/257710.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Wed, 04 Mar 2009 02:36:00 GMThttp://www.aygfsteel.com/wx886104/archive/2009/03/04/257710.htmlhttp://www.aygfsteel.com/wx886104/comments/257710.htmlhttp://www.aygfsteel.com/wx886104/archive/2009/03/04/257710.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/257710.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/257710.htmlConvertUtilsQ这个工L的职能是在字W串和指定类型的实例之间q行转换?

 

 

目前支持的类型有Q?

 

 

  • java.lang.BigDecimal

     

  • java.lang.BigInteger

     

  • boolean and java.lang.Boolean

     

  • byte and java.lang.Byte

     

  • char and java.lang.Character

     

  • java.lang.Class

     

  • double and java.lang.Double

     

  • float and java.lang.Float

     

  • int and java.lang.Integer

     

  • long and java.lang.Long

     

  • short and java.lang.Short

     

  • java.lang.String

     

  • java.io.File

     

  • java.net.URL

     

  • java.sql.Date

     

  • java.sql.Time

     

  • java.sql.Timestamp

     

M提供两类功能Q?

 

 

1.         字W串转换为指定类型;

 

 

2.         注册、注销和查询类型{换器Q?/font>

convert(java.lang.Object value)

Q意的实例转变?font face='"Times' New Roman">StringQ用法非常简单。在试的过E中Q感觉与调用实例上的toString()Ҏ的效果一P不知道是不是在这个方法内仅仅是调用了传入实例?font face='"Times' New Roman">toString()Ҏ?/font>

ps:需要读源代码才能清楚?/font>

convert(java.lang.String value, java.lang.Class clazz)

 

字W串value转换?font face='"Times' New Roman">clazz的一个实例;如果p|的话Q就?font face='"Times' New Roman">String的Ş式返?font face='"Times' New Roman">value?

 

 

convert(java.lang.String[] values, java.lang.Class clazz)

 

q个Ҏ是对前一Ҏ的加强版Q将数组中的每个value都进行{换,最后以Objectq回。(数组也是Object啊)

 

 

deregister()?a href_cetemp='http://www.itepub.net/html/kaifajingcui/Java/2006/0514/"file:///F:/software/apache/commons/commons-beanutils-1.7.0/docs/api/org/apache/commons/beanutils/ConvertUtils.html#deregister()"'>deregister(java.lang.Class clazz)

注销转换器,前者将所有的转换器注销掉,后者只注销对应?font face='"Times' New Roman">clazz的{换器。注销在这里不是彻底删除了Q而是{换器变ؓ默认的{换器Q?font face='"Times' New Roman">apache commons提供的)?/font>

lookup(java.lang.Class clazz)

获取指定cdclazz的{换器.

register(Converter converter, java.lang.Class clazz)

为指定类?font face='"Times' New Roman">clazz注册转换?font face='"Times' New Roman">converter。如?font face='"Times' New Roman">clazz已经存在一个对应的转换器,那么converterQ将覆盖原来的{换器。也是_我们可以?font face='"Times' New Roman">String,Double创徏自定义的cd转换器,q在注册后进行用?/font>

ps:apache的类定义明确Q描q非常清楚,所以就不脓Z子了。当然这只是到达可以正常使用的阶D,如果要进行改造或者创qConvertUtilsQ那可能需要更多的旉Q因要去参?font face='"Times' New Roman">ConvertUtilsBeanQ这里就不详qC?br />
以下Z用convertUtils的一个DATEcd的例子(该例子来源于学堂视屏)
1.定义converter

 1package com.bjsxt.oa.web;
 2
 3import java.text.ParseException;
 4import java.text.SimpleDateFormat;
 5import java.util.Date;
 6
 7import org.apache.commons.beanutils.Converter;
 8
 9public class UtilDateConverter implements Converter {
10    
11    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
12
13    public Object convert(Class type, Object value) {
14        if (value == null{
15            return value;
16        }

17        if (value instanceof Date) {
18            return value;
19        }

20        if (value instanceof String) {
21            try {
22                return format.parse((String)value);
23            }
 catch (ParseException e) {
24                e.printStackTrace();
25            }

26        }

27        return null;
28    }

29
30}

31
2.使用convertUilts注册converter
 1package com.bjsxt.oa.web;
 2
 3import java.util.Date;
 4
 5import javax.servlet.ServletException;
 6import javax.servlet.http.HttpServlet;
 7
 8import org.apache.commons.beanutils.ConvertUtils;
 9
10public class UtilDateConverterInitServlet extends HttpServlet {
11
12    @Override
13    public void init() throws ServletException {
14         ConvertUtils.register(new UtilDateConverter(), Date.class);
15    }

16
17}

18
3.在web.xml中配|servlet
1 <servlet>
2    <servlet-name>utilDateConverter</servlet-name>
3    <servlet-class>com.bjsxt.oa.web.UtilDateConverterInitServlet</servlet-class>
4    <load-on-startup>3</load-on-startup>
5  </servlet>  


]]>
org.apache.commons.beanutils.BeanUtils介绍http://www.aygfsteel.com/wx886104/archive/2009/03/04/257699.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Wed, 04 Mar 2009 01:53:00 GMThttp://www.aygfsteel.com/wx886104/archive/2009/03/04/257699.htmlhttp://www.aygfsteel.com/wx886104/comments/257699.htmlhttp://www.aygfsteel.com/wx886104/archive/2009/03/04/257699.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/257699.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/257699.htmlorg.apache.commons.beanutils.BeanUtils
 
一、简介:

BeanUtils提供?Java反射和自省API的包装。其主要目的是利用反机制对JavaBean的属性进行处理。我们知道,一个JavaBean通常包含了大量的属性,?多情况下Q对JavaBean的处理导致大量get/set代码堆积Q增加了代码长度和阅M码的隑ֺ?br />
二、用法:

BeanUtils是这个包里比较常用的一个工LQ这里只介绍它的copyProperties()Ҏ。该Ҏ定义如下Q?br />

public static void copyProperties(java.lang.Object dest,java.lang.Object orig)
    throws java.lang.IllegalAccessException,
           java.lang.reflect.InvocationTargetException


?果你有两个具有很多相同属性的JavaBeanQ一个很常见的情况就是Struts里的PO对象Q持久对象)和对应的ActionFormQ例?Teacher和TeacherForm。我们一般会在Action里从ActionForm构造一个PO对象Q传l的方式是用类g面的语句对属性?个赋|

//得到TeacherForm
TeacherForm teacherForm=(TeacherForm)form;
//构造Teacher对象
Teacher teacher=new Teacher();
//赋?br /> teacher.setName(teacherForm.getName());
teacher.setAge(teacherForm.getAge());
teacher.setGender(teacherForm.getGender());
teacher.setMajor(teacherForm.getMajor());
teacher.setDepartment(teacherForm.getDepartment());

//持久化Teacher对象到数据库
HibernateDAO=;
HibernateDAO.save(teacher);

而用BeanUtils后,代码大大改观了Q如下所C:
//得到TeacherForm
TeacherForm teacherForm=(TeacherForm)form;
//构造Teacher对象
Teacher teacher=new Teacher();
//赋?br /> BeanUtils.copyProperties(teacher,teacherForm);
//持久化Teacher对象到数据库
HibernateDAO=;
HibernateDAO.save(teacher);


?果Teacher和TeacherForm间存在名UC相同的属性,则BeanUtils不对q些属性进行处理,需要程序员手动处理。例?Teacher包含modifyDateQ该属性记录最后修Ҏ期,不需要用户在界面中输入)属性而TeacherForm无此属性,那么在上面代码的 copyProperties()后还要加上一句:

teacher.setModifyDate(new Date());


?么样Q很方便吧!除BeanUtils外还有一个名为PropertyUtils的工LQ它也提供copyProperties()ҎQ作用与 BeanUtils的同名方法十分相|主要的区别在于后者提供类型{换功能,卛_C个JavaBean的同名属性ؓ不同cdӞ在支持的数据cd范围 内进行{换,而前者不支持q个功能Q但是速度会更快一些。BeanUtils支持的{换类型如下:

      * java.lang.BigDecimal
      * java.lang.BigInteger
      * boolean and java.lang.Boolean
      * byte and java.lang.Byte
      * char and java.lang.Character
      * java.lang.Class
      * double and java.lang.Double
      * float and java.lang.Float
      * int and java.lang.Integer
      * long and java.lang.Long
      * short and java.lang.Short
      * java.lang.String
      * java.sql.Date
      * java.sql.Time
      * java.sql.Timestamp


q里要注意一点,java.util.Date是不被支持的Q而它的子cjava.sql.Date是被支持的。因此如果对象包含时间类型的属性,且希望被转换的时候,一定要使用java.sql.Datecd。否则在转换时会提示argument mistype异常?br />
三、优~点Q?br />
Apache Jakarta Commons目非常有用。我曑֜许多不同的项目上或直接或间接C用各U流行的commonslg。其中的一个强大的lg是BeanUtils。我 说明如何用BeanUtilslocal实体bean转换为对应的value 对象Q?br />

BeanUtils.copyProperties(aValue, aLocal)


?面的代码从aLocal对象复制属性到aValue对象。它相当单!它不localQ或对应的valueQ对象有多少个属性,只管q行复制。我们假?local对象?00个属性。上面的代码使我们可以无需键入臛_100行的冗长、容易出错和反复的get和setҎ调用。这太棒了!太强大了Q太有用 了!

现在Q还有一个坏消息Q用BeanUtils的成本惊人地昂贵Q我做了一个简单的试QBeanUtils所p的时间要过取数 据、将其复制到对应?value对象Q通过手动调用get和setҎQ,以及通过串行化将其返回到q程的客h的时间d。所以要心使用q种威力Q?
该文章的原文地址为:http://lifejava.spaces.live.com/Blog/cns!A666C33543221640!158.entry


]]>
Struts 2.0整合Hibernate 3.2开发注册登录系l??http://www.aygfsteel.com/wx886104/archive/2009/02/09/253883.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Mon, 09 Feb 2009 04:08:00 GMThttp://www.aygfsteel.com/wx886104/archive/2009/02/09/253883.htmlhttp://www.aygfsteel.com/wx886104/comments/253883.htmlhttp://www.aygfsteel.com/wx886104/archive/2009/02/09/253883.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/253883.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/253883.html阅读全文

]]>
Struts 2.0整合Hibernate 3.2开发注册登录系l??http://www.aygfsteel.com/wx886104/archive/2009/02/09/253881.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Mon, 09 Feb 2009 04:07:00 GMThttp://www.aygfsteel.com/wx886104/archive/2009/02/09/253881.htmlhttp://www.aygfsteel.com/wx886104/comments/253881.htmlhttp://www.aygfsteel.com/wx886104/archive/2009/02/09/253881.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/253881.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/253881.html阅读全文

]]>
ThreadLocalhttp://www.aygfsteel.com/wx886104/archive/2009/01/12/250929.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Mon, 12 Jan 2009 02:23:00 GMThttp://www.aygfsteel.com/wx886104/archive/2009/01/12/250929.htmlhttp://www.aygfsteel.com/wx886104/comments/250929.htmlhttp://www.aygfsteel.com/wx886104/archive/2009/01/12/250929.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/250929.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/250929.html什么是ThreadLocalQ?/strong>

֐思义它是local variableQ线E局部变量)。它的功用非常简单,是为每一个用该变量的线E都提供一个变量值的副本Q是每一个线E都可以独立地改变自q副本Q而不会和其它U程的副本冲H。从U程的角度看Q就好像每一个线E都完全拥有该变量?/p>

使用场景

  1. To keep state with a thread (user-id, transaction-id, logging-id)
  2. To cache objects which you need frequently

ThreadLocalc?/strong>

?主要由四个方法组成initialValue()Qget()Qset(T)Qremove()Q其中值得注意的是initialValue()Q该Ҏ 是一个protected的方法,昄是ؓ了子c重写而特意实现的。该Ҏq回当前U程在该U程局部变量的初始|q个Ҏ是一个gq调用方法,在一个线 E第1ơ调用get()或者set(Object)时才执行Qƈ且仅执行1ơ。ThreadLocal中的实实现直接q回一个nullQ?/p>

ThreadLocal的原?/p>

ThreadLocal是如何做Cؓ每一个线E维护变量的副本的呢Q其实实现的思\很简单,在ThreadLocalcM有一个MapQ用于存储每一个线E的变量的副本。比如下面的CZ实现Q?/p>

public class ThreadLocal
{
private Map values = Collections.synchronizedMap(new HashMap());
public Object get()
{
Thread curThread = Thread.currentThread();
Object o = values.get(curThread);
if (o == null && !values.containsKey(curThread))
{
o = initialValue();
values.put(curThread, o);
}
return o;
}

 public void set(Object newValue)
{
values.put(Thread.currentThread(), newValue);
}

 public Object initialValue()
{
return null;
}
}

ThreadLocal 的?/strong>

使用Ҏ一Q?/p>

Hibernate的文档时看到了关于ThreadLocal理多线E访问的部分。具体代码如?

1.  public static final ThreadLocal session = new ThreadLocal();
2.  public static Session currentSession() {
3.      Session s = (Session)session.get();
4.      //open a new session,if this session has none
5.   if(s == null){
6.      s = sessionFactory.openSession();
7.      session.set(s);
8.   }
      return s;
9. }

我们逐行分析
1?初始化一个ThreadLocal对象QThreadLocal有三个成员方?get()、set()、initialvalue()?
    如果不初始化initialvalueQ则initialvalueq回null?
3?session的getҎ当前U程q回其对应的U程内部变量Q也是我们需要的net.sf.hibernate.SessionQ相当于对应每个数据 库连接).多线E情况下׃n数据库链接是不安全的。ThreadLocal保证了每个线E都有自qsQ数据库q接Q?
5。如果是该线E初ơ访问,自然QsQ数据库q接Q会是nullQ接着创徏一个SessionQ具体就是行6?
6。创Z个数据库q接实例 s
7。保存该数据库连接s到ThreadLocal中?
8。如果当前线E已l访问过数据库了Q则从session中get()可以获取该U程上次获取q的q接实例



以上转自 榄?nbsp; http://hi.baidu.com/mojiedao/blog/item/0ceeab99e7a0ad086f068c09.html



]]>
pager-taglib的安装和使用http://www.aygfsteel.com/wx886104/archive/2008/12/29/248944.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Mon, 29 Dec 2008 08:45:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/12/29/248944.htmlhttp://www.aygfsteel.com/wx886104/comments/248944.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/12/29/248944.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/248944.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/248944.html 2、在JSP面中用taglib指o引入pager-taglib标签?br /> 3、用pager-taglib标签库进行分处?br />
pg:pager【这个标{来设|分늚M参数】重要参数说明:
    url:分页的链接根地址Qpager标签会在q个链接的基上附加分参?br />     items:总记录数Qpager标签正是Ҏq个值来计算分页参数?br />     maxPageItems:每页昄的行敎ͼ默认?0
    maxIndexPages:在@环输出页码的时候,最大输出多个늠Q默认是10
    
pg:first【第一늚标签】重要参数说明:
    export变量的意义:
    pageUrl - 分页链接URL地址Q最重要的export参数Q?br />     pageNumber - 늠
    firstItem - 首页W一行的索引?br />     lastItem - 首页最后一行的索引?br />     
pg:pre【上一|{】重要参数说明:
    export变量的意义:
    pageUrl - 分页链接URL地址Q最重要的export参数Q?br />     pageNumber - 늠
    firstItem - 前页W一行的索引?br />     lastItem - 前页最后一行的索引?br />
pg:next【下一|{】重要参数说明:
    export变量的意义:
    pageUrl - 分页链接URL地址Q最重要的export参数Q?br />     pageNumber - 늠
    firstItem - 下页W一行的索引?br />     lastItem - 下页最后一行的索引?br />     
pg:last重要参数说明Q?br />     export变量的意义:
    pageUrl - 分页链接URL地址Q最重要的export参数Q?br />     pageNumber - 늠
    firstItem - NW一行的索引?br />     lastItem - N最后一行的索引?br />     
pg:pages【这个标{来@环输出页码信息】重要参数说明:
    export变量的意义:
    pageUrl - 分页链接URL地址Q最重要的export参数Q?br />     pageNumber - 늠
    firstItem - pageNumberq个늠指定的那一늚W一行的索引?br />     lastItem - pageNumberq个늠指定的那一늚最后一行的索引?br />

pager-taglib-2.0下蝲
http://www.aygfsteel.com/Files/wx886104/pager-taglib-2.0.rar


]]>
java--国际?/title><link>http://www.aygfsteel.com/wx886104/archive/2008/12/15/246314.html</link><dc:creator>勒紧皮带向前?/dc:creator><author>勒紧皮带向前?/author><pubDate>Mon, 15 Dec 2008 01:44:00 GMT</pubDate><guid>http://www.aygfsteel.com/wx886104/archive/2008/12/15/246314.html</guid><wfw:comment>http://www.aygfsteel.com/wx886104/comments/246314.html</wfw:comment><comments>http://www.aygfsteel.com/wx886104/archive/2008/12/15/246314.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wx886104/comments/commentRss/246314.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wx886104/services/trackbacks/246314.html</trackback:ping><description><![CDATA[<p>1、了解缺省Locale是由操作pȝ军_的,Locale是由语言和国家代码组?/p> <p>2、国际化资源文g是由baseName+localel成Q如QMessageBundle_en_US.properties<br /> baseName是Q意合法的文g?/p> <p>3、native2ascii命o的位|和用法<br />  * 位置QJAVA_HOME/bin<br />  * 使用native2ascii.exe  o.properties MessagesBundle_zh_CN.properties</p> 例:<br /> <div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #008080"> 1</span><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><span style="color: #0000ff">package</span><span style="color: #000000"> com.bjsxt.i18n;<br /> </span><span style="color: #008080"> 2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 3</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.text.MessageFormat;<br /> </span><span style="color: #008080"> 4</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.Locale;<br /> </span><span style="color: #008080"> 5</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="color: #0000ff">import</span><span style="color: #000000"> java.util.ResourceBundle;<br /> </span><span style="color: #008080"> 6</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 7</span><span style="color: #000000"><img id="Codehighlighter1_140_959_Open_Image" onclick="this.style.display='none'; Codehighlighter1_140_959_Open_Text.style.display='none'; Codehighlighter1_140_959_Closed_Image.style.display='inline'; Codehighlighter1_140_959_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_140_959_Closed_Image" style="display: none; width: 11px; height: 16px" onclick="this.style.display='none'; Codehighlighter1_140_959_Closed_Text.style.display='none'; Codehighlighter1_140_959_Open_Image.style.display='inline'; Codehighlighter1_140_959_Open_Text.style.display='inline';" height="16" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" width="11" align="top" alt="" /></span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">class</span><span style="color: #000000"> I18nSample </span><span id="Codehighlighter1_140_959_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.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_140_959_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080"> 8</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /><br /> </span><span style="color: #008080"> 9</span><span style="color: #000000"><img id="Codehighlighter1_183_957_Open_Image" onclick="this.style.display='none'; Codehighlighter1_183_957_Open_Text.style.display='none'; Codehighlighter1_183_957_Closed_Image.style.display='inline'; Codehighlighter1_183_957_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_183_957_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_183_957_Closed_Text.style.display='none'; Codehighlighter1_183_957_Open_Image.style.display='inline'; Codehighlighter1_183_957_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" />    </span><span style="color: #0000ff">public</span><span style="color: #000000"> </span><span style="color: #0000ff">static</span><span style="color: #000000"> </span><span style="color: #0000ff">void</span><span style="color: #000000"> main(String[] args) </span><span id="Codehighlighter1_183_957_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.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_183_957_Open_Text"><span style="color: #000000">{<br /> </span><span style="color: #008080">10</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> </span><span style="color: #008080">11</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        Locale defaultLocale </span><span style="color: #000000">=</span><span style="color: #000000"> Locale.getDefault();</span><span style="color: #008000">//</span><span style="color: #008000">获取默认的本地化</span><span style="color: #008000"><br /> </span><span style="color: #008080">12</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">default country=</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> defaultLocale.getCountry());<br /> </span><span style="color: #008080">13</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        System.out.println(</span><span style="color: #000000">"</span><span style="color: #000000">default language=</span><span style="color: #000000">"</span><span style="color: #000000"> </span><span style="color: #000000">+</span><span style="color: #000000"> defaultLocale.getLanguage());<br /> </span><span style="color: #008080">14</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> </span><span style="color: #008080">15</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000">Locale currentLocale = new Locale("en", "US");</span><span style="color: #008000">//</span><span style="color: #008000">通过初始化指定语a和国际本地化<br /> </span><span style="color: #008080">16</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000">Locale currentLocale = new Locale("zh", "CN");</span><span style="color: #008000"><br /> </span><span style="color: #008080">17</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        <br /> </span><span style="color: #008080">18</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        Locale currentLocale </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> Locale(</span><span style="color: #000000">"</span><span style="color: #000000">ja</span><span style="color: #000000">"</span><span style="color: #000000">, </span><span style="color: #000000">"</span><span style="color: #000000">JP</span><span style="color: #000000">"</span><span style="color: #000000">);<br /> </span><span style="color: #008080">19</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        <br /> </span><span style="color: #008080">20</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        ResourceBundle rb </span><span style="color: #000000">=</span><span style="color: #000000"> ResourceBundle.getBundle(</span><span style="color: #000000">"</span><span style="color: #000000">res.MessagesBundle</span><span style="color: #000000">"</span><span style="color: #000000">, currentLocale);</span><span style="color: #008000">//</span><span style="color: #008000">获取本地化配|?br /> </span><span style="color: #008080">21</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000">System.out.println(rb.getString("k1"));</span><span style="color: #008000">//</span><span style="color: #008000">通过配置文g中的key昄<br /> </span><span style="color: #008080">22</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000">System.out.println(rb.getString("k2"));</span><span style="color: #008000"><br /> </span><span style="color: #008080">23</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" /></span><span style="color: #000000">        <br /> </span><span style="color: #008080">24</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        MessageFormat mf </span><span style="color: #000000">=</span><span style="color: #000000"> </span><span style="color: #0000ff">new</span><span style="color: #000000"> MessageFormat(rb.getString(</span><span style="color: #000000">"</span><span style="color: #000000">k1</span><span style="color: #000000">"</span><span style="color: #000000">));</span><span style="color: #008000">//</span><span style="color: #008000">通过站位W显C指定的信息</span><span style="color: #008000"><br /> </span><span style="color: #008080">25</span><span style="color: #008000"><img id="Codehighlighter1_882_888_Open_Image" onclick="this.style.display='none'; Codehighlighter1_882_888_Open_Text.style.display='none'; Codehighlighter1_882_888_Closed_Image.style.display='inline'; Codehighlighter1_882_888_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_882_888_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_882_888_Closed_Text.style.display='none'; Codehighlighter1_882_888_Open_Image.style.display='inline'; Codehighlighter1_882_888_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" alt="" /></span><span style="color: #000000">        System.out.println(mf.format(</span><span style="color: #0000ff">new</span><span style="color: #000000"> Object[]</span><span id="Codehighlighter1_882_888_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.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_882_888_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">"</span><span style="color: #000000">Tom</span><span style="color: #000000">"</span><span style="color: #000000">}</span></span><span style="color: #000000">));</span><span style="color: #008000">//</span><span style="color: #008000">对占位符填充<br /> </span><span style="color: #008080">26</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/InBlock.gif" align="top" alt="" />        </span><span style="color: #008000">//</span><span style="color: #008000">System.out.println(mf.format(new Object[]{"张三"}));</span><span style="color: #008000"><br /> </span><span style="color: #008080">27</span><span style="color: #008000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" alt="" /></span><span style="color: #000000">    }</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">28</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" alt="" />}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">29</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> o.properties文g<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_6_8_Open_Image" onclick="this.style.display='none'; Codehighlighter1_6_8_Open_Text.style.display='none'; Codehighlighter1_6_8_Closed_Image.style.display='inline'; Codehighlighter1_6_8_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_6_8_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_6_8_Closed_Text.style.display='none'; Codehighlighter1_6_8_Open_Image.style.display='inline'; Codehighlighter1_6_8_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span style="color: #000000">k1</span><span style="color: #000000">=</span><span style="color: #000000">你好,</span><span id="Codehighlighter1_6_8_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.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_6_8_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />k2</span><span style="color: #000000">=</span><span style="color: #000000">再见</span></div> ~省的properties文gMessagesBundle.properties<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_9_11_Open_Image" onclick="this.style.display='none'; Codehighlighter1_9_11_Open_Text.style.display='none'; Codehighlighter1_9_11_Closed_Image.style.display='inline'; Codehighlighter1_9_11_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_9_11_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_9_11_Closed_Text.style.display='none'; Codehighlighter1_9_11_Open_Image.style.display='inline'; Codehighlighter1_9_11_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span style="color: #000000">k1</span><span style="color: #000000">=</span><span style="color: #000000">hello,</span><span id="Codehighlighter1_9_11_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.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_9_11_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />k2</span><span style="color: #000000">=</span><span style="color: #000000">good bye</span></div> 英文文gMessagesBundle_en_US.properties<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_9_11_Open_Image" onclick="this.style.display='none'; Codehighlighter1_9_11_Open_Text.style.display='none'; Codehighlighter1_9_11_Closed_Image.style.display='inline'; Codehighlighter1_9_11_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_9_11_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_9_11_Closed_Text.style.display='none'; Codehighlighter1_9_11_Open_Image.style.display='inline'; Codehighlighter1_9_11_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span style="color: #000000">k1</span><span style="color: #000000">=</span><span style="color: #000000">hello,</span><span id="Codehighlighter1_9_11_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.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_9_11_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />k2</span><span style="color: #000000">=</span><span style="color: #000000">good bye</span></div> 中文文gMessagesBundle_zh_CN.properties<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_18_20_Open_Image" onclick="this.style.display='none'; Codehighlighter1_18_20_Open_Text.style.display='none'; Codehighlighter1_18_20_Closed_Image.style.display='inline'; Codehighlighter1_18_20_Closed_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" alt="" /><img id="Codehighlighter1_18_20_Closed_Image" style="display: none" onclick="this.style.display='none'; Codehighlighter1_18_20_Closed_Text.style.display='none'; Codehighlighter1_18_20_Open_Image.style.display='inline'; Codehighlighter1_18_20_Open_Text.style.display='inline';" src="http://www.aygfsteel.com/images/OutliningIndicators/ContractedBlock.gif" align="top" alt="" /><span style="color: #000000">k1</span><span style="color: #000000">=</span><span style="color: #000000">\u4f60\u597d,</span><span id="Codehighlighter1_18_20_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.aygfsteel.com/Images/dot.gif" alt="" /></span><span id="Codehighlighter1_18_20_Open_Text"><span style="color: #000000">{</span><span style="color: #000000">0</span><span style="color: #000000">}</span></span><span style="color: #000000"><br /> </span><span style="color: #008080">2</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" />k2</span><span style="color: #000000">=</span><span style="color: #000000">\u518d\u89c1<br /> </span><span style="color: #008080">3</span><span style="color: #000000"><img src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align="top" alt="" /></span></div> <img src ="http://www.aygfsteel.com/wx886104/aggbug/246314.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wx886104/" target="_blank">勒紧皮带向前?/a> 2008-12-15 09:44 <a href="http://www.aygfsteel.com/wx886104/archive/2008/12/15/246314.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>11.14看代码记?/title><link>http://www.aygfsteel.com/wx886104/archive/2008/11/14/240491.html</link><dc:creator>勒紧皮带向前?/dc:creator><author>勒紧皮带向前?/author><pubDate>Fri, 14 Nov 2008 03:58:00 GMT</pubDate><guid>http://www.aygfsteel.com/wx886104/archive/2008/11/14/240491.html</guid><wfw:comment>http://www.aygfsteel.com/wx886104/comments/240491.html</wfw:comment><comments>http://www.aygfsteel.com/wx886104/archive/2008/11/14/240491.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wx886104/comments/commentRss/240491.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wx886104/services/trackbacks/240491.html</trackback:ping><description><![CDATA[<p>今天看的代码是数据池c,对其中的HashtableQVector和Properties三个c返回Enumerationcd的方法注意了一下?br /> Hashtableq回枚Dcd的方法有<code><strong><a href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/util/Hashtable.html#elements()">elements</a></strong>()q回此哈希表中的值的枚D</code>?code><strong><a href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/util/Hashtable.html#keys()">keys</a></strong>()q回此哈希表中的键的枚D?br /> </code>Vector?code><strong><a href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/util/Vector.html#elements()">elements</a></strong>()</code>q回此向量的lg的枚?br /> <code><strong>Properties?a href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/util/Properties.html#propertyNames()">propertyNames</a></strong>()q回属性列表中所有键的枚举,如果在主属性列表中未找到同名的键,则包括默认属性列表中不同的键?br /> </code><code><strong>Properties</strong></code>?code><strong><a href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/util/Properties.html#getProperty(java.lang.String)">getProperty</a></strong></code>Ҏ有两个;<br /> <code><strong>一个是<a href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/util/Properties.html#getProperty(java.lang.String)">getProperty</a></strong>(<a title="java.lang 中的c? href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/lang/String.html">String</a> key)用指定的键在此属性列表中搜烦属?/code><br /> 一个是<code><strong><a href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/util/Properties.html#getProperty(java.lang.String, java.lang.String)">getProperty</a></strong>(<a title="java.lang 中的c? href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/lang/String.html">String</a> key, <a title="java.lang 中的c? href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/lang/String.html">String</a> defaultValue)用指定的键在属性列表中搜烦属性。如果在属性列表中未找到该键,则接着递归查默认属性列表及光认倹{如果未扑ֈ属性,则此Ҏq回默认值变量?br /> <br /> <strong><font style="background-color: #0a246a" color="#ffffff">ThreadGroup    U程l表CZ个线E的集合。此外,U程l也可以包含其他U程l。线E组构成一|Q在树中Q除了初始线E组外,每个U程l都有一个父U程l?<br /> </p> <p> <table cellspacing="0" cellpadding="3" width="100%" summary="" border="1"> <tbody> <tr class="TableHeadingColor" bgcolor="#ccccff"> <th align="left" colspan="2"><font size="+2"><strong>构造方法摘?/strong></font></th> </tr> <tr class="TableRowColor" bgcolor="white"> <td><code><strong><a href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/lang/ThreadGroup.html#ThreadGroup(java.lang.String)"><font style="background-color: #0a246a" color="#ffffff">ThreadGroup</font></a></strong>(<a title="java.lang 中的c? href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/lang/String.html">String</a> name)</code> <br />           构造一个新U程l?/td> </tr> <tr class="TableRowColor" bgcolor="white"> <td><code><strong><a href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/lang/ThreadGroup.html#ThreadGroup(java.lang.ThreadGroup, java.lang.String)"><font style="background-color: #0a246a" color="#ffffff">ThreadGroup</font></a></strong>(<a title="java.lang 中的c? href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/lang/ThreadGroup.html"><font style="background-color: #0a246a" color="#ffffff">ThreadGroup</font></a> parent, <a title="java.lang 中的c? href="mk:@MSITStore:H:\帮助资料\JDK15chs\JDK1.5中文帮助(CHM)\JAVA_API_CN.CHM::/api/java/lang/String.html">String</a> name)</code> <br />           创徏一个新U程l?/td> </tr> </tbody> </table> </p> <p></font></strong><br /> </code> </p> <img src ="http://www.aygfsteel.com/wx886104/aggbug/240491.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wx886104/" target="_blank">勒紧皮带向前?/a> 2008-11-14 11:58 <a href="http://www.aygfsteel.com/wx886104/archive/2008/11/14/240491.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>代码攉Qmd5加密 两个http://www.aygfsteel.com/wx886104/archive/2008/11/11/239836.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Tue, 11 Nov 2008 03:38:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/11/11/239836.htmlhttp://www.aygfsteel.com/wx886104/comments/239836.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/11/11/239836.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/239836.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/239836.html阅读全文

]]>
代码攉Q一个文件操作类http://www.aygfsteel.com/wx886104/archive/2008/11/11/239828.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Tue, 11 Nov 2008 03:24:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/11/11/239828.htmlhttp://www.aygfsteel.com/wx886104/comments/239828.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/11/11/239828.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/239828.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/239828.html阅读全文

]]>
代码攉Q一个时间格式处理类http://www.aygfsteel.com/wx886104/archive/2008/11/11/239819.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Tue, 11 Nov 2008 03:04:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/11/11/239819.htmlhttp://www.aygfsteel.com/wx886104/comments/239819.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/11/11/239819.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/239819.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/239819.html 1import java.util.*;
 2/**
 3 * <p>Title: Time  </p>
 4 * <p>Description: </p>
 5 *      此类主要用来取得本地pȝ的系l时间ƈ用下?U格式显C?br />  6 *              1. YYMMDDHH         8?br />  7 *              2. YYMMDDHHmm       10?br />  8 *              3. YYMMDDHHmmss     12?br />  9 *              4. YYYYMMDDHHmmss   14?br /> 10 *              5. YYMMDDHHmmssxxx  15?nbsp;(最后的xxx 是毫U?
11 * <p>Copyright: Copyright (c) 2003</p>
12 * <p>Company: hoten </p>
13 * @author lqf
14 * @version 1.0
15 */

16public class CTime {
17    public static final int YYMMDDhhmmssxxx=15;
18    public static final int YYYYMMDDhhmmss=14;
19    public static final int YYMMDDhhmmss=12;
20    public static final int YYMMDDhhmm=10;
21    public static final int YYMMDDhh=8;
22/**
23 * 取得本地pȝ的时_旉格式由参数决?br /> 24 * @param format 旉格式由常量决?br /> 25 * @return String hformat格式的字W串
26 */

27    public synchronized static String  getTime(int format){
28        StringBuffer cTime=new StringBuffer(10);
29        Calendar time=Calendar.getInstance();
30        int miltime=time.get(Calendar.MILLISECOND);
31        int second=time.get(Calendar.SECOND);
32        int minute=time.get(Calendar.MINUTE);
33        int hour=time.get(Calendar.HOUR_OF_DAY);
34        int day =time.get(Calendar.DAY_OF_MONTH);
35        int month=time.get(Calendar.MONTH)+1;
36        int year =time.get(Calendar.YEAR);
37        if(format!=14){
38            if(year>=2000) year=year-2000;
39            else year=year-1900;
40        }

41        if(format>=2){
42            if(format==14) cTime.append(year);
43            else    cTime.append(getFormatTime(year,2));
44        }

45        if(format>=4)
46            cTime.append(getFormatTime(month,2));
47        if(format>=6)
48            cTime.append(getFormatTime(day,2));
49        if(format>=8)
50            cTime.append(getFormatTime(hour,2));
51        if(format>=10)
52            cTime.append(getFormatTime(minute,2));
53        if(format>=12)
54            cTime.append(getFormatTime(second,2));
55        if(format>=15)
56            cTime.append(getFormatTime(miltime,3));
57        return cTime.toString();
58    }

59/**
60 * 产生L位的字符?br /> 61 * @param time 要{换格式的旉
62 * @param format 转换的格?br /> 63 * @return String 转换的时?br /> 64 */

65    private synchronized static String getFormatTime(int time,int format){
66        StringBuffer numm=new StringBuffer();
67        int length=String.valueOf(time).length();
68
69        if(format<length) return null;
70
71        for(int i=0 ;i<format-length ;i++){
72            numm.append("0");
73        }

74        numm.append(time);
75        return numm.toString().trim();
76    }

77}


]]>
java的io操作http://www.aygfsteel.com/wx886104/archive/2008/11/06/238982.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Thu, 06 Nov 2008 03:24:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/11/06/238982.htmlhttp://www.aygfsteel.com/wx886104/comments/238982.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/11/06/238982.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/238982.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/238982.htmlFilecL两个构造方法,File(父目录,文g?Q关联指定的目录下指定名U的文gQFile(文g?目录?Q关联某个文件名或者目录,q里?表示的意思是“或?#8221;?br />     比较好的Ҏ是先用一个File对象兌一个目录名Q然后创个目录,Qmkdir()Q?再用构造方法构造一个文件。以下的代码是在“我的文档”里创Z个名?#8220;1.txt”的文件?br />   File dir=new File("C:"+File.separator+"Documents and Settings"+File.separator+"Yxy"+File.separator+"My Documents");  //此处注意转义字符
  dir.mkdir();  //创徏目录
  File file1=new File(dir,"1.txt");
  file1.createNewFile();  //创徏一个新文g
        String[] str1=dir.list();  //下文说到的list()
    //不知道ؓ什么这里的I格是只能q么长,代码是我从我自己的代码里拯来的Q汗      
    //一个先
    各位Q其实这里可以用转义字符“\\”来代替File.separatorQ但是这不是一个好的习惯。ؓ了实现Java的一ơ编译,四处q行的性感特点Q我们需要一个通用的文件分隔符Q因为各U操作系l下存在差异Q比如linux的文件分隔符是正斜杠"/"。而File的特性separator正是获取当前操作pȝ下的文g分隔W。另Q千万不要将?\"单独存在Q在代码中这是一个{义字W的标识Q它会将接下来的一个字W理解ؓ转义字符?br />      除了q种Ҏ可以创徏新的文gQ还可以调用FilecM的一个静态函?br />  File createTempFile(String prefix,String suffix,File directory),q是一个完整的版本Q在指定的目录下创徏一个以prefix为前~名,suffix为后~名的临时文gQ通过deleteOnExit()来删除。但是还有一个精的版本,
File createTempFile(String prefix,String suffix),没有指定目录Q将在当前操作系l默认的临时文g多w创徏以prefix为前~名,suffix为后~名的临时文g?br />      以上是如何创建文Ӟ接下来讲的是如何查阅目录下的文g和通过文gqo器查找文件?br />     看到前面的代码里写到的list()Ҏ了吗Q返回一个Stringcd的数l,获取当前目录下的所有文件名Q包括目录名Q即文g夹)。但是,q样是不够的Q无法找到我们所需要的文gQ我们需要的是按我们的要求找到某个房间。Java.io包类提供cL件过滤器FileNameFilterQ它是一个接口,内有Ҏboolean accept(File dir, String name),q是一个需要重写的ҎQ重写了q个Ҏ之后Qlist(FileNameFileter f)Ҏ可以列出W合我们要求的方法?br /> 本文来源【学|】网站链接是http://www.xue5.com

 Java中的separatorQpathSeparator{常? -

File.separatorChar q回一个字W,表示当前pȝ默认的文件名分隔W,在Windows中ؓ"\",unix中ؓ"/"?br /> File.separator 与前者相同,但将分隔W作为字W串cdq回?br /> pathSeparatorChar q回一个字W,表示当前pȝ默认的\径名分隔W,在Windows中ؓ";",unix中ؓ":"?br /> File.pathSeparator 与前者相同,但将分隔W作为字W串cdq回?/p>

正文为JDKAPI帮助文档相关内容Q?/p>


separatorChar
public static final char separatorCharThe system-dependent default name-separator character. This field is initialized to contain the first character of the value of the system property file.separator. On UNIX systems the value of this field is '/'; on Microsoft Windows systems it is '\'.

See Also:
System.getProperty(java.lang.String)

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

separator
public static final String separatorThe system-dependent default name-separator character, represented as a string for convenience. This string contains a single character, namely separatorChar.


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

pathSeparatorChar
public static final char pathSeparatorCharThe system-dependent path-separator character. This field is initialized to contain the first character of the value of the system property path.separator. This character is used to separate filenames in a sequence of files given as a path list. On UNIX systems, this character is ':'; on Microsoft Windows systems it is ';'.

See Also:
System.getProperty(java.lang.String)

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

pathSeparator
public static final String pathSeparatorThe system-dependent path-separator character, represented as a string for convenience. This string contains a single character, namely pathSeparatorChar.



]]>
java.lang.OutOfMemoryError: Java heap space 解决Ҏhttp://www.aygfsteel.com/wx886104/archive/2008/11/03/238346.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Mon, 03 Nov 2008 07:18:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/11/03/238346.htmlhttp://www.aygfsteel.com/wx886104/comments/238346.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/11/03/238346.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/238346.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/238346.htmlq个问题的根源是jvm虚拟机的默认Heap大小?4M,可以通过讄其最大和最值来实现.讄的方法主要是几个.

1.可以在windows 更改pȝ环境变量

加上JAVA_OPTS=-Xms64m -Xmx512m

2,如果用的tomcat,在windows?可以?/strong>

C:\tomcat5.5.9\bin\catalina.bat 中加?

set JAVA_OPTS=-Xms64m -Xmx256m

位置? rem Guess CATALINA_HOME if not defined q行的下面加合?

3.如果是linuxpȝ

Linux 在{tomcat_home}/bin/catalina.sh的前面,?

set JAVA_OPTS='-Xms64 -Xmx512'


使用JavaE序从数据库中查询大量的数据时出现异?java.lang.OutOfMemoryError: Java heap space 在JVM中如?8Q的旉是用于GC且可用的 Heap size 不2Q的时候将抛出此异怿息?JVM堆的讄是指javaE序q行q程中JVM可以调配使用的内存空间的讄.JVM在启动的时候会自动讄Heap size的|其初始空??Xms)是物理内存的1/64Q最大空?-Xmx)是物理内存的1/4。可以利用JVM提供?Xmn -Xms -Xmx{选项可进行设|。例如:java -jar -Xmn16m -Xms64m -Xmx128m MyApp.jar如果Heap Size讄偏小Q除了这些异怿息外Q还会发现程序的响应速度变慢了。GC占用了更多的旉Q而应用分配到的执行时间较。Heap Size 最大不要超q可用物理内存的80Q,一般的要将-Xms?Xmx选项讄为相同,?Xmn?/4?Xmx倹{Heap size?-Xms -Xmn 讄不要出物理内存的大。否则会提示“Error occurred during



]]>
oracle的to_date()Ҏ的小妙用Q原创)http://www.aygfsteel.com/wx886104/archive/2008/11/01/238048.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Sat, 01 Nov 2008 06:11:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/11/01/238048.htmlhttp://www.aygfsteel.com/wx886104/comments/238048.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/11/01/238048.html#Feedback2http://www.aygfsteel.com/wx886104/comments/commentRss/238048.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/238048.html 在某些时候需要通过日期中的q_月,日等来统计数据,通常我们会将日期取出Q再在程序中获取当前日期。进行比较,q样会加大开销?br /> 现在可以通过to_date来截取日期中的年Q月Q日的来获取数据?br /> 如: to_char(to_date(b_time,'yyyy-mm-dd'),'yyyy')=to_char(to_date(?,'yyyy-mm-dd hh24:mi:ss'),'yyyy')
q样获取的就是年的字W串Q就可得到指定年的数据?br /> 月:to_char(to_date(b_time,'yyyy-mm-dd'),'mm')=to_char(to_date(?,'yyyy-mm-dd hh24:mi:ss'),'mm')
日:to_char(to_date(b_time,'yyyy-mm-dd'),'dd')=to_char(to_date(?,'yyyy-mm-dd hh24:mi:ss'),'dd')



]]>
Q{载)java中的集合cLȝhttp://www.aygfsteel.com/wx886104/archive/2008/09/25/231114.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Thu, 25 Sep 2008 07:15:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/09/25/231114.htmlhttp://www.aygfsteel.com/wx886104/comments/231114.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/09/25/231114.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/231114.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/231114.htmljava中的集合cLȝ
2008q?9?7?星期?13:59

在用Java的时候,我们都会遇到使用集合QCollectionQ的时候,但是Java API提供了多U集合的实现Q我在用和面试的时候频

频遇到这L“抉择” ?:Q(主要q是面试的时候)

久而久之,也就有了一点点的心得体会,写出来以供大家讨??/p>

ȝ说来QJava API中所用的集合c,都是实现了Collection接口Q他的一个类l承l构如下Q?/p>

Collection<--List<--Vector

Collection<--List<--ArrayList

Collection<--List<--LinkedList

Collection<--Set<--HashSet

Collection<--Set<--HashSet<--LinkedHashSet

Collection<--Set<--SortedSet<--TreeSet

Vector : ZArray的ListQ其实就是封装了Array所不具备的一些功能方便我们用,它不可能走入Array的限制。性能也就不可?/p>

越Array。所以,在可能的情况下,我们要多q用Array。另外很重要的一点就是Vector“sychronized”的,q个也是Vector?/p>

ArrayList的唯一的区别?/p>

ArrayListQ同Vector一h一个基于Array上的链表Q但是不同的是ArrayList不是同步的。所以在性能上要比Vector优越一些,?/p>

是当q行到多U程环境中时Q可需要自己在理U程的同步问题?/p>

LinkedListQLinkedList不同于前面两UListQ它不是ZArray的,所以不受Array性能的限制。它每一个节点(NodeQ都包含两方

面的内容Q?.节点本n的数据(dataQ;2.下一个节点的信息QnextNodeQ。所以当对LinkedList做添加,删除动作的时候就不用?/p>

ZArray的List一P必须q行大量的数据移动。只要更改nextNode的相关信息就可以实现了。这是LinkedList的优ѝ?/p>

ListȝQ?/p>

1. 所有的List中只能容U_个不同类型的对象l成的表Q而不是KeyQValue键值对。例如:[ tom,1,c ]Q?/p>

2. 所有的List中可以有相同的元素,例如Vector中可以有 [ tom,koo,too,koo ]Q?/p>

3. 所有的List中可以有null元素Q例如[ tom,null,1 ]Q?/p>

4. ZArray的ListQVectorQArrayListQ适合查询Q而LinkedListQ链表)适合dQ删除操作?/p>

HashSetQ虽然Set同List都实CCollection接口Q但是他们的实现方式却大不一栗List基本上都是以Array为基。但是Set则是

在HashMap的基上来实现的,q个是Set和List的根本区别。HashSet的存储方式是把HashMap中的Key作ؓSet的对应存储项。看?/p>

HashSet的addQObject objQ方法的实现可以一目了然了?/p>

public boolean add(Object obj)

{

return map.put(obj, PRESENT) == null;

}

q个也是Z么在Set中不能像在List中一h重复的项的根本原因,因ؓHashMap的key是不能有重复的?/p>

LinkedHashSetQHashSet的一个子c,一个链表?/p>

TreeSetQSortedSet的子c,它不同于HashSet的根本就是TreeSet是有序的。它是通过SortedMap来实现的?/p>

SetȝQ?/p>

1. Set实现的基是MapQHashMapQ;

2. Set中的元素是不能重复的Q如果用add(Object obj)Ҏd已经存在的对象,则会覆盖前面的对?/p>

Z么要使用集合c?/p>

当你事先不知道要存放数据的个敎ͼ或者你需要一U比数组下标存取机制更灵zȝҎӞ你就需要用到集合类?/p>

理解集合c?/p>

集合cd放于java.util包中?/p>

集合cd攄都是对象的引用,而非对象本nQ出于表达上的便利,我们U集合中的对象就是指集合中对象的引用Qreference)?/p>

集合cd主要?U:set(集)、list(列表Q和map(映射)?/p>

(1)?/p>

集(setQ是最单的一U集合,它的对象不按特定方式排序Q只是简单的把对象加入集合中Q就像往口袋里放东西?/p>

寚w中成员的讉K和操作是通过集中对象的引用进行的Q所以集中不能有重复对象?/p>

集也有多U变体,可以实现排序{功能,如TreeSetQ它把对象添加到集中的操作将变ؓ按照某种比较规则其插入到有序的对象?/p>

列中。它实现的是SortedSet接口Q也是加入了对象比较的Ҏ。通过寚w中的对象q代Q我们可以得C个升序的对象集合?/p>

(2)列表

列表的主要特征是其对象以U性方式存储,没有特定序Q只有一个开头和一个结,当然Q它与根本没有顺序的集是不同的?/p>

列表在数据结构中分别表现为:数组和向量、链表、堆栈、队列?/p>

关于实现列表的集合类Q是我们日常工作中经常用到的Q将在后边的W记详细介绍?/p>

(3)映射

映射与集或列表有明显区别Q映中每个w是成对的。映中存储的每个对象都有一个相关的关键字(KeyQ对象,关键字决定了

对象在映中的存储位|,索对象时必须提供相应的关键字Q就像在字典中查单词一栗关键字应该是唯一的?/p>

关键字本wƈ不能军_对象的存储位|,它需要对q一U散?hashing)技术来处理Q生一个被UC散列?hash code)的整数|

散列码通常用作一个偏|量Q该偏置量是相对于分配给映射的内存区域v始位|的Q由此确定关键字/对象对的存储位置。理x?/p>

下,散列处理应该产生l定范围内均匀分布的|而且每个关键字应得到不同的散列码?/p>

集合cȝ?/p>

java.util中共?3个类可用于管理集合对象,它们支持集、列表或映射{集合,以下是这些类的简单介l?/p>

集:

HashSetQ?使用HashMap的一个集的实现。虽焉定义成无序,但必d在某U方法能相当高效地找C个对象。用一个HashMap?/p>

象实现集的存储和索操作是在固定时间内实现?

TreeSetQ?在集中以升序对对象排序的集的实现。这意味着从一个TreeSet对象获得W一个P代器按升序提供对象。TreeSetcM?/p>

了一个TreeMap.

列表Q?/p>

VectorQ?实现一个类似数l一L表,自动增加定w来容U你所需的元素。用下标存储和索对象就象在一个标准的数组中一?/p>

。你也可以用一个P代器从一个Vector中检索对象。Vector是唯一的同步容器类??当两个或多个U程同时讉K时也是性能良好的?/p>

Stsck: q个cMVectorz而来Qƈ且增加了Ҏ实现??一U后q先出的存储l构?/p>

LinkedList: 实现一个链表。由q个cd义的链表也可以像栈或队列一栯使用?/p>

ArrayList: 实现一个数l,它的规模可变q且能像链表一栯讉K。它提供的功能类似VectorcM不同步?/p>

映射Q?/p>

HashTableQ?实现一个映象,所有的键必非I。ؓ了能高效的工作,定义键的cdd现hashcode()Ҏ和equal()Ҏ。这个类

是前面java实现的一个承,q且通常能在实现映象的其他类中更好的使用?/p>

HashMapQ?实现一个映象,允许存储I对象,而且允许键是I(׃键必L唯一的,当然只能有一个)?/p>

WeakHashMapQ?实现q样一个映象:通常如果一个键对一个对象而言不再被引用,?对象对将被舍弃。这与HashMap形成对照Q映?/p>

中的键维持键/对象对的生命周期Q尽用映象的E序不再有对键的引用Qƈ且因此不能检索对象?/p>

TreeMapQ?实现q样一个映象,对象是按键升序排列的?/p>

Set和List都是由公共接口Collection扩展而来Q所以它们都可以使用一个类型ؓCollection的变量来引用。这意味着M列表?/p>

集构成的集合都可以用q种方式引用Q只有映类除外Q但也不是完全排除在外,因ؓ可以从映获得一个列表。)所以说Q把一?/p>

列表或集传递给Ҏ的标准途径是用Collectioncd的参数?/p>

Vector q是ArrayListQ哪一个更好,Z么?

要回{这个问题不能一概而论Q有时候用Vector比较好;有时是ArrayListQ有时候这两个都不是最好的选择。你别指望能够获?/p>

一个简单肯定答案,因ؓq要看你用它们干什么。下面有4个要考虑的因素:

(1)API

(2)同步处理

(3)数据增长?/p>

(4)使用模式

下面针对q?个方面进行一一探讨

API

在由Ken Arnold{编著的《Java Programming Language?Addison-Wesley, June 2000)一书中有这L描述QVectorcM?/p>

ArrayList.。所有从API的角度来看这两个c非常相伹{但他们之间也还是有一些主要的区别的?/p>

同步?/p>

Vector是同步的。这个类中的一些方法保证了Vector中的对象是线E安全的。而ArrayList则是异步的,因此ArrayList中的对象q不

是线E安全的。因为同步的要求会媄响执行的效率Q所以如果你不需要线E安全的集合那么使用ArrayList是一个很好的选择Q这?/p>

可以避免׃同步带来的不必要的性能开销?/p>

数据增长

从内部实现机制来讲ArrayList和Vector都是使用数组(Array)来控刉合中的对象。当你向q两U类型中增加元素的时候,如果元素

的数目超Z内部数组目前的长度它们都需要扩展内部数l的长度QVector~省情况下自动增长原来一倍的数组长度QArrayList?/p>

原来?0%,所以最后你获得的这个集合所占的I间L比你实际需要的要大。所以如果你要在集合中保存大量的数据那么使用Vector

有一些优势,因ؓ你可以通过讄集合的初始化大小来避免不必要的资源开销?/p>

使用模式

在ArrayList和Vector中,从一个指定的位置Q通过索引Q查找数据或是在集合的末֢加、移除一个元素所p的时间是一LQ?/p>

q个旉我们用O(1)表示。但是,如果在集合的其他位置增加或移除元素那么花费的旉会呈UŞ增长QO(n-i)Q其中n代表集合?/p>

元素的个敎ͼi代表元素增加或移除元素的索引位置。ؓ什么会q样呢?以ؓ在进行上q操作的时候集合中Wi和第i个元素之后的所

有元素都要执行位Uȝ操作。这一切意味着什么呢Q?/p>

q意味着Q你只是查找特定位置的元素或只在集合的末端增加、移除元素,那么使用Vector或ArrayList都可以。如果是其他操作Q?/p>

你最好选择其他的集合操作类。比如,LinkList集合cd增加或移除集合中M位置的元素所p的时间都是一L—O(1)Q但它在

索引一个元素的使用~比较慢QO(i),其中i是烦引的位置.使用ArrayList也很ҎQ因Z可以单的使用索引来代替创建iterator

对象的操作。LinkList也会为每个插入的元素创徏对象Q所有你要明白它也会带来额外的开销?/p>

最后,在《Practical Java》一书中Peter Haggar使用一个简单的数组QArrayQ来代替Vector或ArrayList。尤其是对于执行?/p>

率要求高的程序更应如此。因Z用数l?Array)避免了同步、额外的Ҏ调用和不必要的重新分配空间的操作?T007)

import java.util.*;
                        public class Testset {
                        public static void main(String args[]){
                        Set set = new HashSet();
                        set.add("aaa");
                        set.add("bbb");
                        set.add("aaa");
                        set.add("bbb");
                        set.add("aaa");
                        set.add("bbb");
                        set.add("aaa");
                        set.add("bbb");
                        set.add("aaa");
                        set.add("bbb");
                        Iterator ite=set.iterator();
                        set.size();
                        while(ite.hasNext())
                        System.out.println("------"+ite.next());
                        }
                        }


转自 http://hi.baidu.com/%C1%F5%CA%E9%B3%AC%B9%A4%B3%CC%CA%A6/blog/item/fa6867fe38a018375d60084e.html

]]>
(转蝲)struts上传下蝲http://www.aygfsteel.com/wx886104/archive/2008/09/25/231112.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Thu, 25 Sep 2008 07:12:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/09/25/231112.htmlhttp://www.aygfsteel.com/wx886104/comments/231112.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/09/25/231112.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/231112.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/231112.html最q要做上传下载,所以又把它d了,熟悉了一把,做了一下字节{换的调整及上传类型的限制Q当然还有上传\径的限制。不q一直在考虑的问题是怎样扑ֈ减少服务器压力的具体ҎQ本列子贴出来是希望能给某些新手一些帮助,同时也希望各路大侠批评指点小弟的许多不?/span>

 

首先建立一个FileAction

package com.action;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import com.actionForm.FileActionForm;
import org.apache.struts.actions.DispatchAction;
import java.util.Date;
import java.text.*;
import org.apache.struts.upload.FormFile;
import java.io.*;
import java.net.URLEncoder;
import com.dao.*;

public class FileAction extends DispatchAction {

    private JDBConnection connection =new JDBConnection();
//以下Ҏ实现文g的上?/span>
    public ActionForward upLoadFile(ActionMapping mapping, ActionForm form,
                                    HttpServletRequest request,
                                    HttpServletResponse response) throws
            Exception {
     ActionForward forward=null;
        Date date = new Date();
        FileActionForm fileActionForm = (FileActionForm) form;
        //FormFile用于指定存取文g的类?br />         FormFile file = fileActionForm.getFile(); //获取当前的文?/span>
      // 获得pȝ的绝对\?/span>  String dir = servlet.getServletContext().getRealPath("/image");
        //我上传的文g没有攑֜服务器上。而是存在D:D:\\loadfile\\temp\\
        String dir="D:\\loadfile\\temp\\";
        int i = 0;
  String type = file.getFileName();
  while(i!=-1){
   //扑ֈ上传文g的类型的位置Q这个地方的?.'
   i = type.indexOf(".");
  /* System.out.println(i);*/
   /*截取上传文g的后~?此时得到了文件的cd*/
   type = type.substring(i+1);
  }
  // 限制上传cd为jpg,txt,rar;
  if (!type.equals("jpg") && !type.equals("txt")&& !type.equals("bmp"))
   
  {//当上传的cd不ؓ上述cdӞ跌{到错误页面?/span>
    forward=mapping.findForward("error");
  }
  else
  {  
//    上传时间加入文件名Q这个地方的是毫U数Q?nbsp;  
     String times = String.valueOf(date.getTime());
    //l合?time.type
         String  fname = times + "." + type;
       //InInputStream是用以从特定的资源读取字节的Ҏ?br />           InputStream streamIn = file.getInputStream();    //创徏d用户上传文g的对?br />           //得到是字节数Q即byte,我们可以直接用file.getFileSize(),也可以在创徏d对象时用streamIn.available();
         // int ok=streamIn.available();          
          int ok=file.getFileSize();
          String strFee = null;
          //q个地方是处理上传的为M单位计算Ӟ下一个是以kb,在下一个是byte;
         
          if(ok>=1024*1024)
          {
           float ok1=(((float)ok)/1024f/1024f); 
           DecimalFormat myformat1 = new DecimalFormat("0.00");        
          strFee = myformat1.format(ok1)+"M";
                 System.out.println(strFee+"M");
          }
          else if(ok>1024 && ok<=1024*1024)
          {
             double  ok2=((double)ok)/1024;
             DecimalFormat myformat2=new DecimalFormat("0.00");
            strFee = myformat2.format(ok2)+"kb";
                 System.out.println(strFee+"kb");
          }
          else if(ok<1024)
          {
           System.out.println("aaaaaaaaa");
           strFee=String.valueOf(ok)+"byte";
           System.out.println(strFee);
          
          }
          System.out.println( streamIn.available()+"文g大小byte");
          //q个是io包下的上传文件类
          File uploadFile = new File(dir);   //指定上传文g的位|?br />           if (!uploadFile.exists() || uploadFile == null) {  //判断指定路径dir是否存在Q不存在则创\?br />               uploadFile.mkdirs();
          }
          //上传的\?文g?br />           String path = uploadFile.getPath() + "\\" + fname;
       //OutputStream用于向某个目标写入字节的抽象c,q个地方写入目标是pathQ通过输出FileOutputStreamd
          OutputStream streamOut = new FileOutputStream(path);
          int bytesRead = 0;
          byte[] buffer = new byte[8192];
          //数据读入byte数组的一部分Q其中读入字节数的最大值是8192Q读入的字节存储到Qbuffer[0]到buffer[0+8190-1]的部分中
          //streamIn.readҎq回的是实际d字节数目.如果d末尾则返?1.如果bytesReadq回?则表C没有读取Q何字节?br />
          while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {
           //写入buffer数组的一部分Q从buf[0]开始写入ƈ写入bytesRead个字节,q个writeҎ发生阻塞直臛_节写入完成?br />               streamOut.write(buffer, 0, bytesRead);
          }
        //  关闭输出输入?销毁File?br />           streamOut.close();
          streamIn.close();
          file.destroy();    
          String paths=path;
          System.out.println(paths);
         String fileName = Chinese.toChinese(fileActionForm.getFileName()); //获取文g的名U?/span>
        //String fileSize = String.valueOf(file.getFileSize());
         String fileDate = DateFormat.getDateInstance().format(date);
         String sql = "insert into tb_file values('" + fileName + "','" +
         strFee + "','" + fileDate + "','" + paths + "')";

         connection.executeUpdate(sql);
         connection.closeConnection();
         forward=mapping.findForward("upLoadFileResult");
  }
        return forward;
    }
    //实现文g的下?br />     public ActionForward downFile(ActionMapping mapping, ActionForm form,
                                  HttpServletRequest request,
                                  HttpServletResponse response) throws
            Exception {
        String path = request.getParameter("path");
        System.out.println(path+"111");
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        OutputStream fos = null;
        InputStream fis = null;
       
      //如果是从服务器上取就用这个获得系l的l对路径Ҏ?nbsp; String filepath = servlet.getServletContext().getRealPath("/" + path);
        String  filepath=path;
        System.out.println("文g路径"+filepath);
        File uploadFile = new File(filepath);
        fis = new FileInputStream(uploadFile);
        bis = new BufferedInputStream(fis);
        fos = response.getOutputStream();
        bos = new BufferedOutputStream(fos);
        //q个就是弹Z载对话框的关键代?/span>
        response.setHeader("Content-disposition",
                           "attachment;filename=" +
                           URLEncoder.encode(path, "utf-8"));
        int bytesRead = 0;
        //q个地方的同上传的一栗我׃多说了,都是用输入流q行先读Q然后用输出去写,唯一不同的是我用的是~冲输入输出?br />         byte[] buffer = new byte[8192];
        while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) {
            bos.write(buffer, 0, bytesRead);
        }
        bos.flush();
        fis.close();
        bis.close();
        fos.close();
        bos.close();
        return null;
    }

}

FileActionForm

     

package com.actionForm;

import org.apache.struts.action.*;
import org.apache.struts.upload.*;

public class FileActionForm extends ActionForm {
    private String fileName;//上传文g的名U?br />     private String fileSize;//上传文g的大?br />     private String filePath;//上传文g到服务器的\?br />     private String fileDate;//上传文g的日?br />     private FormFile file;//上传文g

    public String getFileName() {
        return fileName;
    }

    public FormFile getFile() {
        return file;
    }

    public String getFileSize() {
        return fileSize;
    }

    public String getFilePath() {
        return filePath;
    }

    public String getFileDate() {
        return fileDate;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public void setFile(FormFile file) {
        this.file = file;
    }

    public void setFileSize(String fileSize) {
        this.fileSize = fileSize;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    public void setFileDate(String fileDate) {
        this.fileDate = fileDate;
    }

}

index.jsp  此位|的form是javabeen的对象,q个javabeen中存取的囄的相关信?/span>

<table width="264" height="81" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="115"  rowspan="4" align="center"><img src="<%=form.getFilePath()%>" width="100" height="100"></td>
                  <td width="133" align="center">囄名称Q?lt;%=form.getFileName()%></td>
                </tr>
                <tr align="center">
                  <td>囄大小Q?lt;%=form.getFileSize()%></td>
                </tr>
                <tr align="center">
                  <td>上传日期:<%=form.getFileDate()%></td>
                </tr>
                <tr>
                  <td align="center"><a href="fileAction.do?method=downFile&path=<%=form.getFilePath()%>" ><img src="priture/bottond.jpg"></a>


                  </td>
                </tr>
            </table>

<html:form action="fileAction.do?method=upLoadFile" enctype="multipart/form-data" onsubmit="return Mycheck()">
        <table height="52" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr align="center">
            <td width="60" height="26">囄名称:</td>
            <td width="160"> <html:text property="fileName"/> </td>
            <td width="60">囄路径:</td>
            <td width="198"> <html:file property="file"/> </td>
          </tr>
          <tr align="right">
            <td height="26" colspan="4"> <html:submit>上传</html:submit> </td>
          </tr>
        </table>
  </html:form>

struts-config.xml  

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "

<struts-config>
  <form-beans>
    <form-bean name="fileActionForm" type="com.actionForm.FileActionForm" />
  </form-beans>
  <action-mappings>
    <action name="fileActionForm" parameter="method" path="/fileAction" scope="request" type="com.action.FileAction" validate="true">
        <forward name="upLoadFileResult" path="/result.jsp"/>
        <forward name="error" path="/fail.jsp"></forward>
    </action>
  </action-mappings>
  <message-resources parameter="ApplicationResources" />
</struts-config>



转自javaEye http://www.javaeye.com/topic/219585



]]>
从资源服务器上下载文件的实现http://www.aygfsteel.com/wx886104/archive/2008/09/25/231111.html勒紧皮带向前?/dc:creator>勒紧皮带向前?/author>Thu, 25 Sep 2008 07:10:00 GMThttp://www.aygfsteel.com/wx886104/archive/2008/09/25/231111.htmlhttp://www.aygfsteel.com/wx886104/comments/231111.htmlhttp://www.aygfsteel.com/wx886104/archive/2008/09/25/231111.html#Feedback0http://www.aygfsteel.com/wx886104/comments/commentRss/231111.htmlhttp://www.aygfsteel.com/wx886104/services/trackbacks/231111.htmlhttp://ip:port/zg/xxxx.file的Ş式保存的。在xg上通过q样的\径可以正常显C源文件。但当需要下载文件时Q尽可以直接点L件\径来下蝲文gQ在firefox上比较方便,在maxton和ie上也可用Q但也会打开文gQ包括:rarQzip{文件类型)Q,如括号里说的一Pq样l用L体验很不好?br /> 解决Q在zg上徏一个downloadҎQ通过zg的请求\径放在xg的下载界面上Q当点击xg界面上的下蝲q接Ӟ都是hzg的download。因此,文g下蝲解决?br />
psQ这个只是新手的我给新手兄弟们的一点分享,请各路高手尽量指炏V谢谢!
ps2Qto新手兄弟Q关于文件上传下载网上很多,我的博客也有Q请自行选择?br />

]]>
վ֩ģ壺 ³| Ұ| | ÷| ݳ| | Ͽ| | | | | ½| Ԫ| | ΢ɽ| żҴ| Т| | ϲ| | | | ʯ| ׯ| | | ϻ| | ɽ| | ˳| | | Խ| ɽ| | | ͭ| DZ| | |