<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>久酷 &#187; java</title>
	<atom:link href="http://www.jiucool.com/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jiucool.com</link>
	<description>Say That What I Can Say!</description>
	<lastBuildDate>Thu, 12 Jan 2012 23:09:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://www.jiucool.com/?pushpress=hub'/>
		<item>
		<title>Java处理JSON数据错误解决办法</title>
		<link>http://www.jiucool.com/java-json-data-error-handling-solution/</link>
		<comments>http://www.jiucool.com/java-json-data-error-handling-solution/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 15:08:20 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[json-lib]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/java-json-data-error-handling-solution/</guid>
		<description><![CDATA[json数据JS处理起来蛮方便，java处理起来的话我是用导入的Json-lib这个包，源码写好了，执行时总是报如下错误：



Exception in thread &#34;main&#34; java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException

at java.lang.ClassLoader.defineClass1&#40;Native Method&#41;

<span class="readmore"><a href="http://www.jiucool.com/java-json-data-error-handling-solution/" title="Java处理JSON数据错误解决办法">Read More: 1006 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>json数据JS处理起来蛮方便，java处理起来的话我是用导入的Json-lib这个包，源码写好了，执行时总是报如下错误：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Exception</span> in thread <span style="color: #0000ff;">&quot;main&quot;</span> java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">NoClassDefFoundError</span><span style="color: #339933;">:</span> org<span style="color: #339933;">/</span>apache<span style="color: #339933;">/</span>commons<span style="color: #339933;">/</span>lang<span style="color: #339933;">/</span>exception<span style="color: #339933;">/</span>NestableRuntimeException
at java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">ClassLoader</span>.<span style="color: #006633;">defineClass1</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Native</span> <span style="color: #003399;">Method</span><span style="color: #009900;">&#41;</span>
at java.<span style="color: #006633;">lang</span>.<span style="color: #003399;">ClassLoader</span>.<span style="color: #006633;">defineClass</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">ClassLoader</span>.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">620</span><span style="color: #009900;">&#41;</span>
at java.<span style="color: #006633;">security</span>.<span style="color: #003399;">SecureClassLoader</span>.<span style="color: #006633;">defineClass</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">SecureClassLoader</span>.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">124</span><span style="color: #009900;">&#41;</span>
at java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URLClassLoader</span>.<span style="color: #006633;">defineClass</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">URLClassLoader</span>.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">260</span><span style="color: #009900;">&#41;</span>
at java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URLClassLoader</span>.<span style="color: #006633;">access</span>$000<span style="color: #009900;">&#40;</span><span style="color: #003399;">URLClassLoader</span>.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">56</span><span style="color: #009900;">&#41;</span>
at java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URLClassLoader</span>$1.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">URLClassLoader</span>.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">195</span><span style="color: #009900;">&#41;</span>
at java.<span style="color: #006633;">security</span>.<span style="color: #003399;">AccessController</span>.<span style="color: #006633;">doPrivileged</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Native</span> <span style="color: #003399;">Method</span><span style="color: #009900;">&#41;</span>
at java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URLClassLoader</span>.<span style="color: #006633;">findClass</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">URLClassLoader</span>.<span style="color: #006633;">java</span><span style="color: #339933;">:</span><span style="color: #cc66cc;">188</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>几经检查,程序没问题，原来是myeclipse的lib包有问题，主要是json-lib的dependencies 包缺少，依赖包一共如下几个，全部包含的话，OK搞定！(<a href="http://json-lib.sourceforge.net/" target="_blank">http://json-lib.sourceforge.net/</a>)&#160;
<p>Json-lib requires (at least) the following dependencies in your classpath:</p>
<ol>
<li>jakarta commons-lang 2.4 </li>
<li>jakarta commons-beanutils 1.7.0 </li>
<li>jakarta commons-collections 3.2 </li>
<li>jakarta commons-logging 1.1.1 </li>
<li>ezmorph 1.0.6</li>
</ol>
<p>打包下载地址：<a title="http://d.download.csdn.net/down/491113/luyi122333" href="http://d.download.csdn.net/down/491113/luyi122333" target="_blank">http://d.download.csdn.net/down/491113/luyi122333</a></p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/java-json-data-error-handling-solution/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/java-json-data-error-handling-solution/#comments">15 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/json/" rel="tag">json</a>, <a href="http://www.jiucool.com/tag/json-lib/" rel="tag">json-lib</a>, <a href="http://www.jiucool.com/tag/xml/" rel="tag">xml</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/java-json-data-error-handling-solution/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>IE 下调试JavaScript</title>
		<link>http://www.jiucool.com/javascript-debugging-under-ie/</link>
		<comments>http://www.jiucool.com/javascript-debugging-under-ie/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 12:11:50 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[IE 调试javascript]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/javascript-debugging-under-ie/</guid>
		<description><![CDATA[IE 下不仅N多CSS标准样式表无法识别，而且N多莫名其妙的javascript问题，也就是说在别的浏览器下可以识别的javascript代码，有IE下可能无法识别并且报错，导致某些网页功能无法使用！真杯具！

装一个IE下高度javascript的工具吧：



装一个IE-debugbar软件，下载地址（含注册机）http://d.download.csdn.net/down/2499396/monlyu 

<span class="readmore"><a href="http://www.jiucool.com/javascript-debugging-under-ie/" title="IE 下调试JavaScript">Read More: 369 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.jiucool.com/tag/ie/" class="st_tag internal_tag" rel="tag" title="Posts tagged with ie">IE</a> 下不仅N多CSS标准样式表无法识别，而且N多莫名其妙的javascript问题，也就是说在别的浏览器下可以识别的javascript代码，有IE下可能无法识别并且报错，导致某些网页功能无法使用！真杯具！</p>
<p>装一个IE下高度javascript的工具吧：</p>
<ol>
<li>装一个IE-debugbar软件，下载地址（含注册机）<a title="http://d.download.csdn.net/down/2499396/monlyu" href="http://d.download.csdn.net/down/2499396/monlyu" target="_blank">http://d.download.csdn.net/down/2499396/monlyu</a> </li>
<li>安装 Script Debugger&#160; <a title="http://www.microsoft.com/downloads/details.aspx?familyid=2f465be0-94fd-4569-b3c4-dffdf19ccd99&amp;displaylang=en" href="http://www.microsoft.com/downloads/details.aspx?familyid=2f465be0-94fd-4569-b3c4-dffdf19ccd99&amp;displaylang=en" target="_blank">http://www.microsoft.com/downloads/details.aspx?familyid=2f465be0-94fd-4569-b3c4-dffdf19ccd99&amp;displaylang=en</a></li>
<li>然后在IE下的设置启用调试功能
<p>&#160;<a href="http://pic.jiucool.com/2010/09/iedebugerjiucool.jpg"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="ie-debuger-jiucool" border="0" alt="ie-debuger-jiucool" src="http://pic.jiucool.com/2010/09/iedebugerjiucool_thumb.jpg" width="424" height="543" /></a> </li>
</ol>
<p>IE 啊，你都成开发人员的公敌了！若非要用网银，早就将你干掉了！</p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/javascript-debugging-under-ie/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/javascript-debugging-under-ie/#comments">12 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/ie/" rel="tag">ie</a>, <a href="http://www.jiucool.com/tag/ie-%e8%b0%83%e8%af%95javascript/" rel="tag">IE 调试javascript</a>, <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/javascript/" rel="tag">javascript</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/javascript-debugging-under-ie/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Java发送http请求 (get 与 post方法请求)</title>
		<link>http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/</link>
		<comments>http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 16:00:00 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[Http]]></category>
		<category><![CDATA[HttpURLConnection用法]]></category>
		<category><![CDATA[http请求]]></category>
		<category><![CDATA[post]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/</guid>
		<description><![CDATA[Java发送http请求 (get 与 post方法请求)，以下代码经本人亲自调试可用！可以直接使用之。

 注意：通过BufferedReader 读取远程返回的数据时，必须设置读取编码，否则中文会乱码！





package com.jiucool.www.struts.action;

&#160;

<span class="readmore"><a href="http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/" title="Java发送http请求 (get 与 post方法请求)">Read More: 4712 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>Java发送http请求 (<a href="http://www.jiucool.com/tag/get/" class="st_tag internal_tag" rel="tag" title="Posts tagged with get">get</a> 与 post方法请求)，以下代码经本人亲自调试可用！可以直接使用之。
<p /> 注意：通过BufferedReader 读取远程返回的数据时，必须设置读取编码，否则中文会乱码！
<p />

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.jiucool.www.struts.action</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.DataOutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStreamReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.HttpURLConnection</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URLEncoder</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> post_request <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> GET_URL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.jiucool.com/request.php?key=j0r56u2&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> POST_URL <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.jiucool.com/request.php&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> readContentFromGet<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// 拼凑get请求的URL字串，使用URLEncoder.encode对特殊和不可见字符进行编码</span>
        <span style="color: #003399;">String</span> getURL <span style="color: #339933;">=</span> GET_URL <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;&amp;activatecode=&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">URLEncoder</span>.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;久酷博客&quot;</span>, <span style="color: #0000ff;">&quot;utf-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">URL</span> getUrl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span>getURL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// 根据拼凑的URL，打开连接，URL.openConnection函数会根据URL的类型，</span>
        <span style="color: #666666; font-style: italic;">// 返回不同的URLConnection子类的对象，这里URL是一个http，因此实际返回的是HttpURLConnection</span>
        <span style="color: #003399;">HttpURLConnection</span> connection <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">HttpURLConnection</span><span style="color: #009900;">&#41;</span> getUrl
                .<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// 进行连接，但是实际上get request要在下一句的connection.getInputStream()函数中才会真正发到</span>
        <span style="color: #666666; font-style: italic;">// 服务器</span>
        connection.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// 取得输入流，并使用Reader读取</span>
        <span style="color: #003399;">BufferedReader</span> reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>connection.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,<span style="color: #0000ff;">&quot;utf-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//设置编码,否则中文乱码</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=============================&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Contents of get request&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=============================&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">String</span> lines<span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>lines <span style="color: #339933;">=</span> reader.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        	<span style="color: #666666; font-style: italic;">//lines = new String(lines.getBytes(), &quot;utf-8&quot;);</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>lines<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        reader.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// 断开连接</span>
        connection.<span style="color: #006633;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=============================&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Contents of get request ends&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=============================&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> readContentFromPost<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span><span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">// Post请求的url，与get不同的是不需要带参数</span>
        <span style="color: #003399;">URL</span> postUrl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span>POST_URL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// 打开连接</span>
        <span style="color: #003399;">HttpURLConnection</span> connection <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">HttpURLConnection</span><span style="color: #009900;">&#41;</span> postUrl
                .<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Output to the connection. Default is</span>
        <span style="color: #666666; font-style: italic;">// false, set to true because post</span>
        <span style="color: #666666; font-style: italic;">// method must write something to the</span>
        <span style="color: #666666; font-style: italic;">// connection</span>
        <span style="color: #666666; font-style: italic;">// 设置是否向connection输出，因为这个是post请求，参数要放在</span>
        <span style="color: #666666; font-style: italic;">// http正文内，因此需要设为true</span>
        connection.<span style="color: #006633;">setDoOutput</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Read from the connection. Default is true.</span>
        connection.<span style="color: #006633;">setDoInput</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Set the post method. Default is GET</span>
        connection.<span style="color: #006633;">setRequestMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;POST&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Post cannot use caches</span>
        <span style="color: #666666; font-style: italic;">// Post 请求不能使用缓存</span>
        connection.<span style="color: #006633;">setUseCaches</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// This method takes effects to</span>
        <span style="color: #666666; font-style: italic;">// every instances of this class.</span>
        <span style="color: #666666; font-style: italic;">// URLConnection.setFollowRedirects是static函数，作用于所有的URLConnection对象。</span>
        <span style="color: #666666; font-style: italic;">// connection.setFollowRedirects(true);</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// This methods only</span>
        <span style="color: #666666; font-style: italic;">// takes effacts to this</span>
        <span style="color: #666666; font-style: italic;">// instance.</span>
        <span style="color: #666666; font-style: italic;">// URLConnection.setInstanceFollowRedirects是成员函数，仅作用于当前函数</span>
        connection.<span style="color: #006633;">setInstanceFollowRedirects</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Set the content type to urlencoded,</span>
        <span style="color: #666666; font-style: italic;">// because we will write</span>
        <span style="color: #666666; font-style: italic;">// some URL-encoded content to the</span>
        <span style="color: #666666; font-style: italic;">// connection. Settings above must be set before connect!</span>
        <span style="color: #666666; font-style: italic;">// 配置本次连接的Content-type，配置为application/x-www-form-urlencoded的</span>
        <span style="color: #666666; font-style: italic;">// 意思是正文是urlencoded编码过的form参数，下面我们可以看到我们对正文内容使用URLEncoder.encode</span>
        <span style="color: #666666; font-style: italic;">// 进行编码</span>
        connection.<span style="color: #006633;">setRequestProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type&quot;</span>,
                <span style="color: #0000ff;">&quot;application/x-www-form-urlencoded&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// 连接，从postUrl.openConnection()至此的配置必须要在connect之前完成，</span>
        <span style="color: #666666; font-style: italic;">// 要注意的是connection.getOutputStream会隐含的进行connect。</span>
        connection.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">DataOutputStream</span> out <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">DataOutputStream</span><span style="color: #009900;">&#40;</span>connection
                .<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// The URL-encoded contend</span>
        <span style="color: #666666; font-style: italic;">// 正文，正文内容其实跟get的URL中'?'后的参数字符串一致</span>
        <span style="color: #003399;">String</span> content <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;key=j0r53nmbbd78x7m1pqml06u2&amp;type=1&amp;toemail=jiucool@gmail.com&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;&amp;activatecode=&quot;</span> <span style="color: #339933;">+</span> <span style="color: #003399;">URLEncoder</span>.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;久酷博客&quot;</span>, <span style="color: #0000ff;">&quot;utf-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// DataOutputStream.writeBytes将字符串中的16位的unicode字符以8位的字符形式写道流里面</span>
        out.<span style="color: #006633;">writeBytes</span><span style="color: #009900;">&#40;</span>content<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
        out.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        out.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// flush and close</span>
        <span style="color: #003399;">BufferedReader</span> reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>connection.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>,<span style="color: #0000ff;">&quot;utf-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//设置编码,否则中文乱码</span>
        <span style="color: #003399;">String</span> line<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=============================&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Contents of post request&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=============================&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> reader.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//line = new String(line.getBytes(), &quot;utf-8&quot;);</span>
            <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=============================&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Contents of post request ends&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;=============================&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        reader.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        connection.<span style="color: #006633;">disconnect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>HttpURLConnection.connect函数，实际上只是建立了一个与服务器的tcp连接，并没有实际发送http请求。无论是post还是get，http请求实际上直到HttpURLConnection.getInputStream()这个函数里面才正式发送出去。</p>
<p>在readContentFromPost() 中，顺序是重中之重，对connection对象的一切配置（那一堆set函数）都必须要在connect()函数执行之前完成。而对 outputStream的写操作，又必须要在inputStream的读操作之前。这些顺序实际上是由http请求的格式决定的。</p>
<p><a href="http://www.jiucool.com/tag/http/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Http">http</a> 请求实际上由两部分组成，一个是http头，所有关于此次http请求的配置都在http头里面定义，一个是正文content，在connect()函数里面，会根据HttpURLConnection对象的配置值生成http头，因此在调用connect函数之前，就必须把所有的配置准备好。</p>
<p>紧接着http头的是http请求的正文，正文的内容通过outputStream写入，实际上outputStream不是一个网络流，充其量是个字符串流，往里面写入的东西不会立即发送到网络，而是在流关闭后，根据输入的内容生成http正文。</p>
<p>至此，http请求的东西已经准备就绪。在getInputStream()函数调用的时候，就会把准备好的http请求正式发送到服务器了，然后返回一个输入流，用于读取服务器对于此次http请求的返回信息。由于http请求在getInputStream的时候已经发送出去了（包括http头和正文），因此在getInputStream()函数之后对connection对象进行设置（对http头的信息进行修改）或者写入 outputStream（对正文进行修改）都是没有意义的了，执行这些操作会导致异常的发生。<br />
来自：<a href="http://blog.csdn.net/pandazxx/archive/2007/06/18/1657109.aspx" target="_blank">pandazxx CSDN</a></p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/#comments">16 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/get/" rel="tag">get</a>, <a href="http://www.jiucool.com/tag/http/" rel="tag">Http</a>, <a href="http://www.jiucool.com/tag/httpurlconnection%e7%94%a8%e6%b3%95/" rel="tag">HttpURLConnection用法</a>, <a href="http://www.jiucool.com/tag/http%e8%af%b7%e6%b1%82/" rel="tag">http请求</a>, <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/post/" rel="tag">post</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/java-sending-http-requests-get-and-post-method-request/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>JAVA 打开文件乱码 解决办法</title>
		<link>http://www.jiucool.com/java-file-unreadable-code-open-solution/</link>
		<comments>http://www.jiucool.com/java-file-unreadable-code-open-solution/#comments</comments>
		<pubDate>Fri, 20 Aug 2010 16:00:00 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[BufferedReader]]></category>
		<category><![CDATA[乱码]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/java-file-unreadable-code-open-solution/</guid>
		<description><![CDATA[有些问题有时很奇怪，也很让人恼火，GBK、GB2312是什么编码，当然是汉字编码喽，而常常汉字编码不认识汉字，是不是让人恼火呢？

 下面这部分代码的意思是打开D盘目录下的file_jiucool.txt文件 ，然后在控制台将其内容输出！





String Data_Path = &#34;D:/file_jiucool.txt&#34;;

		File file = new File&#40;Data_Path&#41;;

<span class="readmore"><a href="http://www.jiucool.com/java-file-unreadable-code-open-solution/" title="JAVA 打开文件乱码 解决办法">Read More: 963 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>有些问题有时很奇怪，也很让人恼火，GBK、GB2312是什么编码，当然是汉字编码喽，而常常汉字编码不认识汉字，是不是让人恼火呢？
<p /> 下面这部分代码的意思是打开D盘目录下的file_jiucool.txt文件 ，然后在控制台将其内容输出！
<p />

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> Data_Path <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;D:/file_jiucool.txt&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">File</span> file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>Data_Path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> line<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>		
			<span style="color: #003399;">FileReader</span> reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileReader</span><span style="color: #009900;">&#40;</span>Data_Path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
			<span style="color: #003399;">BufferedReader</span> bufferedreader<span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span>reader<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> bufferedreader.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					line <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">String</span><span style="color: #009900;">&#40;</span>line.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span></pre></div></div>

<p>上述代码中，设置为GBK、GB2312 时全部为乱码，设置为UTF-8时，最后一个汉字为乱码，是不是很让人郁闷？正确代码如下：
<p />

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> Data_Path <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;D:/file_jiucool.txt&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">File</span> file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">File</span><span style="color: #009900;">&#40;</span>Data_Path<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> line<span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>file.<span style="color: #006633;">exists</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>		
			<span style="color: #666666; font-style: italic;">//FileReader reader = new FileReader(Data_Path);	</span>
			<span style="color: #666666; font-style: italic;">//BufferedReader bufferedreader= new BufferedReader(reader);</span>
			<span style="color: #003399;">InputStreamReader</span> isr <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">FileInputStream</span><span style="color: #009900;">&#40;</span>file<span style="color: #009900;">&#41;</span>, <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003399;">BufferedReader</span> bufferedreader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span>isr<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> bufferedreader.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=</span><span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #666666; font-style: italic;">//line = new String(line.getBytes(), &quot;UTF-8&quot;);</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span></pre></div></div>

<p>所以，在读取文件的时候就得进行编码设置，而不是读完文件输出时再设置编码！</p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/java-file-unreadable-code-open-solution/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/java-file-unreadable-code-open-solution/#comments">6 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/bufferedreader/" rel="tag">BufferedReader</a>, <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/%e4%b9%b1%e7%a0%81/" rel="tag">乱码</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/java-file-unreadable-code-open-solution/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Java 与 PHP 发送get请求并获取远程内容</title>
		<link>http://www.jiucool.com/java-php-get-remote-doget-method-content/</link>
		<comments>http://www.jiucool.com/java-php-get-remote-doget-method-content/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 16:00:00 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[doget请求]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[调用远程内容]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/?p=8266</guid>
		<description><![CDATA[既然两种语言都玩，就有得对比了，先看JAVA实现，再来看PHP，当然实现的方法有很多种特别是JAVA对于同一种功能的实现绝对比PHP多很多，这点是毫无疑问的！

JAVA实现方法一：



package com.jiucool.www.struts.action;

&#160;

import java.io.BufferedReader;

<span class="readmore"><a href="http://www.jiucool.com/java-php-get-remote-doget-method-content/" title="Java 与 PHP 发送get请求并获取远程内容">Read More: 971 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>既然两种语言都玩，就有得对比了，先看JAVA实现，再来看PHP，当然实现的方法有很多种特别是JAVA对于同一种功能的实现绝对比PHP多很多，这点是毫无疑问的！</p>
<p>JAVA实现方法一：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.jiucool.www.struts.action</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStreamReader</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.MalformedURLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URLConnection</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> doget_http_request<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> doget_http_request<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003399;">StringBuffer</span> readOneLineBuff <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringBuffer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span> content <span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">URL</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.jiucool.com/sendemail.php?key=j0r53nmbbd78x7m1&quot;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;&amp;activatecode=2QyiF0SXXTq8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">URLConnection</span> conn <span style="color: #339933;">=</span> url.<span style="color: #006633;">openConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">BufferedReader</span> reader <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedReader</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InputStreamReader</span><span style="color: #009900;">&#40;</span>conn.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
		<span style="color: #003399;">String</span> line <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>line <span style="color: #339933;">=</span> reader.<span style="color: #006633;">readLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			readOneLineBuff.<span style="color: #006633;">append</span><span style="color: #009900;">&#40;</span>line<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		 content <span style="color: #339933;">=</span> readOneLineBuff.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		reader.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">MalformedURLException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		e2.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
	<span style="color: #000000; font-weight: bold;">return</span> content<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>对于PHP的实现，简单得让人要跳楼，看代码：
<p />

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://www.jiucool.com/sendemail.php?key=j0r53nmbbd78x7m1&amp;activatecode=2QyiF0SXXTq8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>PHP实在太简单了！不过有一点，PHP的弱类型语言让人实在有点不习惯，变量不声明即可使用，太不严谨了！</p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/java-php-get-remote-doget-method-content/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/java-php-get-remote-doget-method-content/#comments">3 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/doget%e8%af%b7%e6%b1%82/" rel="tag">doget请求</a>, <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/php-2/" rel="tag">php</a>, <a href="http://www.jiucool.com/tag/%e8%b0%83%e7%94%a8%e8%bf%9c%e7%a8%8b%e5%86%85%e5%ae%b9/" rel="tag">调用远程内容</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/java-php-get-remote-doget-method-content/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Java 与 PHP 的MD5加密方法</title>
		<link>http://www.jiucool.com/java-and-phps-md5-encryption/</link>
		<comments>http://www.jiucool.com/java-and-phps-md5-encryption/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 02:27:37 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[java md5加密]]></category>
		<category><![CDATA[md5]]></category>
		<category><![CDATA[md5加密]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/?p=8236</guid>
		<description><![CDATA[不得不说java要比复杂很多很多，包括相关配置，使用以及具体开发方面！对于PHP 你自学几天就可以写东西了，但对于java有点难度！

最近写的代码，同时用到了php 与java，来看看其MD5加密方法：

java里MD5没有现成的方法，只得自己写一个，如下：



public static String EncoderByMd5&#40;String str&#41;&#123;

		if&#40;isNull&#40;str&#41;&#41;&#123;

<span class="readmore"><a href="http://www.jiucool.com/java-and-phps-md5-encryption/" title="Java 与 PHP 的MD5加密方法">Read More: 470 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>不得不说java要比复杂很多很多，包括相关配置，使用以及具体开发方面！对于PHP 你自学几天就可以写东西了，但对于java有点难度！</p>
<p>最近写的代码，同时用到了php 与java，来看看其MD5加密方法：</p>
<p>java里MD5没有现成的方法，只得自己写一个，如下：</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">String</span> EncoderByMd5<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> str<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>isNull<span style="color: #009900;">&#40;</span>str<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">//确定计算方法</span>
			<span style="color: #003399;">MessageDigest</span> md5<span style="color: #339933;">=</span> <span style="color: #003399;">MessageDigest</span>.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;MD5&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			BASE64Encoder base64en <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BASE64Encoder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">//加密后的字符串</span>
			<span style="color: #003399;">String</span> newstr<span style="color: #339933;">=</span>base64en.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span>md5.<span style="color: #006633;">digest</span><span style="color: #009900;">&#40;</span>str.<span style="color: #006633;">getBytes</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;utf-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> newstr.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> str.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p><a href="http://www.jiucool.com/tag/php-2/" class="st_tag internal_tag" rel="tag" title="Posts tagged with php">php</a> MD5加密非常简单直接这样就可以了：</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>差别与难易程度确实有点大！</p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/java-and-phps-md5-encryption/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/java-and-phps-md5-encryption/#comments">8 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/java-md5%e5%8a%a0%e5%af%86/" rel="tag">java md5加密</a>, <a href="http://www.jiucool.com/tag/md5/" rel="tag">md5</a>, <a href="http://www.jiucool.com/tag/md5%e5%8a%a0%e5%af%86/" rel="tag">md5加密</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/java-and-phps-md5-encryption/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Java 上传文件过程及清空相关缓存目录</title>
		<link>http://www.jiucool.com/java-upload-process-and-empty-the-cache-directory-associated/</link>
		<comments>http://www.jiucool.com/java-upload-process-and-empty-the-cache-directory-associated/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 07:25:10 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[上传文件]]></category>
		<category><![CDATA[清空子目录]]></category>
		<category><![CDATA[清空文件]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/?p=8200</guid>
		<description><![CDATA[一个类+几个方法,写过一次的东西，就要记录下来，以后可以方便的使用！



	//提交注册3 &#38;&#38; 上传相关图片

public ActionForward reg_enterprise_3&#40;ActionMapping mapping, ActionForm form,

		HttpServletRequest request, HttpServletResponse response&#41;

<span class="readmore"><a href="http://www.jiucool.com/java-upload-process-and-empty-the-cache-directory-associated/" title="Java 上传文件过程及清空相关缓存目录">Read More: 1728 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>一个类+几个方法,写过一次的东西，就要记录下来，以后可以方便的使用！</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">	<span style="color: #666666; font-style: italic;">//提交注册3 &amp;&amp; 上传相关图片</span>
<span style="color: #000000; font-weight: bold;">public</span> ActionForward reg_enterprise_3<span style="color: #009900;">&#40;</span>ActionMapping mapping, ActionForm form,
		HttpServletRequest request, HttpServletResponse response<span style="color: #009900;">&#41;</span>
		<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>, ServletException <span style="color: #009900;">&#123;</span>
	UserInfo userinfo <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>UserInfo<span style="color: #009900;">&#41;</span>request.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;willRegUser&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">int</span> uid <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getUserInfoService</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">insert</span><span style="color: #009900;">&#40;</span>userinfo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">String</span> mark <span style="color: #339933;">=</span> StringUtils.<span style="color: #006633;">getParameter</span><span style="color: #009900;">&#40;</span>request, <span style="color: #0000ff;">&quot;mark&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jump_jiucool&quot;</span>.<span style="color: #006633;">equalsIgnoreCase</span><span style="color: #009900;">&#40;</span>mark<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		ActionForward gotourl <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ActionForward<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		gotourl.<span style="color: #006633;">setPath</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/reg_enterprise4.jsp);
		gotourl.setRedirect(true);
		return gotourl;
	}
	CookieUtils.setCookie(request, response, &quot;</span>umobile_jiucool<span style="color: #0000ff;">&quot;, userinfo.getMsisdn(),60*60*24*30);
	CookieUtils.setCookie(request, response, &quot;</span>uemail_jiucool<span style="color: #0000ff;">&quot;, userinfo.getEmail(),60*60*24*30);
	CookieUtils.setCookie(request, response, &quot;</span>uid_jiucool<span style="color: #0000ff;">&quot;, String.valueOf(userinfo.getId()),60*60*24*30);
	request.getSession().setAttribute(Constants.USER_SESSION, new SessionUser(userinfo.getId()));
	String tempFilePath = Constants.PIC_UPLOAD_PATH + &quot;</span>enterprisePic<span style="color: #339933;">/</span>temp<span style="color: #0000ff;">&quot; + &quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot;;
	try {
		File file = new File(tempFilePath);
		if(!file.exists()){
			file.mkdirs();
		}
		DiskFileItemFactory factory = new DiskFileItemFactory();
		factory.setSizeThreshold(4*1024);
		factory.setRepository(new File(tempFilePath));
		ServletFileUpload upload = new ServletFileUpload(factory);
		upload.setSizeMax(4*1024*1024);
		List items = upload.parseRequest(request);
		Iterator iter = items.iterator();
		Integer type=0;
		while(iter.hasNext()){
			FileItem item = (FileItem)iter.next();
			String filename = item.getFieldName();
			if(filename.equalsIgnoreCase(&quot;</span>uploadface<span style="color: #0000ff;">&quot;)){
				type=1;
			}else if(filename.equalsIgnoreCase(&quot;</span>uploadidcard<span style="color: #0000ff;">&quot;)){
				type=2;
			}			
			if(!item.isFormField()){
				this.processUploadedFile(item, userinfo, type);
			}
		}
		Boolean flag = true;
		 File dirFile = new File(tempFilePath);     	       
		  File[] files = dirFile.listFiles();     
		        for(int i=0;i&lt;files.length;i++){     
		             //删除子文件     
		             if(files[i].isFile()){     
		                 flag = deleteFile(files[i].getAbsolutePath());     
		                 if(!flag){     
		                     break;     
		                 }     
		             }     
		             //删除子目录     
		             else{     
		                 flag = deleteDirectory(files[i].getAbsolutePath());     
		                 if(!flag){     
		                     break;     
		                 }     
		             }     
		         }     
	}catch(Exception e){
		throw new ServletException(e);
	}	
	ActionForward gotourl = new ActionForward();
	gotourl.setPath(&quot;</span><span style="color: #339933;">/</span>reg_enterprise4.<span style="color: #006633;">jsp</span><span style="color: #339933;">?</span>uid<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot; + userinfo.getId());
	gotourl.setRedirect(true);
	return gotourl;
}
private void processUploadedFile(FileItem item,UserInfo userinfo,Integer type) throws Exception{
	String filename = item.getName();
	int index=filename.lastIndexOf(&quot;</span>\\<span style="color: #0000ff;">&quot;);
	filename = filename.substring(index+1, filename.length());
	long fileSize = item.getSize();
	if(filename.equals(&quot;</span><span style="color: #0000ff;">&quot;) &amp;&amp; fileSize ==0)return;
	String suffixName =  item.getName().substring(
			 item.getName().lastIndexOf(&quot;</span>.<span style="color: #0000ff;">&quot;));
	if(&quot;</span>.<span style="color: #006633;">png</span><span style="color: #0000ff;">&quot;.equalsIgnoreCase(suffixName) || &quot;</span>.<span style="color: #006633;">jpg</span><span style="color: #0000ff;">&quot;.equalsIgnoreCase(suffixName)
			|| &quot;</span>.<span style="color: #006633;">gif</span><span style="color: #0000ff;">&quot;.equalsIgnoreCase(suffixName) || &quot;</span>.<span style="color: #006633;">jpeg</span><span style="color: #0000ff;">&quot;.equalsIgnoreCase(suffixName)){
		// 数据库存入路径					
		filename = System.currentTimeMillis() + suffixName;
&nbsp;
		String adFileName =&quot;</span><span style="color: #0000ff;">&quot;;
		if(type==1){
			 adFileName = StringUtils.replaceChar(userinfo.getId()*11,&quot;</span><span style="color: #339933;">-</span><span style="color: #0000ff;">&quot;) + &quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot; + DateUtils.format(&quot;</span>yyyMMdd<span style="color: #0000ff;">&quot;, new Date()) + &quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot;;
			 FileUtils.saveFileStream(item.getInputStream(),Constants.FACE_UPLOAD_PATH , adFileName + filename);
				userinfo.setFace(&quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot; + adFileName + filename);
				this.getUserInfoService().update(userinfo);
		}else if(type==2){
			 adFileName = &quot;</span>enterprisePic<span style="color: #339933;">/</span><span style="color: #0000ff;">&quot; + &quot;</span>idcard<span style="color: #0000ff;">&quot; + &quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot; + DateUtils.format(&quot;</span>yyyMMdd<span style="color: #0000ff;">&quot;, new Date()) + &quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot;;
			userinfo.setComidcard(adFileName + filename);				
		}else if(type==3){
			 adFileName = &quot;</span>enterprisePic<span style="color: #339933;">/</span><span style="color: #0000ff;">&quot; + &quot;</span>comlicense<span style="color: #0000ff;">&quot; + &quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot; + DateUtils.format(&quot;</span>yyyMMdd<span style="color: #0000ff;">&quot;, new Date()) + &quot;</span><span style="color: #339933;">/</span><span style="color: #0000ff;">&quot;;
				userinfo.setComlicense(adFileName + filename);
			}
			if(type&gt;1){
				this.getUserInfoService().update(userinfo);
				FileUtils.saveFileStream(item.getInputStream(),Constants.PIC_UPLOAD_PATH,adFileName + filename);
			}
		}
	}
  /**   
   * 删除单个文件   
   * @param   fileName    被删除文件的文件名   
   * @return 单个文件删除成功返回true,否则返回false   
   */    
  public static boolean deleteFile(String fileName){     
      File file = new File(fileName);     
      if(file.isFile() &amp;&amp; file.exists()){     
          file.delete();     
      return true;     
  }else{     
          return false;     
      }     
  }     
&nbsp;
  /**   
   * 删除目录（文件夹）以及目录下的文件   
   * @param   dir 被删除目录的文件路径   
   * @return  目录删除成功返回true,否则返回false   
   */    
  public static boolean deleteDirectory(String dir){     
      //如果dir不以文件分隔符结尾，自动添加文件分隔符     
  if(!dir.endsWith(File.separator)){     
      dir = dir+File.separator;     
  }     
  File dirFile = new File(dir);     
  //如果dir对应的文件不存在，或者不是一个目录，则退出     
  if(!dirFile.exists() || !dirFile.isDirectory()){     
      System.out.println(&quot;</span>删除目录失败<span style="color: #0000ff;">&quot;+dir+&quot;</span>目录不存在！<span style="color: #0000ff;">&quot;);     
      return false;     
  }     
  boolean flag = true;     
  //删除文件夹下的所有文件(包括子目录)     
  File[] files = dirFile.listFiles();     
  for(int i=0;i&lt;files.length;i++){     
      //删除子文件     
  if(files[i].isFile()){     
      flag = deleteFile(files[i].getAbsolutePath());     
      if(!flag){     
          break;     
      }     
  }     
  //删除子目录     
      else{     
          flag = deleteDirectory(files[i].getAbsolutePath());     
          if(!flag){     
              break;     
          }     
      }     
  }     
&nbsp;
  if(!flag){     
      System.out.println(&quot;</span>删除目录失败<span style="color: #0000ff;">&quot;);     
      return false;     
  }     
&nbsp;
  //删除当前目录     
  if(dirFile.delete()){     
      System.out.println(&quot;</span>删除目录<span style="color: #0000ff;">&quot;+dir+&quot;</span>成功！<span style="color: #0000ff;">&quot;);     
      return true;     
  }else{     
      System.out.println(&quot;</span>删除目录<span style="color: #0000ff;">&quot;+dir+&quot;</span>失败！<span style="color: #0000ff;">&quot;);     
          return false;     
      }     
  }</span></pre></div></div>

<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/java-upload-process-and-empty-the-cache-directory-associated/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/java-upload-process-and-empty-the-cache-directory-associated/#comments">3 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/%e4%b8%8a%e4%bc%a0%e6%96%87%e4%bb%b6/" rel="tag">上传文件</a>, <a href="http://www.jiucool.com/tag/%e6%b8%85%e7%a9%ba%e5%ad%90%e7%9b%ae%e5%bd%95/" rel="tag">清空子目录</a>, <a href="http://www.jiucool.com/tag/%e6%b8%85%e7%a9%ba%e6%96%87%e4%bb%b6/" rel="tag">清空文件</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/java-upload-process-and-empty-the-cache-directory-associated/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>sitemapindex站点地图索引文件用法</title>
		<link>http://www.jiucool.com/sitemapindex-usage/</link>
		<comments>http://www.jiucool.com/sitemapindex-usage/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 19:14:09 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[xml]]></category>
		<category><![CDATA[应用相关]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sitemap]]></category>
		<category><![CDATA[sitemapindex]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/?p=7894</guid>
		<description><![CDATA[昨晚有朋友发来问我关于上篇文章（大型网站Sitemap生成方法）关于如何将child-sitemap写入到main-sitemap中，这里主要是用到的站点地图协议sitemapindex！

sitemapindex主要包括以下几个标记！



&#60;sitemapindex&#62; &#8211; 文件头尾的父标记。 





<span class="readmore"><a href="http://www.jiucool.com/sitemapindex-usage/" title="sitemapindex站点地图索引文件用法">Read More: 540 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>昨晚有朋友发来问我关于上篇文章（<a href="http://www.jiucool.com/large-scale-web-site-sitemap-generate/">大型网站Sitemap生成方法</a>）关于如何将child-sitemap写入到main-sitemap中，这里主要是用到的站点地图协议sitemapindex！</p>
<p><a href="http://www.jiucool.com/sitemapindex-usage/">sitemapindex</a>主要包括以下几个标记！</p>
<ul>
<li><strong>&lt;sitemapindex&gt;</strong> &#8211; 文件头尾的父标记。 </li>
</ul>
<ul>
<li><strong>&lt;<a href="http://www.jiucool.com/tag/sitemap/" class="st_tag internal_tag" rel="tag" title="Posts tagged with sitemap">sitemap</a>&gt;</strong> &#8211; 文件中列出的每个站点地图的父标记（<strong>&lt;sitemapindex&gt;</strong> 的子标记） </li>
</ul>
<ul>
<li><strong>&lt;loc&gt;</strong> &#8211; 站点地图的位置（<strong>&lt;sitemap&gt;</strong> 的子标记） </li>
</ul>
<ul>
<li><strong>&lt;lastmod&gt;</strong> &#8211; 站点地图 的上次修改日期（可选） </li>
</ul>
<p>示例如下：</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sitemapindex</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sitemap<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;loc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://www.example.com/sitemap1.xml.gz<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/loc<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastmod<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2010-12-01T18:28:17+00:00<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastmod<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sitemap<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sitemapindex<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>并且我发现了一个很有意思的现象，网易的网站地图居然连sitemap协议都不遵守，不知网易的开发人员是咋搞的！网易sitemap地址：<a href="http://www.jiucool.com/tag/http/" class="st_tag internal_tag" rel="tag" title="Posts tagged with Http">http</a>://news.163.com/sitemap.<a href="http://www.jiucool.com/tag/xml/" class="st_tag internal_tag" rel="tag" title="Posts tagged with xml">xml</a>，趁网易人员没看到此文章赶紧上图来看看：</p>
<p><img src="http://pic.jiucool.com/2010/06/网易sitemap.jpg" /> </p>
<p>从图中我们可以看到，网易开发人员居然直接将sitemap写成了urlset的子标签！将urlset 与sitemapindex子标签内容混合编写，这就相当于将向柴油机里加水，无论加多少也跑不起来啊！杯具！这种写法明显不符合协议规则！</p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/sitemapindex-usage/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/sitemapindex-usage/#comments">9 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/sitemap/" rel="tag">sitemap</a>, <a href="http://www.jiucool.com/tag/sitemapindex/" rel="tag">sitemapindex</a>, <a href="http://www.jiucool.com/tag/xml/" rel="tag">xml</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/sitemapindex-usage/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>大型网站Sitemap生成方法</title>
		<link>http://www.jiucool.com/large-scale-web-site-sitemap-generate/</link>
		<comments>http://www.jiucool.com/large-scale-web-site-sitemap-generate/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 13:13:30 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[xml]]></category>
		<category><![CDATA[应用相关]]></category>
		<category><![CDATA[dom4j]]></category>
		<category><![CDATA[google sitemap]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[sitemap]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/?p=7873</guid>
		<description><![CDATA[Sitemap对我们大家来说并不陌生，稍懂SEO的人就知其作用！我们最常用的WordPress也有相应的插件来实现，但我个人觉得我们最常用的Baidu Sitemap Generator、Google XML Sitemaps等等插件生成机制并不是很是很完善！

原因为何？请看下文分解：

因为搜索引擎对sitemap其中的网址数目抓取有一定的限制，记得最早的时候，google对于一个sitemap只可以抓取1000个网址,后来才大幅增加！不管一个sitemap可抓取数量现在具体增加到了多少，但肯定数目的多少对搜索引擎的抓取肯定有影响，既然有影响我们为何不做得更完美一些呢！

<span class="readmore"><a href="http://www.jiucool.com/large-scale-web-site-sitemap-generate/" title="大型网站Sitemap生成方法">Read More: 1002 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>Sitemap对我们大家来说并不陌生，稍懂SEO的人就知其作用！我们最常用的WordPress也有相应的插件来实现，但我个人觉得我们最常用的<strong>Baidu Sitemap Generator、Google <a href="http://www.jiucool.com/tag/xml/" class="st_tag internal_tag" rel="tag" title="Posts tagged with xml">XML</a> Sitemaps</strong>等等插件生成机制并不是很是很完善！</p>
<p><strong>原因为何？请看下文分解：</strong></p>
<p>因为搜索引擎对<a href="http://www.jiucool.com/large-scale-web-site-sitemap-generate/">sitemap</a>其中的网址数目抓取有一定的限制，记得最早的时候，google对于一个sitemap只可以抓取1000个网址,后来才大幅增加！不管一个sitemap可抓取数量现在具体增加到了多少，但肯定数目的多少对搜索引擎的抓取肯定有影响，既然有影响我们为何不做得更完美一些呢！</p>
<p>并且如果sitemap如果是单个文件的话，量级太大，再加服务器速度太慢，估计没有几分钟是显示不出来的！现在google也将速度指标加入PR里，单个页面不宜过大！</p>
<p><strong>Baidu Sitemap Generator、Google XML Sitemaps</strong>等插件全部是采用单文件形式，并且生成机制也有待完善，如果你WP网站文章很少没问题，但当用WP建大型网站时文章数很多，各种问题就随之而来了！！</p>
<p>所以<a href="http://www.jiucool.com/large-scale-web-site-sitemap-generate/">多sitemap机制</a>更有利于搜索引擎快速、顺利的抓取！</p>
<p><strong>何为多sitemap机制？</strong> 首先我们生成一个主sitemap（我们用main-sitemap来称呼吧）文件，此文件为sitemapindex类型，其中存放子sitemap文件（我们称之为child-sitemap吧，下同）！child-sitemap文件只用来存放具体文章item. 这里我们假定每个child-sitemap存放网址数为5000个！</p>
<p><strong>我画了一个流程图，我的思路是这样的：</strong></p>
<p><a href="http://pic.jiucool.com/2010/06/jiucoolsitemap1.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="jiucool关于sitemap生成思路" border="0" alt="jiucool关于sitemap生成思路" src="http://pic.jiucool.com/2010/06/jiucoolsitemap_thumb1.jpg" width="554" height="409" /></a> </p>
<p>这样我们只需提交一个main-sitemap就可以了，搜索引擎就会通过main-sitemap找到其他所有的child-sitemap文件，并索引之！另外还写了一个方法，就是初始化全站sitemap生成，还一个是删除文章时item条目删除！ 这一起加起来就构成了一个完整的sitemap更新机制！ </p>
<p>嗯，这就是今天的工作，从流程到实现，搞定！</p>
<p>如果大家还有更好的方法，欢迎拍砖！</p>
<p>PS. 之前有朋友说每次不必那么麻烦，查找 插入删除item，何不直接删除文件重建？？这样逻辑更简单！ 简单是简单，但是对于大型网站来说，文章数至少是几万级别以上的，如果每更新一篇文章，如果重建一次，服务器肯定承受不住！所以采取逻辑复杂一些，服务器消耗更少！</p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/large-scale-web-site-sitemap-generate/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/large-scale-web-site-sitemap-generate/#comments">20 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/dom4j/" rel="tag">dom4j</a>, <a href="http://www.jiucool.com/tag/google-sitemap/" rel="tag">google sitemap</a>, <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/sitemap/" rel="tag">sitemap</a>, <a href="http://www.jiucool.com/tag/xml/" rel="tag">xml</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/large-scale-web-site-sitemap-generate/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>dom4j为生成XML的文件添加xmlns属性</title>
		<link>http://www.jiucool.com/dom4j-xml-xmlns/</link>
		<comments>http://www.jiucool.com/dom4j-xml-xmlns/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 09:42:13 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[xml]]></category>
		<category><![CDATA[应用相关]]></category>
		<category><![CDATA[dom4j]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[xmlns]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/?p=7864</guid>
		<description><![CDATA[今天在开发sitemap地图时遇到一个小小问题，就是xmlns属性的添加！我们知道sitmap 根结点有一些属性！大体如下：





1

2

3

<span class="readmore"><a href="http://www.jiucool.com/dom4j-xml-xmlns/" title="dom4j为生成XML的文件添加xmlns属性">Read More: 557 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>今天在开发sitemap地图时遇到一个小小问题，就是xmlns属性的添加！我们知道sitmap 根结点有一些属性！大体如下：
<p/>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;urlset</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span> </span>
<span style="color: #009900;"><span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/urlset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><a href="http://www.jiucool.com/tag/xmlns/" class="st_tag internal_tag" rel="tag" title="Posts tagged with xmlns">xmlns</a> 是什么 意思，字面意思我们就可以理解，意思就是XML（可扩展标识语言）命名空间！而我们在添加此类属性时一般是用的addAttribute, addNamespce 方法！但实际使用上来看，都不行。
<p/>
经研究发现原来如此:
<p/>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Document</span> document <span style="color: #339933;">=</span> DocumentHelper.<span style="color: #006633;">createDocument</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">Element</span> urlset <span style="color: #339933;">=</span> document.<span style="color: #006633;">addElement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;urlset&quot;</span>, <span style="color: #0000ff;">&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
urlset.<span style="color: #006633;">addNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xsi&quot;</span>,<span style="color: #0000ff;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
urlset.<span style="color: #006633;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xsi:schemaLocation&quot;</span>,<span style="color: #0000ff;">&quot;http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>也就是在生成根结点的时候，直接生成了他的命名空间! OK，完美搞定！</p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/dom4j-xml-xmlns/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/dom4j-xml-xmlns/#comments">8 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/dom4j/" rel="tag">dom4j</a>, <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/xml/" rel="tag">xml</a>, <a href="http://www.jiucool.com/tag/xmlns/" rel="tag">xmlns</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/dom4j-xml-xmlns/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>dom4j 删除XML节点</title>
		<link>http://www.jiucool.com/remove-xml-node-dom4j/</link>
		<comments>http://www.jiucool.com/remove-xml-node-dom4j/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 11:37:14 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[xml]]></category>
		<category><![CDATA[应用相关]]></category>
		<category><![CDATA[dom4j]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/?p=7845</guid>
		<description><![CDATA[今天完善开发了一下JAVA RSS生成程序，主要是对XML文件的操作！整理一下思路是这样的：



若XML文件不存在，则生成之

若文件存在，并且新文章与原有item不重复，将新文章内容插入之

删除文章，删除item

控制文章数目变量rssCount，超出该数值先删除最旧的item，然后再插入数据，保证生成数据的准确性。

<span class="readmore"><a href="http://www.jiucool.com/remove-xml-node-dom4j/" title="dom4j 删除XML节点">Read More: 557 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>今天完善开发了一下JAVA RSS生成程序，主要是对XML文件的操作！整理一下思路是这样的：
<ol>
<li>若XML文件不存在，则生成之</li>
<li>若文件存在，并且新文章与原有item不重复，将新文章内容插入之</li>
<li>删除文章，删除item</li>
<li>控制文章数目变量rssCount，超出该数值先删除最旧的item，然后再插入数据，保证生成数据的准确性。</li>
</ol>
<p> OK,这样就搞定！
<p /> 折腾了半天时间主要浪费在了查找相关API文档及节点删除问题上！ 其实代码写出来很简单，没多少，但思考的时间却是蛮多！
<p /></p>
<p> 下面来看看这个删除XML节点的代码片段：
<p />

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">List</span> itemList <span style="color: #339933;">=</span> document.<span style="color: #006633;">selectNodes</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;//rss/channel/item&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//获得item节点list对象</span>
<span style="color: #000066; font-weight: bold;">int</span> itemListsize <span style="color: #339933;">=</span> itemList.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> delarray <span style="color: #339933;">=</span> getInItemNumber<span style="color: #009900;">&#40;</span>RssUtils.<span style="color: #006633;">getFilename</span><span style="color: #009900;">&#40;</span>bbsinfo.<span style="color: #006633;">getTypeid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//获得每个item对象的guid 标识符并通过getInItemNumber方法对其排序，</span>
<span style="color: #666666; font-style: italic;">//当然如果本来已经是有序的则不需另作排序</span>
<span style="color: #000066; font-weight: bold;">int</span> delorder <span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>itemListsize <span style="color: #339933;">&gt;=</span> rssCount<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">//rssCount控制RSS输出数量	</span>
	<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>x <span style="color: #339933;">&lt;</span>itemList.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>								
		<span style="color: #003399;">Element</span> itemElement <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span><span style="color: #009900;">&#41;</span>itemList.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">Element</span> guidElement <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span><span style="color: #009900;">&#41;</span>itemElement.<span style="color: #006633;">element</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;guid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>guidElement.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span>.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>delarray<span style="color: #009900;">&#91;</span>delorder<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			itemElement.<span style="color: #006633;">detach</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//删除节点通过detach()方法，查了半天API文档才找到</span>
			<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		 <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		delorder<span style="color: #339933;">++;</span>
		itemListsize<span style="color: #339933;">--;</span><span style="color: #666666; font-style: italic;">//这里的++ -- 一定不能忘,否则无限循环!</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>哈哈,我这样标注得够详细了吧!我在网上看到很多朋友是用Iterator进行迭代，个人感觉Iterator在这里不好用，用之麻烦！</p>
<p/>
嗯，除了删除节点问题其他的关于XML文档的生成与添加数据还算容易！</p>
<p />PS. 之前在博客整天喷些没用的东西，嗯，现在写点与工作相关的吧，以做思想标记与日后查找,HOHO&#8230;.</p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/remove-xml-node-dom4j/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/remove-xml-node-dom4j/#comments">7 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/dom4j/" rel="tag">dom4j</a>, <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/xml/" rel="tag">xml</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/remove-xml-node-dom4j/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>jdom dom4j 操作XML</title>
		<link>http://www.jiucool.com/jdom-dom4j-xml-operation/</link>
		<comments>http://www.jiucool.com/jdom-dom4j-xml-operation/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 18:52:38 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[xml]]></category>
		<category><![CDATA[应用相关]]></category>
		<category><![CDATA[dom4j]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdom]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/jdom-dom4j-xml-operation/</guid>
		<description><![CDATA[昨天晚上研究比较了一下Jdom dom4j操作XML相关内容,jdom 与 dom4j 整个流程下来，个人感觉还是比较喜欢dom4j。

jdom很简单，但是他的操作方式不是很喜欢，jdom先把所有节点创建出来，在最后再将其关系组织起来，这样感觉如果节点过多的话会导致混乱；而dom4j的操作方式是从根节点开始，自上而下节点的创建与关系的组织井井有条！

在性能上来看，如果XML文件过大的话jdom会导致内存溢出，并且效率也不高；dom4j效率与性能上都很高，连Sun的JAXM也在用DOM4J。目前许多开源项目中大量采用DOM4J，例如大名鼎鼎的Hibernate也用DOM4J来读取XML配置文件。 

<span class="readmore"><a href="http://www.jiucool.com/jdom-dom4j-xml-operation/" title="jdom dom4j 操作XML">Read More: 339 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>昨天晚上研究比较了一下Jdom dom4j操作XML相关内容,<a href="http://www.jiucool.com/tag/jdom/" class="st_tag internal_tag" rel="tag" title="Posts tagged with jdom">jdom</a> 与 <a href="http://www.jiucool.com/tag/dom4j/" class="st_tag internal_tag" rel="tag" title="Posts tagged with dom4j">dom4j</a> 整个流程下来，个人感觉还是比较喜欢dom4j。</p>
<p>jdom很简单，但是他的操作方式不是很喜欢，jdom先把所有节点创建出来，在最后再将其关系组织起来，这样感觉如果节点过多的话会导致混乱；而dom4j的操作方式是从根节点开始，自上而下节点的创建与关系的组织井井有条！</p>
<p>在性能上来看，如果XML文件过大的话jdom会导致内存溢出，并且效率也不高；dom4j效率与性能上都很高，连Sun的JAXM也在用DOM4J。目前许多开源项目中大量采用DOM4J，例如大名鼎鼎的Hibernate也用DOM4J来读取XML配置文件。 </p>
<p>这几天把手头工作做完后，再写下网站RSS、谷歌sitemap、百度sitemap生成程序！</p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/jdom-dom4j-xml-operation/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/jdom-dom4j-xml-operation/#comments">17 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/dom4j/" rel="tag">dom4j</a>, <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/jdom/" rel="tag">jdom</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/jdom-dom4j-xml-operation/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Java数据库连接池lookup用法</title>
		<link>http://www.jiucool.com/java-lookup/</link>
		<comments>http://www.jiucool.com/java-lookup/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 00:41:00 +0000</pubDate>
		<dc:creator>久酷</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[应用相关]]></category>
		<category><![CDATA[lookup]]></category>

		<guid isPermaLink="false">http://www.jiucool.com/java-lookup/</guid>
		<description><![CDATA[大项目用框架相对方便些，小一点项目还是不要用框架了太过复杂！

非框架时引用数据源我们一般这样：

Context ctx = new InitialContext(); 

DataSource ds = (DataSource)ctx.lookup(“java:comp/env/jdbc/MysqlDb”);

但看到有的地方是直接这样写的：

DataSource ds = (DataSource)ctx.lookup(“jdbc/MysqlDb”);

<span class="readmore"><a href="http://www.jiucool.com/java-lookup/" title="Java数据库连接池lookup用法">Read More: 787 Words Totally</a></span>]]></description>
			<content:encoded><![CDATA[<p>大项目用框架相对方便些，小一点项目还是不要用框架了太过复杂！</p>
<p>非框架时引用数据源我们一般这样：</p>
<p><code>Context ctx = new InitialContext(); </code></p>
<p><code>DataSource ds = (DataSource)ctx.<a href="http://www.jiucool.com/tag/lookup/" class="st_tag internal_tag" rel="tag" title="Posts tagged with lookup">lookup</a>(“<a href="http://www.jiucool.com/tag/java/" class="st_tag internal_tag" rel="tag" title="Posts tagged with java">java</a>:comp/env/jdbc/MysqlDb”);</code></p>
<p>但看到有的地方是直接这样写的：</p>
<p><code>DataSource ds = (DataSource)ctx.lookup(“jdbc/MysqlDb”);</code></p>
<p>到底有啥区别？</p>
<p>java:comp/env 是环境命名上下文（environment naming context（ENC）），是在EJB规范1.1以后引入的，引入这个是为了解决原来JNDI查找所引起的冲突问题，也是为了提高EJB或者J2EE应用的移植性。</p>
<p>ENC是一个引用，引用是用于定位企业应用程序的外部资源的逻辑名。引用是在应用程序部署描述符文件中定义的。在部署时，引用被绑定到目标可操作环境中资源的物理位置（JNDI名）。使用ENC是把对其它资源的JNDI查找的硬编码解脱出来，通过配置这个引用可以在不修改代码的情况下，将引用指向不同的EJB(JNDI)。 在J2EE中的引用常用的有：</p>
<p>&#8212;&#8212;&#8212;JDBC 数据源引用在java:comp/env/jdbc 子上下文中声明<br />
&#8212;&#8212;&#8212;JMS 连接工厂在java:comp/env/jms 子上下文中声明<br />
&#8212;&#8212;&#8212;JavaMail 连接工厂在java:comp/env/mail 子上下文中声明<br />
&#8212;&#8212;&#8212;URL 连接工厂在 java:comp/env/url子上下文中声明</p>
<p>所以我们还是应该这样写更加规范： <code>Context ctx = new InitialContext(); </code></p>
<p><code>DataSource ds = (DataSource)ctx.lookup(“java:comp/env/jdbc/MysqlDb”);</code></p>
<p>No related posts.</p><br/>
<a href="http://www.jiucool.com/godaddy-domain" target="_blank"><img src="http://pic.jiucool.com/2010/godaddy_score_savings_468x60.jpg" /></a>
<hr />
<p><small>© 久酷 for <a href="http://www.jiucool.com">久酷</a>, 2010. |
<a href="http://www.jiucool.com/java-lookup/" target="_blank">Permalink</a> |
<a href="http://www.jiucool.com/java-lookup/#comments">3 comments</a> |
Twitter:
<a href="http://twitter.com/jiucool" target="_blank">@jiucool</a>
<br/>
Post tags: <a href="http://www.jiucool.com/tag/java/" rel="tag">java</a>, <a href="http://www.jiucool.com/tag/lookup/" rel="tag">lookup</a><br/>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.jiucool.com/java-lookup/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

