<?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://roamlog.info/category/java/feed" rel="self" type="application/rss+xml" />
	<link>http://roamlog.info</link>
	<description>WordPress, Design, Web2.0, Software, IT, News</description>
	<lastBuildDate>Tue, 30 Mar 2010 00:39:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Google Reader OSX 皮肤 1.5</title>
		<link>http://roamlog.info/archives/osx-style-google-reader-15.html</link>
		<comments>http://roamlog.info/archives/osx-style-google-reader-15.html#comments</comments>
		<pubDate>Mon, 13 Oct 2008 22:00:16 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[google reader]]></category>
		<category><![CDATA[greasemonkey]]></category>

		<guid isPermaLink="false">http://roamlog.cn/?p=526</guid>
		<description><![CDATA[
Google Reader OSX 皮肤， 如图，之前有介绍过（1，2），我一直在用的一款 Google reader 的皮肤，很喜欢。
作者已不太想更新此皮肤了，但 Google reader 还在不断的更新，这就导致了新的 bug 的出现，其它还好，最不能容忍的是点击 Feed Settings 时列表不能正常显示，如下图：


所以，我就把该 Greasemonkey 脚本稍微修改了一下，解决了这个让人蛮不爽的 bug，显示效果如下图（注：Greasemonkey 是 Firefox 下的一款扩展。）：

如果你也在使用这个皮肤，也碰到这个 bug 的话，不妨试试这个修改版，下面是下载地址。
下载: os_x_style_google_reader.user.js.zip (16.3 kb)版本: 1.6 （2008/10/28 更新到 1.6）注意: 先安装 Greasemonkey，然后把此 js 文件拖到 Firefox 窗口进行安装。

另外，此脚本版权归原作者 Jon Hicks 所有，Enjoy!
]]></description>
			<content:encoded><![CDATA[<p><img src='http://roamlog.cn/wp-content/uploads/2007/10/google-reader-osx-theme.png' alt='greader osx 1.4' /></p>
<p>Google Reader OSX 皮肤， 如图，之前有介绍过（<a href="http://roamlog.cn/archives/greader-13-straight-outta-beta-release.html">1</a>，<a href="http://roamlog.cn/archives/greader-osx-14.html">2</a>），我一直在用的一款 <a href="https://www.google.com/reader">Google reader</a> 的皮肤，很喜欢。</p>
<p>作者已不太想更新此皮肤了，但 Google reader 还在不断的更新，这就导致了新的 bug 的出现，其它还好，最不能容忍的是点击 Feed Settings 时列表不能正常显示，如下图：<br />
<span id="more-526"></span><br />
<img src="http://roamlog.cn/wp-content/uploads/2008/10/osx_google_reader_bug.png" alt="osx_google_reader_bug" /></p>
<p>所以，我就把该 Greasemonkey 脚本稍微修改了一下，解决了这个让人蛮不爽的 bug，显示效果如下图（注：<a href="http://addons.mozine.cn/firefox/16/">Greasemonkey</a> 是 Firefox 下的一款扩展。）：</p>
<p><img src="http://roamlog.cn/wp-content/uploads/2008/10/osx_google_reader_new.png" alt="osx_google_reader_new" /></p>
<p>如果你也在使用这个皮肤，也碰到这个 bug 的话，不妨试试这个修改版，下面是下载地址。</p>
<p class="dl">下载: <a href="http://www.box.net/shared/u7m1k2ef1n" target="_blank">os_x_style_google_reader.user.js.zip</a> (16.3 kb)<br />版本: 1.6 （2008/10/28 更新到 1.6）<br />注意: 先安装 Greasemonkey，然后把此 js 文件拖到 Firefox 窗口进行安装。
</p>
<p>另外，此脚本版权归原作者 Jon Hicks 所有，Enjoy!</p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=526&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/osx-style-google-reader-15.html/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>eclipse小技巧之Quick Access(快速访问)</title>
		<link>http://roamlog.info/archives/quick-access-of-eclipse-tips.html</link>
		<comments>http://roamlog.info/archives/quick-access-of-eclipse-tips.html#comments</comments>
		<pubDate>Sat, 15 Sep 2007 15:09:28 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[eclipse tips]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/09/15/quick-access-of-eclipse-tips/</guid>
		<description><![CDATA[eclipse是我的主力开发工具,熟练掌握一些小技巧和快捷键可以起到事半功倍的作用,其中有一个tpis很吸引我,那就是Ctrl+3 Quick Access
我想很多经常用linux的人都习惯使用命令行来操作,我也不例外,而eclipse中的这个tips就给我这种感觉


如图,启动eclipse后，可以按ctrl+3这个快捷键启动这个画面，然后可以进行一些类型命令行的操作，比如输入new class，可以看到下图一,然后按回车，就可以看到我们熟悉的新建一个class的画面了


这是一个非常有意思的功能，让我找回了命令行操作的感觉，eclipse的tips还有很多，在以后我会慢慢写一些这方面的文章，不妨写成系列好了 -_-
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.eclipse.org">eclipse</a>是我的主力开发工具,熟练掌握一些小技巧和快捷键可以起到事半功倍的作用,其中有一个tpis很吸引我,那就是Ctrl+3 Quick Access</p>
<p>我想很多经常用linux的人都习惯使用命令行来操作,我也不例外,而eclipse中的这个tips就给我这种感觉<br />
<img src='http://roamlog.cn/wp-content/uploads/2007/09/quickaccess.png' alt='quickaccess.png' /><br />
<span id="more-105"></span><br />
如图,启动eclipse后，可以按ctrl+3这个快捷键启动这个画面，然后可以进行一些类型命令行的操作，比如输入new class，可以看到下图一,然后按回车，就可以看到我们熟悉的新建一个class的画面了<br />
<img src='http://roamlog.cn/wp-content/uploads/2007/09/newclass.png' alt='newclass.png' /><br />
<img src='http://roamlog.cn/wp-content/uploads/2007/09/class.png' alt='class.png' /></p>
<p>这是一个非常有意思的功能，让我找回了命令行操作的感觉，eclipse的tips还有很多，在以后我会慢慢写一些这方面的文章，不妨写成系列好了 -_-</p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=105&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/quick-access-of-eclipse-tips.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>高效程序开发人员应该有的7个习惯</title>
		<link>http://roamlog.info/archives/seven-habits-of-effective-developers.html</link>
		<comments>http://roamlog.info/archives/seven-habits-of-effective-developers.html#comments</comments>
		<pubDate>Sat, 08 Sep 2007 01:58:39 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[programmer]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/09/08/seven-habits-of-effective-developers/</guid>
		<description><![CDATA[Sun Microsystems亚太区的工程师Lee Chuk Munn写了一篇不错的小文，介绍一个高效程序开发人员的应该有的 7个习惯

1. 明白问题
2. 使用合适的工具
3. 保持简单,简易
4. 保持代码整洁
5. 学习调试
6. 借鉴他人
7. 持续学习

Keep it clean, and keep it simple&#8211;that is the maxim software developers should adhere to.


Understand the problem
For instance, Lee said, there are different algorithms engineers can use to write a sorting program.
To select the right one to use, developers need to first understand the [...]]]></description>
			<content:encoded><![CDATA[<p>Sun Microsystems亚太区的工程师Lee Chuk Munn写了一篇不错的小文，介绍一个高效程序开发人员的应该有的 <a href="http://nextlib.lifegoo.com/user/jack/article/1965">7个习惯</a></p>
<p class=shell>
1. 明白问题<br />
2. 使用合适的工具<br />
3. 保持简单,简易<br />
4. 保持代码整洁<br />
5. 学习调试<br />
6. 借鉴他人<br />
7. 持续学习
</p>
<p><b>Keep it clean, and keep it simple</b>&#8211;that is the maxim software developers should adhere to.
</p>
<ul>
<li>Understand the problem</li>
<p>For instance, Lee said, there are different algorithms engineers can use to write a sorting program.</p>
<p>To select the right one to use, developers need to first understand the size of the data–that the sorting program will be administered on–in order to decide which is the right algorithm to use. &#8220;Choosing the wrong one would put your application in jeopardy in future,&#8221; he said.</p>
<li>Use appropriate tools</li>
<p>Quoting American psychologist Abraham Maslow, Lee read: &#8220;If the only tool you have is a hammer, you will see every problem as a nail.&#8221;</p>
</p>
<p>This Maslow concept has become so popular among software developers that it has been dubbed the &#8220;Golden Hammer&#8221; rule, which cautions engineers with limited knowledge or training of solutions that they run the risk of using only tools they are familiar with, but that may not be the most appropriate, when they develop a new program.</p>
</ul>
<p><span id="more-52"></span></p>
<ul>
<li>Strive for simplicity</li>
</ul>
<p>Programmers should develop applications that are:</p>
<ol>
<li>Easy to understand;</li>
<li>Easy to explain; </li>
<li>Easy to maintain; </li>
<li>and Easy to document.</li>
</ol>
<ul>
<li>Keep your code clear</li>
<p>Lee said: &#8220;Put yourself as an author, how would you write something that others can easily understand and follow your thoughts? That’s how a programmer should code as well.&#8221;</p>
<li>Learn to debug</li>
<p>&#8220;Sometimes, there are bugs in your codes, or in other [software] libraries that you may have bought or downloaded that you cannot control,&#8221; Lee said, underscoring the need for developers to &#8220;test early, test often&#8221;.</p>
<li>Leverage what is available</li>
<p>Developers should also look for solutions or algorithms that are already publicly available, such as those highlighted in developer forums and mailing lists.</p>
<li>Continue to learn</li>
<p>Can developers then balance the commercial need to push out applications as quickly as possible, with the need to write codes that are clean?</p>
<p>Lee believes they can. &#8220;A lot of people say if they don’t have qu</p>
<ul>
<img src="http://roamlog.info/?ak_action=api_record_view&id=52&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/seven-habits-of-effective-developers.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>关于finally中赋值</title>
		<link>http://roamlog.info/archives/the-finally-of-java.html</link>
		<comments>http://roamlog.info/archives/the-finally-of-java.html#comments</comments>
		<pubDate>Sun, 02 Sep 2007 02:31:29 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/09/02/the-finally-of-java/</guid>
		<description><![CDATA[今天看到一个有意思的程序,写下来

public class FinallyTest &#123;
	private static int test&#40;&#41; &#123;
		int i=1;
		try &#123;
			i=2;
			return i;
		&#125; catch &#40;Exception e&#41; &#123;
			i = 3;
			return i;
		&#125; finally &#123;
			i = 4;
		&#125;
	&#125;
	public static void main&#40;String&#91;&#93; args&#41;&#123;
		FinallyTest finallyTest = new FinallyTest &#40;&#41;;
		System.out.println&#40;&#34;i=&#34; + finallyTest.test&#40;&#41;&#41;;
	&#125;
&#125;

运行结果是

i=2

为什么呢,不是明明在finally中赋值了i=4吗?
答案是:


i是值变量，在try里面写了return i; 这时虚拟机栈已经把 i 这时的值copy到栈顶，然后才再去处理
finnaly，之后对 i 进行任何改变不会影响这时候栈顶的这个返回值，只会影响 i 的值。所以尽管此时i
的值变了，但那是 i 的事情，不是Return的事情
如果在finnaly里面也加了return的话，这时候虚拟机栈又会把 i的值copy到return的栈顶（这时候是4）
所以在finnaly里面也加了return的话会返回4
这个题目正说明了java是按值返回的，如果把i设成Integer型，具有更好的说明性，i只是一个对象的引
用，在finnally中改变i只是将i指向另一个Integer对象,但是返回值在之前已经确定了
try 中return执行后，先退出try block，再退出 method body。
因为return已经执行，return的值是已经确定的，在接下来退出try block的时候执行了finally
的代码，此时finally对i值的修改已经不能影响return了，接下来程序退出method body,返回2

]]></description>
			<content:encoded><![CDATA[<p>今天看到一个有意思的程序,写下来</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;">class</span> FinallyTest <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">int</span> test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			i<span style="color: #339933;">=</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> i<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>
			i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> i<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">finally</span> <span style="color: #009900;">&#123;</span>
			i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</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> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		FinallyTest finallyTest <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FinallyTest <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;i=&quot;</span> <span style="color: #339933;">+</span> finallyTest.<span style="color: #006633;">test</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>运行结果是</p>
<p class=shell>
i=2
</p>
<p>为什么呢,不是明明在finally中赋值了i=4吗?<br />
答案是:<br />
<span id="more-45"></span></p>
<blockquote><p>
i是值变量，在try里面写了return i; 这时虚拟机栈已经把 i 这时的值copy到栈顶，然后才再去处理</p>
<p>finnaly，之后对 i 进行任何改变不会影响这时候栈顶的这个返回值，只会影响 i 的值。所以尽管此时i</p>
<p>的值变了，但那是 i 的事情，不是Return的事情</p>
<p>如果在finnaly里面也加了return的话，这时候虚拟机栈又会把 i的值copy到return的栈顶（这时候是4）<br />
所以在finnaly里面也加了return的话会返回4</p>
<p>这个题目正说明了java是按值返回的，如果把i设成Integer型，具有更好的说明性，i只是一个对象的引</p>
<p>用，在finnally中改变i只是将i指向另一个Integer对象,但是返回值在之前已经确定了</p>
<p>try 中return执行后，先退出try block，再退出 method body。<br />
因为return已经执行，return的值是已经确定的，在接下来退出try block的时候执行了finally<br />
的代码，此时finally对i值的修改已经不能影响return了，接下来程序退出method body,返回2
</p></blockquote>
<img src="http://roamlog.info/?ak_action=api_record_view&id=45&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/the-finally-of-java.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>webwork学习笔记(二)之简单登录实现</title>
		<link>http://roamlog.info/archives/webwork-studies-of-login.html</link>
		<comments>http://roamlog.info/archives/webwork-studies-of-login.html#comments</comments>
		<pubDate>Wed, 06 Jun 2007 07:13:40 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[webwork]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/06/06/webwork-studies-of-login/</guid>
		<description><![CDATA[配置web.xml

&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;
&#60;!DOCTYPE web-app PUBLIC &#34;-//Sun Microsystems, Inc.
//DTD Web Application 2.3//EN&#34; 
&#34;http://java.sun.com/dtd/web-app_2_3.dtd&#34;&#62;
&#60;web-app&#62;
  &#60;servlet&#62;
  	&#60;servlet-name&#62;webwork&#60;/servlet-name&#62;
  	&#60;servlet-class&#62;
com.opensymphony.webwork.dispatcher.ServletDispatcher
&#60;/servlet-class&#62;
  &#60;/servlet&#62;
  &#60;servlet-mapping&#62;
  	&#60;servlet-name&#62;webwork&#60;/servlet-name&#62;
  	&#60;url-pattern&#62;*.action&#60;/url-pattern&#62;
  &#60;/servlet-mapping&#62;
  &#60;taglib&#62;
  	&#60;taglib-uri&#62;webwork&#60;/taglib-uri&#62;
  	&#60;taglib-location&#62;/WEB-INF/lib/webwork-2.1.7.jar&#60;/taglib-location&#62;
  &#60;/taglib&#62;
  &#60;resource-ref&#62;
	&#60;res-ref-name&#62;jdb/sqlserver&#60;/res-ref-name&#62;
	&#60;res-type&#62;javax.sql.DataSource&#60;/res-type&#62;
	&#60;res-auth&#62;Container&#60;/res-auth&#62;
&#60;/resource-ref&#62;
&#60;/web-app&#62;


配置webwork.properties略，参考 此篇
jsp文件之 index.jsp 实现登录界面

&#60;%@ page contentType=&#34;text/html; charset=gbk&#34;%&#62;
&#60;%@ taglib prefix=&#34;ww&#34; uri=&#34;webwork&#34;%&#62;
&#60;html&#62;
	&#60;head&#62;
		&#60;title&#62;login&#60;/title&#62;
	&#60;/head&#62;
	&#60;body&#62;
		&#60;form action=&#34;login.action&#34; method=&#34;post&#34;&#62;
			&#60;input type=&#34;textfield&#34; name=&#34;userName&#34; /&#62;&#60;br /&#62;
			&#60;input type=&#34;password&#34; name=&#34;password&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>配置web.xml</p>

<div class="wp_syntax"><div 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: #00bbdd;">&lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.</span>
<span style="color: #00bbdd;">//DTD Web Application 2.3//EN&quot; </span>
<span style="color: #00bbdd;">&quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>webwork<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
com.opensymphony.webwork.dispatcher.ServletDispatcher
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>webwork<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*.action<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taglib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taglib-uri<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>webwork<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/taglib-uri<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taglib-location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/WEB-INF/lib/webwork-2.1.7.jar<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/taglib-location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/taglib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdb/sqlserver<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.sql.DataSource<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Container<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><span id="more-40"></span><br />
配置webwork.properties略，参考 <a href="http://roamlog.cn/?p=58">此篇</a><br />
jsp文件之 index.jsp 实现登录界面</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ page contentType=&quot;text/html; charset=gbk&quot;%&gt;
&lt;%@ taglib prefix=&quot;ww&quot; uri=&quot;webwork&quot;%&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;login&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;form action=&quot;login.action&quot; method=&quot;post&quot;&gt;
			&lt;input type=&quot;textfield&quot; name=&quot;userName&quot; /&gt;&lt;br /&gt;
			&lt;input type=&quot;password&quot; name=&quot;password&quot; /&gt;&lt;br/&gt;
			&lt;input type=&quot;submit&quot; value=&quot;submit&quot; /&gt;&lt;br/&gt;
			&lt;ww:property value=&quot;message&quot; /&gt;
		&lt;/form&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>登录成功页面 loginsuccess.jsp</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ page contentType=&quot;text/html; charset=gbk&quot;%&gt;
&lt;%@ taglib prefix=&quot;ww&quot; uri=&quot;webwork&quot;%&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;success&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;ww:property value=&quot;#session['userName']&quot; /&gt;
		&lt;ww:property value=&quot;message&quot; /&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>action，只列出execute方法，其它方法略</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">　　　<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> userName<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> password<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> message<span style="color: #339933;">;</span>
　　　.......
　　　<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">boolean</span> isSucced <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>userName <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: #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;start to logining&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			userName <span style="color: #339933;">=</span> userName.<span style="color: #006633;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			password <span style="color: #339933;">=</span> password.<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: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>userName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> password.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				isSucced <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
				message <span style="color: #339933;">=</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;">else</span> <span style="color: #009900;">&#123;</span>
				isSucced <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>isSucced<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>userName.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;zbsdg&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> password.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;123&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				isSucced <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
                     ActionContext.<span style="color: #006633;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getSession</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
                  .<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;userName&quot;</span>, userName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					message <span style="color: #339933;">=</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;">else</span> <span style="color: #009900;">&#123;</span>
					isSucced <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
					message <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;用户名或密码错误&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			isSucced <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			message <span style="color: #339933;">=</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;">if</span> <span style="color: #009900;">&#40;</span>isSucced<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> SUCCESS<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">return</span> ERROR<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>配置xwork.xml</p>

<div class="wp_syntax"><div 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: #00bbdd;">&lt;!DOCTYPE xwork PUBLIC &quot;-//OpenSymphony Group//XWork 1.0//EN&quot;</span>
<span style="color: #00bbdd;">&quot;http://www.opensymphony.com/xwork/xwork-1.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xwork<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;webwork-default.xml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;package</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;default&quot;</span> <span style="color: #000066;">extends</span>=<span style="color: #ff0000;">&quot;webwork-default&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default-interceptor-ref</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;completeStack&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;login&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.webwork.action.Login&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;error&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>index.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/result<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;success&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>loginsuccess.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/result<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/package<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xwork<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<img src="http://roamlog.info/?ak_action=api_record_view&id=40&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/webwork-studies-of-login.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>webwork学习笔记(一)</title>
		<link>http://roamlog.info/archives/webwork-studies-notos-of-one.html</link>
		<comments>http://roamlog.info/archives/webwork-studies-notos-of-one.html#comments</comments>
		<pubDate>Tue, 05 Jun 2007 03:31:48 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[webwork]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/06/05/webwork-studies-notos-of-one/</guid>
		<description><![CDATA[webwork, 一  mvc  框架
所需基本类库,从官方 下载, 我采用 webwork2.1.7, 主要是为了配合 webwork in action 这本书
学习要点:
1. 所需类库:

commons-logging.jar ognl.jar oscore.jar velocity-dep.jar webwork-2.1.7.jar xwork.jar

2. action可选择implements Action,也可以选择extends ActionSupport,推荐采用后者,都要实现      execute这个方法,如:

public String execute&#40;&#41; &#123;
      if&#40;name == null &#124;&#124; &#34;&#34;.equals&#40;name&#41; &#124;&#124; &#34;World&#34;.equals&#40;name&#41;&#41;&#123;
	   addFieldError&#40;&#34;name&#34;,
&#34;Blank names or names of 'World' are not allowed!&#34;&#41;;
			return [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.opensymphony.com/webwork/">webwork</a>, 一  <a href="http://en.wikipedia.org/wiki/Model-view-controller">mvc</a>  框架<br />
所需基本类库,从官方 <a href="http://www.opensymphony.com/webwork/download.action">下载</a>, 我采用 webwork2.1.7, 主要是为了配合 <a href="http://www.manning.com/lightbody">webwork in action</a> 这本书<br />
学习要点:<br />
1. 所需类库:</p>
<p class=shell>
commons-logging.jar ognl.jar oscore.jar velocity-dep.jar webwork-2.1.7.jar xwork.jar
</p>
<p>2. action可选择implements Action,也可以选择extends ActionSupport,推荐采用后者,都要实现      execute这个方法,如:</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: #003399;">String</span> execute<span style="color: #009900;">&#40;</span><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>name <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">||</span> <span style="color: #0000ff;">&quot;&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #0000ff;">&quot;World&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	   addFieldError<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span>,
<span style="color: #0000ff;">&quot;Blank names or names of 'World' are not allowed!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">return</span> INPUT<span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		message <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;hello, &quot;</span> <span style="color: #339933;">+</span> name <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;!&quot;</span><span style="color: #339933;">;</span>
		message <span style="color: #339933;">+=</span> <span style="color: #0000ff;">&quot;The time is:&quot;</span><span style="color: #339933;">;</span>
		message <span style="color: #339933;">+=</span> mystring<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">return</span> SUCCESS<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-38"></span><br />
3.主要有三个配置文件web.xml xwork.xml webwork.properties</p>
<p>4.webwork.properties配置方法(初步)</p>
<p class=shell>
webwork.tag.altSyntax = true
</p>
<p>5.web.xml的配置</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>webwork<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
com.opensymphony.webwork.dispatcher.ServletDispatcher
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>webwork<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*.action<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taglib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taglib-uri<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>webwork<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/taglib-uri<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taglib-location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                   /WEB-INF/lib/webwork-2.1.7.jar
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/taglib-location<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/taglib<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>注意DOCTYPE</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.</span>
<span style="color: #00bbdd;">//DTD Web Application 2.3//EN&quot;</span>
<span style="color: #00bbdd;">&quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot;&gt;</span></pre></div></div>

<p>6. xwork.xml配置</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE xwork PUBLIC &quot;-//OpenSymphony Group//XWork 1.0//EN&quot;</span>
<span style="color: #00bbdd;">&quot;http://www.opensymphony.com/xwork/xwork-1.0.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xwork<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;webwork-default.xml&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;package</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;default&quot;</span> <span style="color: #000066;">extends</span>=<span style="color: #ff0000;">&quot;webwork-default&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;default-interceptor-ref</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;completeStack&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hello&quot;</span></span>
<span style="color: #009900;">			<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;com.zbsdg.webwork.example.HelloWorld&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;success&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>index.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/result<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;result</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;input&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>name.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/result<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/action<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/package<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xwork<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>对webwork感兴趣的推荐看这两篇文章<br />
<a href="http://www.matrix.org.cn/resource/article/2006-07-19/WebWork_44539.html">WebWork入门教程&#8211;创建你第一个WebWork action</a><br />
<a href="http://www.blogjava.net/moxie/archive/2006/10/20/76375.html">WebWork深入浅出</a></p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=38&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/webwork-studies-notos-of-one.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>将下拉列表框中的数据添加到文本框中</title>
		<link>http://roamlog.info/archives/add-list-box-data-to-text.html</link>
		<comments>http://roamlog.info/archives/add-list-box-data-to-text.html#comments</comments>
		<pubDate>Wed, 23 May 2007 00:15:36 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/05/23/add-list-box-data-to-text/</guid>
		<description><![CDATA[下拉列表框中的数据是从字典表中取得的, 实现方法 在 这里
这次是采用js来实现的,代码如下

      function atSub&#40;&#41;
&#123;
    var index_s =document.add.test.selectedIndex;
    var content = document.add.test.options&#91;index_s&#93;.value;
     document.add.member.value+= content + &#34;   &#34;;
&#125;

页面代码如下

&#60;tr&#62;
&#60;td class='small' width=&#34;14%&#34; bgcolor=&#34;#D8EBF5&#34;&#62;
   &#60;div align=&#34;center&#34;&#62;成员：&#60;/div&#62;
&#60;/td&#62;
&#60;td colspan=&#34;3&#34; bgcolor=&#34;#D8EBF5&#34; class='small'&#62;
&#60;input type=&#34;text&#34; name=&#34;member&#34; id=&#34;member&#34; size=&#34;76.5&#34;&#62;
    &#60;select style=&#34;width: 160; [...]]]></description>
			<content:encoded><![CDATA[<p>下拉列表框中的数据是从字典表中取得的, 实现方法 在 <a href="http://roamlog.cn/?p=47">这里</a><br />
这次是采用js来实现的,代码如下</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">      <span style="color: #003366; font-weight: bold;">function</span> atSub<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> index_s <span style="color: #339933;">=</span>document.<span style="color: #660066;">add</span>.<span style="color: #660066;">test</span>.<span style="color: #660066;">selectedIndex</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> content <span style="color: #339933;">=</span> document.<span style="color: #660066;">add</span>.<span style="color: #660066;">test</span>.<span style="color: #660066;">options</span><span style="color: #009900;">&#91;</span>index_s<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
     document.<span style="color: #660066;">add</span>.<span style="color: #660066;">member</span>.<span style="color: #660066;">value</span><span style="color: #339933;">+=</span> content <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;   &quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>页面代码如下</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;tr&gt;
&lt;td class='small' width=&quot;14%&quot; bgcolor=&quot;#D8EBF5&quot;&gt;
   &lt;div align=&quot;center&quot;&gt;成员：&lt;/div&gt;
&lt;/td&gt;
&lt;td colspan=&quot;3&quot; bgcolor=&quot;#D8EBF5&quot; class='small'&gt;
&lt;input type=&quot;text&quot; name=&quot;member&quot; id=&quot;member&quot; size=&quot;76.5&quot;&gt;
    &lt;select style=&quot;width: 160; height: 23&quot; 
        onChange=&quot;javascript:atSub();&quot; name=&quot;test&quot;&gt;
	&lt;option value=&quot;&quot;&gt;选择成员	&lt;/option&gt;
		&lt;%
                     Vector mm = UserInfo.getAllUsers();
                         for(int i=0;i&lt;mm.size();i++){
                             UserInfo mmall = (UserInfo)mm.get(i);
		%&gt;
		&lt;option value=&quot;&lt;%=mmall.getUserName()%&gt;&quot;&gt;
	                &lt;%=mmall.getUserName()%&gt;
		&lt;/option&gt;
               &lt;%}%&gt;
    &lt;/select&gt;
&lt;/td&gt;
&lt;/tr&gt;</pre></div></div>

<img src="http://roamlog.info/?ak_action=api_record_view&id=35&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/add-list-box-data-to-text.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>字典表与列表框的讨论</title>
		<link>http://roamlog.info/archives/list-box-and-dictionary-table.html</link>
		<comments>http://roamlog.info/archives/list-box-and-dictionary-table.html#comments</comments>
		<pubDate>Thu, 17 May 2007 05:19:01 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/05/17/list-box-and-dictionary-table/</guid>
		<description><![CDATA[在最近的一个小系统里要加入一个功能,一个列表框,数据从数据库的字典表中取得,研究了一下,实现了,记录下
只显示一个字段的内容,我采用Vector来实现,代码如下

package com.xx.work.data;
&#160;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
&#160;
import com.aheadsoft.work.dao.DBConnect;
&#160;
public class Add &#123;
	private int ID;
	private String workType;
	public int getID&#40;&#41; &#123;
		return ID;
	&#125;
	public void setID&#40;int id&#41; &#123;
		ID = id;
	&#125;
	public String getWorkType&#40;&#41; &#123;
		return workType;
	&#125;
	public void setWorkType&#40;String workType&#41; &#123;
		this.workType = workType;
	&#125;
	public Add&#40;&#41;&#123;
		ID = 0;
		workType = &#34;&#34;;
	&#125;
	public Add&#40;int ID, String workType&#41;&#123;
		this.ID = ID;
		this.workType = workType;
	&#125;
	public void setID&#40;String newID&#41; &#123;
		if &#40;newID != null&#41;
			this.ID = Integer.parseInt&#40;newID&#41;;
	&#125;
	public [...]]]></description>
			<content:encoded><![CDATA[<p>在最近的一个小系统里要加入一个功能,一个列表框,数据从数据库的字典表中取得,研究了一下,实现了,记录下<br />
只显示一个字段的内容,我采用Vector来实现,代码如下</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.xx.work.data</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.ResultSet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.SQLException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Vector</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.aheadsoft.work.dao.DBConnect</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> Add <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> ID<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> workType<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> ID<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setID<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		ID <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getWorkType<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> workType<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setWorkType<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> workType<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">workType</span> <span style="color: #339933;">=</span> workType<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> Add<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		ID <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		workType <span style="color: #339933;">=</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;">public</span> Add<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> ID, <span style="color: #003399;">String</span> workType<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ID</span> <span style="color: #339933;">=</span> ID<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">workType</span> <span style="color: #339933;">=</span> workType<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setID<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> newID<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>newID <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">ID</span> <span style="color: #339933;">=</span> <span style="color: #003399;">Integer</span>.<span style="color: #006633;">parseInt</span><span style="color: #009900;">&#40;</span>newID<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: #003399;">Vector</span>  excute<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;">Exception</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Vector</span> list <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Vector</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">String</span> Str <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;select * from workType&quot;</span><span style="color: #339933;">;</span>
		DBConnect dbc <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">ResultSet</span> rs <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			dbc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DBConnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
				rs <span style="color: #339933;">=</span> dbc.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span>Str<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>rs.<span style="color: #006633;">next</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>
					Add add <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Add<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					add.<span style="color: #006633;">setWorkType</span><span style="color: #009900;">&#40;</span>rs.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;workType&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					list.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span>add<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</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;">SQLException</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;">finally</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>rs <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
					rs.<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: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">SQLException</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;">finally</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>dbc <span style="color: #339933;">!=</span>  <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
				dbc.<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;">return</span> list<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> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-34"></span><br />
JSP页面实现代码如下</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ page import=&quot;com.aheadsoft.work.data.Add&quot;%&gt;
//其它略
&lt;select name=&quot;workType&quot; style=&quot;width: 160; height: 23&quot;&gt;
	&lt;option selected value=&quot;&quot;&gt;
		选择工作类型
	&lt;/option&gt;
	&lt;%
		Vector work = Add.excute();
                for(int i=0;i&lt;work.size();i++){
                    Add add = (Add)work.get(i);
	 %&gt;
&lt;option&gt;&lt;%=add.getWorkType()%&gt;&lt;/option&gt;
&lt;%}%&gt;
&lt;/select&gt;</pre></div></div>

<img src="http://roamlog.info/?ak_action=api_record_view&id=34&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/list-box-and-dictionary-table.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>tomcat5.5.23中access连接池的配置方法</title>
		<link>http://roamlog.info/archives/connect-pool-of-access.html</link>
		<comments>http://roamlog.info/archives/connect-pool-of-access.html#comments</comments>
		<pubDate>Thu, 17 May 2007 05:10:51 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/05/17/connect-pool-of-access/</guid>
		<description><![CDATA[记录一下, 这里只给出server.xml的配置方法,其它的配置及测试代码在  这里

&#60;logger className=&#34;org.apache.catalina.logger.FileLogger&#34;
            directory=&#34;logs&#34;  prefix=&#34;localhost_log.&#34; suffix=&#34;.txt&#34;
            timestamp=&#34;true&#34;/&#62;
         &#60;context docBase=&#34;cmmi&#34; path=&#34;/cmmi&#34; 
            [...]]]></description>
			<content:encoded><![CDATA[<p>记录一下, 这里只给出server.xml的配置方法,其它的配置及测试代码在  <a href="http://roamlog.cn/?p=39">这里</a></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;logger</span> <span style="color: #000066;">className</span>=<span style="color: #ff0000;">&quot;org.apache.catalina.logger.FileLogger&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">directory</span>=<span style="color: #ff0000;">&quot;logs&quot;</span>  <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;localhost_log.&quot;</span> <span style="color: #000066;">suffix</span>=<span style="color: #ff0000;">&quot;.txt&quot;</span></span>
<span style="color: #009900;">            <span style="color: #000066;">timestamp</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context</span> <span style="color: #000066;">docBase</span>=<span style="color: #ff0000;">&quot;cmmi&quot;</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/cmmi&quot;</span> </span>
<span style="color: #009900;">                 <span style="color: #000066;">reloadable</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">crossContext</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;logger</span> <span style="color: #000066;">className</span>=<span style="color: #ff0000;">&quot;org.apache.catalina.logger.FileLogger&quot;</span></span>
<span style="color: #009900;">                     <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;localhost_lovehome_log.&quot;</span> </span>
<span style="color: #009900;">                     <span style="color: #000066;">suffix</span>=<span style="color: #ff0000;">&quot;.txt&quot;</span> <span style="color: #000066;">timestamp</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbc/access&quot;</span> <span style="color: #000066;">auth</span>=<span style="color: #ff0000;">&quot;Container&quot;</span> </span>
<span style="color: #009900;">              <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;javax.sql.DataSource&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">maxActive</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">maxIdle</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">maxWait</span>=<span style="color: #ff0000;">&quot;10000&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">driverClassName</span>=<span style="color: #ff0000;">&quot;sun.jdbc.odbc.JdbcOdbcDriver&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;sa&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;12345&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;jdbc:odbc:work&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">defaultAutoCommit</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">removeAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">removeAbondonedTimeout</span>=<span style="color: #ff0000;">&quot;60&quot;</span> <span style="color: #000066;">logAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<img src="http://roamlog.info/?ak_action=api_record_view&id=33&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/connect-pool-of-access.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>一个简单的jsp分页实现</title>
		<link>http://roamlog.info/archives/simpleness-pagination-of-jsp.html</link>
		<comments>http://roamlog.info/archives/simpleness-pagination-of-jsp.html#comments</comments>
		<pubDate>Thu, 29 Mar 2007 00:54:15 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[jsp]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/03/29/simpleness-pagination-of-jsp/</guid>
		<description><![CDATA[环境
xp + jdk1.5 + tomcat5.5.23 + eclipse3.2.2 + myeclipse5.1.1GA + sqlserver2000
使用连接池方式连接数据库,至于这方面的问题可参考 http://roamlog.cn/?p=39
写一个DBConnection.java封装对数据库的一些操作,实现SqlTestDS的getConnection()方法连接数据库
DBConnection.java

package database;
import java.sql.*;
public class DBConnection&#123;
	private Connection conn = null;
	private Statement stmt = null;
	ResultSet rs = null;
	public ResultSet executeQuery&#40;String sql&#41; &#123;
	try &#123;
	     conn =SqlTestDS.getConnection&#40;&#41;;
             stmt=conn.createStatement
&#40;ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY&#41;;
			rs = stmt.executeQuery&#40;sql&#41;;
		&#125; catch &#40;Exception [...]]]></description>
			<content:encoded><![CDATA[<p>环境<br />
xp + jdk1.5 + tomcat5.5.23 + eclipse3.2.2 + myeclipse5.1.1GA + sqlserver2000</p>
<p>使用连接池方式连接数据库,至于这方面的问题可参考 http://roamlog.cn/?p=39</p>
<p>写一个DBConnection.java封装对数据库的一些操作,实现SqlTestDS的getConnection()方法连接数据库</p>
<p>DBConnection.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;">database</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DBConnection<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Connection</span> conn <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Statement</span> stmt <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #003399;">ResultSet</span> rs <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">ResultSet</span> executeQuery<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sql<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
	     conn <span style="color: #339933;">=</span>SqlTestDS.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
             stmt<span style="color: #339933;">=</span>conn.<span style="color: #006633;">createStatement</span>
<span style="color: #009900;">&#40;</span><span style="color: #003399;">ResultSet</span>.<span style="color: #006633;">TYPE_SCROLL_INSENSITIVE</span>,
<span style="color: #003399;">ResultSet</span>.<span style="color: #006633;">CONCUR_READ_ONLY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			rs <span style="color: #339933;">=</span> stmt.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span>sql<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>
			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;">return</span> rs<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> executeUpdate<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sql<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			conn <span style="color: #339933;">=</span> SqlTestDS.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			stmt <span style="color: #339933;">=</span>conn.<span style="color: #006633;">createStatement</span>
<span style="color: #009900;">&#40;</span><span style="color: #003399;">ResultSet</span>.<span style="color: #006633;">TYPE_SCROLL_INSENSITIVE</span>,
<span style="color: #003399;">ResultSet</span>.<span style="color: #006633;">CONCUR_READ_ONLY</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			stmt.<span style="color: #006633;">executeUpdate</span><span style="color: #009900;">&#40;</span>sql<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>
			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: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> closeStmt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			stmt.<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;">Exception</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: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> closeConn<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			conn.<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;">Exception</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-29"></span><br />
一个jsp文件,负责分页的处理<br />
fenye.jsp</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;%@ page contentType=&quot;text/html;charset=gbk&quot;%&gt;
&lt;%@ page pageEncoding=&quot;gbk&quot;%&gt;
&lt;%
request.setCharacterEncoding(&quot;gbk&quot;);
%&gt;
&lt;%@ page import=&quot;java.sql.*&quot;%&gt;
&lt;%@ page import=&quot;database.DBConn&quot;%&gt;
&nbsp;
&lt;%
	//变量声明
	ResultSet sqlRst; //结果集对象
	String strCon; //数据库连接字符串
	String strSQL; //SQL语句
	int intPageSize; //一页显示的记录数
	int intRowCount; //记录总数
	int intPageCount; //总页数
	int intPage; //待显示页码
	String strPage;
	int i;
	//设置一页显示的记录数
	intPageSize = 4;
	//取得待显示页码
	strPage = request.getParameter(&quot;page&quot;);
	if (strPage == null) {
//表明在QueryString中没有page这一个参数，此时显示第一页数据
		intPage = 1;
	} else {//将字符串转换成整型
		intPage = Integer.parseInt(strPage);
		if (intPage &lt; 1)
			intPage = 1;
	}
	strSQL = &quot;select fkid,shjiaid from shop_shjiafk order by fkid desc&quot;;
	//执行SQL语句并获取结果集
	DBConn dd = new DBConn();
	sqlRst = dd.executeQuery(strSQL);
	//获取记录总数
	sqlRst.last();//光标在最后一行
	intRowCount = sqlRst.getRow();//获得当前行号
	//记算总页数
	intPageCount = (intRowCount + intPageSize - 1) / intPageSize;
	//调整待显示的页码
	if (intPage &gt; intPageCount)
		intPage = intPageCount;
%&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;script language=&quot;javascript&quot;&gt;
function newwin(url) {
var newwin=window.open(url,&quot;newwin&quot;,&quot;toolbar=no,location=no,directories=no,
status=no,menubar=no,scrollbars=yes,resizable=yes,width=600,height=450&quot;);
newwin.focus();
return false;
}
&lt;/script&gt;
		&lt;script language=&quot;javascript&quot;&gt;
function submit10()
{
self.location.replace(&quot;fenye.jsp&quot;)
}
&lt;/script&gt;
         &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gbk&quot;&gt;
		&lt;title&gt;会员管理&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;
		&lt;form method=&quot;post&quot; action=&quot;fenye.jsp&quot;&gt;
			第
			&lt;%=intPage%&gt;
			页 共
			&lt;%=intPageCount%&gt;
			页
&nbsp;
			&lt;%
		if (intPage &lt; intPageCount) {
		%&gt;
			&lt;a href=&quot;fenye.jsp?page=&lt;%=intPage + 1%&gt;&quot;&gt;下一页 &lt;/a&gt;
			&lt;%
			}
			%&gt;
			&lt;%
			if (intPage &gt; 1) {
			%&gt;
			&lt;a href=&quot;fenye.jsp?page=&lt;%=intPage - 1%&gt;&quot;&gt; 上一页&lt;/a&gt;
			&lt;%
			}
			%&gt;
			转到第:
			&lt;input type=&quot;text&quot; name=&quot;page&quot; size=&quot;8&quot;&gt;
			页
			&lt;span&gt;&lt;input class=buttonface type=&quot;submit&quot; value=&quot;go&quot;
					name=&quot;cndok&quot;&gt; &lt;/span&gt;
		&lt;/form&gt;
		&lt;table border=&quot;1&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;&gt;
			&lt;tr&gt;
				&lt;th&gt;
					ID
				&lt;/th&gt;
				&lt;th&gt;
					用户名
				&lt;/th&gt;
				&lt;th width=&quot;8%&quot;&gt;
					删除
				&lt;/th&gt;
			&lt;/tr&gt;
			&lt;%
					if (intPageCount &gt; 0) {
					//将记录指针定位到待显示页的第一条记录上
					sqlRst.absolute((intPage - 1) * intPageSize + 1);
					//显示数据
					i = 0;
					String user_id, user_name;
					while (i &lt; intPageSize &amp;&amp; !sqlRst.isAfterLast()) {
						user_id = sqlRst.getString(1);
						user_name = sqlRst.getString(2);
			%&gt;
			&lt;tr&gt;
				&lt;td&gt;
					&lt;%=user_id%&gt;
				&lt;/td&gt;
				&lt;td&gt;
					&lt;%=user_name%&gt;
				&lt;/td&gt;
				&lt;td width=&quot;8%&quot; align=&quot;center&quot;&gt;
					&lt;a href=&quot;delete.jsp?user_id=&lt;%=user_id%&gt;&quot;
						onClick=&quot;return newwin(this.href);&quot;&gt;删除&lt;/a&gt;
				&lt;/td&gt;
			&lt;/tr&gt;
			&lt;%
						sqlRst.next();
						i++;
					}
				}
			%&gt;
		&lt;/table&gt;
	&lt;/body&gt;
&lt;/html&gt;
&lt;%
	dd.closeStmt();
	dd.closeConn();
%&gt;</pre></div></div>

<p>完成</p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=29&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/simpleness-pagination-of-jsp.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>笔记:tomcat5.5.23的连接池配置方法</title>
		<link>http://roamlog.info/archives/nots-of-configure-tomcat55-pool.html</link>
		<comments>http://roamlog.info/archives/nots-of-configure-tomcat55-pool.html#comments</comments>
		<pubDate>Wed, 28 Mar 2007 08:56:15 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/03/28/nots-of-configure-tomcat55-pool/</guid>
		<description><![CDATA[前些天我也写过一篇类似的文章,关于连接池配置的,今天我重新写过一篇,介绍不同的配置方法
环境搭建我就不多说了,我的环境是:

xp + jdk1.5 + tomcat5.5.23 + eclipse3.2.2 + myeclipse5.1.1GA + sqlserver2000

首先写个连接数据源的java类

SqlTestDS.java


package database;
import javax.sql.DataSource;
import javax.naming.*;
import java.sql.*;
public class SqlTestDS &#123;
private static DataSource ds = null;
static &#123;
init&#40;&#41;;
&#125;
private static void init&#40;&#41; &#123;
try &#123;
// 1、创建命名服务环境
Context ctx = new InitialContext&#40;&#41;;
if &#40;ctx == null&#41;
throw new Exception&#40;&#34;No Context&#34;&#41;;
&#160;
// 2、从JNDI中查询数据源对象
ds = &#40;DataSource&#41; ctx.lookup&#40;&#34;java:comp/env/jdbc/sqlserver&#34;&#41;;
&#160;
&#125; catch &#40;Exception e&#41; &#123;
e.printStackTrace&#40;&#41;;
&#125;
&#125;
&#160;
// 将构造函数定义为private权限是为了保证全局只有一个SqlTestDS实例
// 也就是实现了单例模式
private SqlTestDS&#40;&#41; &#123;
&#160;
&#125;
&#160;
public static Connection getConnection&#40;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>前些天我也写过一篇类似的文章,关于连接池配置的,今天我重新写过一篇,介绍不同的配置方法<br />
环境搭建我就不多说了,我的环境是:</p>
<blockquote><p>
xp + jdk1.5 + tomcat5.5.23 + eclipse3.2.2 + myeclipse5.1.1GA + sqlserver2000
</p></blockquote>
<p>首先写个连接数据源的java类</p>
<blockquote><p>
SqlTestDS.java
</p></blockquote>

<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;">database</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.sql.DataSource</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.naming.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.sql.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SqlTestDS <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> DataSource ds <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">static</span> <span style="color: #009900;">&#123;</span>
init<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;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// 1、创建命名服务环境</span>
<span style="color: #003399;">Context</span> ctx <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">InitialContext</span><span style="color: #009900;">&#40;</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>ctx <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Exception</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No Context&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 2、从JNDI中查询数据源对象</span>
ds <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>DataSource<span style="color: #009900;">&#41;</span> ctx.<span style="color: #006633;">lookup</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;java:comp/env/jdbc/sqlserver&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<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>
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: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// 将构造函数定义为private权限是为了保证全局只有一个SqlTestDS实例</span>
<span style="color: #666666; font-style: italic;">// 也就是实现了单例模式</span>
<span style="color: #000000; font-weight: bold;">private</span> SqlTestDS<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Connection</span> getConnection<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;">SQLException</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>ds <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: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">SQLException</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;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// 3、从数据源中获取数据库连接</span>
<span style="color: #000000; font-weight: bold;">return</span> ds.<span style="color: #006633;">getConnection</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>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><span id="more-28"></span><br />
再写个jsp文件,简单测试用.进行相关配置,接下来我将介绍和以前那篇不同的配置方法<br />
第一种<br />
在/META-INF目录下新建一个context.xml文件,写入以下内容</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">       docBase=&quot;myweb&quot;      //工程的虚拟目录
       path=&quot;/myweb&quot;          //访问路径
       reloadable=&quot;true&quot;&gt;
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbc/mysql&quot;</span> <span style="color: #000066;">auth</span>=<span style="color: #ff0000;">&quot;Container&quot;</span> </span>
<span style="color: #009900;">              <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;javax.sql.DataSource&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">maxActive</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">maxIdle</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">maxWait</span>=<span style="color: #ff0000;">&quot;10000&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">driverClassName</span>=<span style="color: #ff0000;">&quot;com.microsoft.jdbc.sqlserver.SQLServerDriver&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;sa&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;12345&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=vnet&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">defaultAutoCommit</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">removeAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">              <span style="color: #000066;">removeAbondonedTimeout</span>=<span style="color: #ff0000;">&quot;60&quot;</span> <span style="color: #000066;">logAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>第二种<br />
在$CATALINA_HOME/conf/Catalina/localhost/  下新建一个和工程名同名的xml文件,如我的myweb.xml<br />
内容同上</p>
<p>当然还要配置一下web.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdb/mysql<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.sql.DataSource<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Container<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>然后重启tomcat,测试<br />
访问路径为 http://localhost:8080/myweb/MyJsp.jsp<br />
配置成功</p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=28&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/nots-of-configure-tomcat55-pool.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>tomcat5.5.20的连接池配置方法</title>
		<link>http://roamlog.info/archives/the-method-of-configure-tomcat55-pool.html</link>
		<comments>http://roamlog.info/archives/the-method-of-configure-tomcat55-pool.html#comments</comments>
		<pubDate>Tue, 27 Feb 2007 11:35:04 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/02/27/the-method-of-configure-tomcat55-pool/</guid>
		<description><![CDATA[配置server.xml,在< /host > 标签前加入

&#60;context
       docBase=&#34;C:/eclipse/workspace/myweb/hello&#34;
        path=&#34;/hello&#34;
         reloadable=&#34;true&#34;
&#60;resource name=&#34;jdbc/mysql&#34; auth=&#34;Container&#34; type=&#34;javax.sql.DataSource&#34;
	maxActive=&#34;100&#34; maxIdle=&#34;30&#34; maxWait=&#34;10000&#34;
	driverClassName=&#34;com.mysql.jdbc.Driver&#34;
	username=&#34;root&#34; password=&#34;123456&#34;
	url=&#34;jdbc:mysql://localhost/testmysql&#34;
	defaultAutoCommit=&#34;true&#34; removeAbondoned=&#34;true&#34;
	removeAbondonedTimeout=&#34;60&#34; logAbondoned=&#34;true&#34;/&#62;
&#60;/context&#62;

配置web.xml

	&#60;resource-ref&#62;
		&#60;res-ref-name&#62;jdb/mysql&#60;/res-ref-name&#62;
		&#60;res-type&#62;javax.sql.DataSource&#60;/res-type&#62;
		&#60;res-auth&#62;Container&#60;/res-auth&#62;
	&#60;/resource-ref&#62;

]]></description>
			<content:encoded><![CDATA[<p>配置server.xml,在< /host > 标签前加入</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context</span></span>
<span style="color: #009900;">       <span style="color: #000066;">docBase</span>=<span style="color: #ff0000;">&quot;C:/eclipse/workspace/myweb/hello&quot;</span></span>
<span style="color: #009900;">        <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;/hello&quot;</span></span>
<span style="color: #009900;">         <span style="color: #000066;">reloadable</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbc/mysql&quot;</span> <span style="color: #000066;">auth</span>=<span style="color: #ff0000;">&quot;Container&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;javax.sql.DataSource&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">maxActive</span>=<span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">maxIdle</span>=<span style="color: #ff0000;">&quot;30&quot;</span> <span style="color: #000066;">maxWait</span>=<span style="color: #ff0000;">&quot;10000&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">driverClassName</span>=<span style="color: #ff0000;">&quot;com.mysql.jdbc.Driver&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;123456&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;jdbc:mysql://localhost/testmysql&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">defaultAutoCommit</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">removeAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">	<span style="color: #000066;">removeAbondonedTimeout</span>=<span style="color: #ff0000;">&quot;60&quot;</span> <span style="color: #000066;">logAbondoned</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/context<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>配置web.xml</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>jdb/mysql<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-ref-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>javax.sql.DataSource<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Container<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/res-auth<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resource-ref<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<img src="http://roamlog.info/?ak_action=api_record_view&id=26&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/the-method-of-configure-tomcat55-pool.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>自动设置环境变量</title>
		<link>http://roamlog.info/archives/auto-configure-environment-variable.html</link>
		<comments>http://roamlog.info/archives/auto-configure-environment-variable.html#comments</comments>
		<pubDate>Mon, 12 Feb 2007 10:43:48 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/02/12/auto-configure-environment-variable/</guid>
		<description><![CDATA[在ChinaJavaWorld看到的很简单的一个脚本，用于自动设置环境变量。
把代码拷贝，另存为javaEnv.bat。安装完Java 2 SDK之后，开一个命令行窗口,输入 javaEnv java2SDKDir (java2SDKDir是你的java的安装目录，不带路径最后的)并运行。 (注：一定要在javaEnv后边加上你的sdk的目录)

@echo off
IF EXIST %1\bin\java.exe (
   rem 如输入正确的 Java2SDK 安装目录，开始设置环境变量
   @setx JAVA_HOME %1
   @setx path %path%;%JAVA_HOME%\bin
   @setx classpath %classpath%;.
   @setx classpath %classpath%;%JAVA_HOME%lib	ools.jar
   @setx classpath %classpath%;%JAVA_HOME%libdt.jar
   @setx classpath %classpath%;%JAVA_HOME%jrelib
t.jar
   @echo on
   @echo Java [...]]]></description>
			<content:encoded><![CDATA[<p>在ChinaJavaWorld看到的很简单的一个脚本，用于自动设置环境变量。<br />
把代码拷贝，另存为javaEnv.bat。安装完Java 2 SDK之后，开一个命令行窗口,输入 javaEnv java2SDKDir (java2SDKDir是你的java的安装目录，不带路径最后的)并运行。 (注：一定要在javaEnv后边加上你的sdk的目录)</p>
<pre name="code" class="java">
@echo off
IF EXIST %1\bin\java.exe (
   rem 如输入正确的 Java2SDK 安装目录，开始设置环境变量
   @setx JAVA_HOME %1
   @setx path %path%;%JAVA_HOME%\bin
   @setx classpath %classpath%;.
   @setx classpath %classpath%;%JAVA_HOME%lib	ools.jar
   @setx classpath %classpath%;%JAVA_HOME%libdt.jar
   @setx classpath %classpath%;%JAVA_HOME%jrelib
t.jar
   @echo on
   @echo Java 2 SDK 环境参数设置完毕，正常退出。
)  ELSE (
      IF "%1"=="" (
      rem 如没有提供安装目录，提示之后退出
      @echo on
      @echo 没有提供 Java2SDK 的安装目录,不做任何设置，现在退出环境变量设置。
      ) ELSE (
        rem 如果提供非空的安装目录但没有binjava.exe，则指定的目录为错误的目录
        @echo on
        @echo 非法的 Java2SDK 的安装目录,不做任何设置，现在退出环境变量设置。
      )
)
</pre>
<p>摘录至<a href="http://blog.weeker.org/">[weeker]</a></p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=20&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/auto-configure-environment-variable.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java学习笔记</title>
		<link>http://roamlog.info/archives/study-notes-of-java.html</link>
		<comments>http://roamlog.info/archives/study-notes-of-java.html#comments</comments>
		<pubDate>Fri, 09 Feb 2007 07:16:49 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/02/09/study-notes-of-java/</guid>
		<description><![CDATA[1.  构造器也可以声明为抛出检查型异常, throws子句位于参数列表之后,构造器的左花括号之前.如果有 throws 子句, 那么任何调用该构造器作为new表达式一部分的方法就都必须要么捕获这个声明的异常, 要么声明将这个异常抛出.
2.  方法中的所有参数都是&#8221;按值&#8221;传递的, 换句话说, 方法中参数变量的值是调用者所指派的引元之值的副本. 如果我们将一个 double 类型的引元传入方法, 那么无论传入的值是什么, 该方法的参数都是这个值的副本, 而且, 该方法对参数值的修改不会影响到调用这个方法的代码中的值. 例如:


class PassByValue&#123;
	public static void main&#40;String &#91;&#93; args&#41;&#123;
		double one = 1.0;
		System.out.println&#40;&#34;before: one = &#34; + one&#41;;
		halveIt&#40;one&#41;;
		System.out.println&#40;&#34;after: one = &#34; + one&#41;;
	&#125;
	public static void halveIt&#40;double arg&#41;&#123;
		arg /= 2.0;
		System.out.println&#40;&#34;halved: arg = &#34; + arg&#41;;
	&#125;
&#125;

下列输出说明, halveIt内部的arg的值被2整除之后并没有影响main方法中变量one的值:

before: one = 1.0
halved: arg [...]]]></description>
			<content:encoded><![CDATA[<p>1.  构造器也可以声明为抛出检查型异常, throws子句位于参数列表之后,构造器的左花括号之前.如果有 throws 子句, 那么任何调用该构造器作为new表达式一部分的方法就都必须要么捕获这个声明的异常, 要么声明将这个异常抛出.</p>
<p>2.  方法中的所有参数都是&#8221;按值&#8221;传递的, 换句话说, 方法中参数变量的值是调用者所指派的引元之值的副本. 如果我们将一个 double 类型的引元传入方法, 那么无论传入的值是什么, 该方法的参数都是这个值的副本, 而且, 该方法对参数值的修改不会影响到调用这个方法的代码中的值. 例如:<br />
<span id="more-17"></span></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> PassByValue<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: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">double</span> one <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1.0</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;before: one = &quot;</span> <span style="color: #339933;">+</span> one<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		halveIt<span style="color: #009900;">&#40;</span>one<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;after: one = &quot;</span> <span style="color: #339933;">+</span> one<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> halveIt<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span> arg<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		arg <span style="color: #339933;">/=</span> <span style="color: #cc66cc;">2.0</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;halved: arg = &quot;</span> <span style="color: #339933;">+</span> arg<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>下列输出说明, halveIt内部的arg的值被2整除之后并没有影响main方法中变量one的值:</p>
<p class="shell">
before: one = 1.0<br />
halved: arg = 0.5<br />
after: one = 1.0
</p>
<p> 应该注意的是, 如果参数是一个对象引用, 那么它就只是一个&#8221;值&#8221;传递的对象引用, 而非对象本身, 因此, 我们可以在方法内部修改参数所引用的对象, 而这不会影响到被传入的引用本身. 但是如果我们修改了对象的某些字段, 或者调用了可以修改对象状态的方法, 那么对于程序中所有存有该对象引用的部分而言, 都意味着这个对象发生了变化. 下面的例子显示了二者的区别:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> PassRef <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: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Body sirius <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Body<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sirius&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <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;before: &quot;</span> <span style="color: #339933;">+</span> sirius<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        commonName<span style="color: #009900;">&#40;</span>sirius<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;after:  &quot;</span> <span style="color: #339933;">+</span> sirius<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> commonName<span style="color: #009900;">&#40;</span>Body bodyRef<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        bodyRef.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Dog Star&quot;</span><span style="color: #339933;">;</span>
        bodyRef <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>该程序产生的输出如下:</p>
<p class="shell">
before: 0(sirius)<br />
after:   0(Dog star)
</p>
<p>注意, sirius所引用的对象的内容已经变了&#8212;&#8211;该对象的名字发生了变化, 但是变量sirius仍然保持着对Body对象的引用, 尽管commonName方法将参数变量bodyRef的值修改成了null.</p>
<p>附 <a href="http://www.amazon.com/Java-TM-Programming-Language-4th/dp/0321349806/ref=sr_11_1/104-1356882-4815942?ie=UTF8"">The Java Programming Language(Fourth Edition) </a> 上对参数值的描述</p>
<p>All parameters to methods are passed &#8220;by value.&#8221; In other words, values of parameter variables in a method are copies of the values the invoker specified as arguments. If you pass a double to a method, its parameter is a copy of whatever value was being passed as an argument, and the method can change its parameter&#8217;s value without affecting values in the code that invoked the method. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> PassByValue <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: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">double</span> one <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1.0</span><span style="color: #339933;">;</span>
&nbsp;
        <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;before: one = &quot;</span> <span style="color: #339933;">+</span> one<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        halveIt<span style="color: #009900;">&#40;</span>one<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;after:  one = &quot;</span> <span style="color: #339933;">+</span> one<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> halveIt<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">double</span> arg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        arg <span style="color: #339933;">/=</span> <span style="color: #cc66cc;">2.0</span><span style="color: #339933;">;</span>     <span style="color: #666666; font-style: italic;">// divide arg by two</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;halved: arg = &quot;</span> <span style="color: #339933;">+</span> arg<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>The following output illustrates that the value of arg inside halveIt is divided by two without affecting the value of the variable one in main:</p>
<p>before: one = 1.0<br />
halved: arg = 0.5<br />
after:  one = 1.0</p>
<p>You should note that when the parameter is an object reference, it is the object referencenot the object itselfthat is passed &#8220;by value.&#8221; Thus, you can change which object a parameter refers to inside the method without affecting the reference that was passed. But if you change any fields of the object or invoke methods that change the object&#8217;s state, the object is changed for every part of the program that holds a reference to it. Here is an example to show this distinction:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> PassRef <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: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        Body sirius <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Body<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sirius&quot;</span>, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <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;before: &quot;</span> <span style="color: #339933;">+</span> sirius<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        commonName<span style="color: #009900;">&#40;</span>sirius<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;after:  &quot;</span> <span style="color: #339933;">+</span> sirius<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <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> commonName<span style="color: #009900;">&#40;</span>Body bodyRef<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        bodyRef.<span style="color: #006633;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Dog Star&quot;</span><span style="color: #339933;">;</span>
        bodyRef <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This program produces the following output:</p>
<p>before: 0 (Sirius)<br />
after:  0 (Dog Star)</p>
<p>Notice that the contents of the object have been modified with a name change, while the variable sirius still refers to the Body object even though the method commonName changed the value of its bodyRef parameter variable to null. This requires some explanation.</p>
<p>The following diagram shows the state of the variables just after main invokes commonName:</p>
<p>At this point, the two variables sirius (in main) and bodyRef (in commonName) both refer to the same underlying object. When commonName changes the field bodyRef.name, the name is changed in the underlying object that the two variables share. When commonName changes the value of bodyRef to null, only the value of the bodyRef variable is changed; the value of sirius remains unchanged because the parameter bodyRef is a pass-by-value copy of sirius. Inside the method commonName, all you are changing is the value in the parameter variable bodyRef, just as all you changed in halveIt was the value in the parameter variable arg. If changing bodyRef affected the value of sirius in main, the &#8220;after&#8221; line would say &#8220;null&#8221;. However, the variable bodyRef in commonName and the variable sirius in main both refer to the same underlying object, so the change made inside commonName is visible through the reference sirius.</p>
<p>Some people will say incorrectly that objects are passed &#8220;by reference.&#8221; In programming language design, the term pass by reference properly means that when an argument is passed to a function, the invoked function gets a reference to the original value, not a copy of its value. If the function modifies its parameter, the value in the calling code will be changed because the argument and parameter use the same slot in memory. If the Java programming language actually had pass-by-reference parameters, there would be a way to declare halveIt so that the above code would modify the value of one, or so that commonName could change the variable sirius to null. This is not possible. The Java programming language does not pass objects by reference; it passes object references by value. Because two copies of the same reference refer to the same actual object, changes made through one reference variable are visible through the other. There is exactly one parameter passing modepass by valueand that helps keep things simple.</p>
<p>You can declare method parameters to be final, meaning that the value of the parameter will not change while the method is executing. Had bodyRef been declared final, the compiler would not have allowed you to change its value to null. When you do not intend to change a parameter&#8217;s value, you can declare it final so the compiler can enforce this expectation. A final declaration can also protect against assigning a value to a parameter when you intended to assign to a field of the same name. The declaration can also help the compiler or virtual machine optimize some expressions using the parameter, because it is known to remain the same. A final modifier on a parameter is an implementation detail that affects only the method&#8217;s code, not the invoking code, so you can change whether a parameter is final without affecting any invoking code.</p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=17&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/study-notes-of-java.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Shoot Yourself in the Foot in Any Programming Language</title>
		<link>http://roamlog.info/archives/how-to-shoot-yourself-in-the-foot-in-any-programming-language.html</link>
		<comments>http://roamlog.info/archives/how-to-shoot-yourself-in-the-foot-in-any-programming-language.html#comments</comments>
		<pubDate>Fri, 09 Feb 2007 03:36:34 +0000</pubDate>
		<dc:creator>漫步</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://roamlog.cn/index.php/2007/02/09/how-to-shoot-yourself-in-the-foot-in-any-programming-language/</guid>
		<description><![CDATA[
C
You shoot yourself in the foot.
C++
You accidentally create a dozen clones of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can’t tell which are bitwise copies and which are just pointing at others and saying, “That’s me, over there.”
JAVA
After importing java.awt.right.foot.* and java.awt.gun.right.hand.*, and writing the classes [...]]]></description>
			<content:encoded><![CDATA[<p><coolcode linenum="none"><br />
C<br />
You shoot yourself in the foot.</p>
<p>C++<br />
You accidentally create a dozen clones of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can’t tell which are bitwise copies and which are just pointing at others and saying, “That’s me, over there.”</p>
<p>JAVA<br />
After importing java.awt.right.foot.* and java.awt.gun.right.hand.*, and writing the classes and methods of those classes needed, you’ve forgotten what the hell you’re doing.<br />
<span id="more-16"></span><br />
Ruby<br />
Your foot is ready to be shot in roughly five minutes, but you just can’t find anywhere to shoot it.</p>
<p>PHP<br />
You shoot yourself in the foot with a gun made with pieces from 300 other guns.</p>
<p>ASP.NET<br />
Find a gun, it falls apart. Put it back together, it falls apart again. You try using the .GUN Framework, it falls apart. You stab yourself in the foot instead.</p>
<p>SQL<br />
SELECT @ammo:=bullet FROM gun WHERE trigger = ‘PULLED’;<br />
INSERT INTO leg (foot) VALUES (@ammo);</p>
<p>Perl<br />
You shoot yourself in the foot, but nobody can understand how you did it. Six months later, neither can you. (via Andy)</p>
<p>Javascript<br />
YOu’ve perfected a robust, rich user experience for shooting yourself in the foot. You then find that bullets are disabled on your gun.</p>
<p>CSS<br />
You shoot your right foot with one hand, then switch hands to shoot your left foot but you realize that the gun has turned into a banana.</p>
<p>FORTRAN<br />
You shoot yourself in each toe, iteratively, until you run out of toes, then you read in the next foot and repeat. If you run out of bullets, you continue anyway because you have no exception-handling ability.</p>
<p>Modula2<br />
After realizing that you can’t actually accomplish anything in this language, you shoot yourself in the head.</p>
<p>COBOL<br />
Using a COLT 45 HANDGUN, AIM gun at LEG.FOOT, THEN place ARM.HAND.FINGER. on HANDGUN.TRIGGER and SQUEEZE. THEN return HANDGUN to HOLSTER. CHECK whether shoelace needs to be retied.</p>
<p>LISP<br />
You shoot yourself in the appendage which holds the gun with which<br />
you shoot yourself in the appendage which holds the gun with which<br />
you shoot yourself in the appendage which holds the gun with which<br />
you shoot yourself in the appendage which holds the gun with which<br />
you shoot yourself in the appendage which holds ….</p>
<p>BASIC<br />
Shoot yourself in the foot with a water pistol. On big systems, continue until entire lower body is waterlogged.</p>
<p>FORTH<br />
Foot in yourself shoot.</p>
<p>APL<br />
You shoot yourself in the foot, then spend all day figuring out how to do it in fewer characters.</p>
<p>Pascal<br />
The compiler won’t let you shoot yourself in the foot.</p>
<p>SNOBOL<br />
If you succeed, shoot yourself in the left foot.<br />
If you fail, shoot yourself in the right foot.</p>
<p>Concurrent Euclid<br />
You shoot yourself in somebody else’s foot.</p>
<p>HyperTalk<br />
Put the first bullet of the gun into the foot of the left leg of you.<br />
Answer the result.</p>
<p>Motif<br />
You spend days writing a UIL description of your foot, the trajectory, the bullet, and the intricate scrollwork on the ivory handles of the gun. When you finally get around to pulling the trigger, the gun jams.</p>
<p>Unix<br />
% ls<br />
foot.c foot.h foot.o toe.c toe.o<br />
% rm * .o<br />
rm: .o: No such file or directory<br />
% ls<br />
%</p>
<p>Paradox<br />
Not only can you shoot yourself in the foot, your users can too.</p>
<p>Revelation<br />
You’ll be able to shoot yourself in the foot just as soon as you figure out what all these bullets are for.</p>
<p>Visual Basic<br />
You’ll shoot yourself in the foot, but you’ll have so much fun doing it that you won’t care.</p>
<p>Prolog<br />
You tell your program you want to be shot in the foot. The program figures out how to do it, but the syntax doesn’t allow it to explain.</p>
<p>Ada<br />
After correctly packaging your foot, you attempt to concurrently load the gun, pull the trigger, scream and shoot yourself in the foot. When you try, however, you discover that your foot is of the wrong type.</p>
<p>Assembly<br />
You try to shoot yourself in the foot only to discover you must first reinvent the gun, the bullet, and your foot. After that’s done, you pull the trigger, the gun beeps several times, then crashes.</p>
<p>370 JCL<br />
You send your foot down to MIS with a 4000-page document explaining how you want it to be shot. Three years later, your foot comes back deep-fried.</p>
<p>Python<br />
You try to shoot yourself in the foot but you just keep hitting the whitespace between your toes.</p>
<p></coolcode></p>
<img src="http://roamlog.info/?ak_action=api_record_view&id=16&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://roamlog.info/archives/how-to-shoot-yourself-in-the-foot-in-any-programming-language.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
