﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-kxbin-文章分类-J2EE</title><link>http://www.blogjava.net/kxbin/category/42063.html</link><description>创出一片天地</description><language>zh-cn</language><lastBuildDate>Wed, 21 Mar 2012 22:08:19 GMT</lastBuildDate><pubDate>Wed, 21 Mar 2012 22:08:19 GMT</pubDate><ttl>60</ttl><item><title>手工配置tomcat 的log参数 显示详细的log信息（转）</title><link>http://www.blogjava.net/kxbin/articles/372390.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Wed, 21 Mar 2012 10:00:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/372390.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/372390.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/372390.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/372390.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/372390.html</trackback:ping><description><![CDATA[<table style="table-layout: fixed; font-family: Arial; background-color: #ffffff; width: 959px; "><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; "><div id="blog_text" style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: 20px; overflow-x: hidden; overflow-y: hidden; position: relative !important; border-image: initial; "><p style="line-height: normal; ">开发测试中经常有tomcat报[严重]的错，但没有明细，这种情况下要手工配置tomcat 的log参数。</p><p style="line-height: normal; ">昨天部署web应用到<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">Tomcat</a>之后,无法成功启动,并且控制台没有详细的错误信息,<br />顶多就两行提示信息,例如:<br />严重: Error listenerStart<br />严重: Context [/lizongbo] startup failed due to previous errors</p><p style="line-height: normal; ">或者</p><p style="line-height: normal; ">严重: Error filterStart<br />org.apache.catalina.core.StandardContext start<br />严重: Context startup failed due to previous errors</p><p style="line-height: normal; ">查找logs目录下的信息,除了这两句话,也没别的辅助内容.<br />给查错带来了困难,在这种情况下,是因为<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">Tomcat</a>自身的默认日志没有将一些错误信息输出到控制台或文件,<br />这个时候则需要配置<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">Tomcat</a>自身的log,启用详细的调试日志.</p><p style="line-height: normal; ">在<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">Tomcat</a>&nbsp;5.5和<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">Tomcat</a>&nbsp;6.0中的配置基本一样,只是相关文件放的目录有所不同.</p><p style="line-height: normal; ">首先需要准备的文件为:</p><p style="line-height: normal; ">1.<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.jar , 下载地址 :&nbsp;<a href="http://www.apache.org/dist/logging/--escaped_anchor">http://www.apache.org/dist/logging/--escaped_anchor</a>:e0a22b16b97ca8dedb8d5b8c15ffbcaa--/1.2.15/apache-<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>-1.2.15.zip<br />2.<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">Tomcat</a>&nbsp;5.5所需的 commons-logging.jar,下载地址:&nbsp;<a href="http://www.apache.org/dist/commons/logging/binaries/commons-logging-1.1.zip">http://www.apache.org/dist/commons/logging/binaries/commons-logging-1.1.zip</a></p><p style="line-height: normal; ">3.<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>配置文件:<br /><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.properties<br />配置内容为:</p><p style="line-height: normal; "><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.rootLogger=ERROR,R</p><p style="line-height: normal; "><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.appender.CONSOLE=org.apache.<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.ConsoleAppender<br /><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.appender.CONSOLE.layout=org.apache.<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.PatternLayout<br /><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.appender.CONSOLE.layout.ConversionPattern=[%p]%t-%c-%m%n</p><p style="line-height: normal; "><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.appender.R=org.apache.<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.RollingFileAppender<br /><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.appender.R.File=${catalina.home}/logs/lizongbo.log<br /><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.appender.R.MaxFileSize=10MB<br /><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.appender.R.MaxBackupIndex=10<br /><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.appender.R.layout=org.apache.<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.PatternLayout<br /><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.appender.R.layout.ConversionPattern=[%p]%t-%c-%m%n</p><p style="line-height: normal; "><a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.logger.org.apache.catalina=INFO,R,CONSOLE</p><p style="line-height: normal; ">#日志级别不能太低,如果配置为debug的话,输出的日志信息太多,导致<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>启动非常的慢.</p><p style="line-height: normal; ">4.<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">Tomcat</a>&nbsp;6.0所需的juli替换文件:<br /><a href="http://www.apache.org/dist/--escaped_anchor">http://www.apache.org/dist/--escaped_anchor</a>:079305423cce36d6691457475e081123--/<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-6/v6.0.14/bin/extras/<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-juli-adapters.jar<br /><a href="http://www.apache.org/dist/--escaped_anchor">http://www.apache.org/dist/--escaped_anchor</a>:079305423cce36d6691457475e081123--/<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-6/v6.0.14/bin/extras/<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-juli.jar</p><p style="line-height: normal; ">在Tomcat6.0中,</p><p style="line-height: normal; ">将<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-juli-adapters.jar,<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>-1.2.15.jar,<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.properties复制到D:\Java\ApacheTomcat6.0.14\lib下面.</p><p style="line-height: normal; ">将<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-juli.jar复制到D:\Java\apache-<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-6.0.14\bin\下面.</p><p style="line-height: normal; ">然后启动<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>,就可以在D:\Java\apache-<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-6.0.14\logs下看到lizongbo.log了.</p><p style="line-height: normal; ">在 Tomcat5.5中,</p><p style="line-height: normal; ">将commons-logging-1.1.jar,<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>-1.2.15.jar,复制到D:\Java\apache-<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-5.5.25\common\lib下面.<br />将<a internal_tag"="" title="标签 log4j 下的日志" href="http://618119.com/tag/log4j" rel="tag nofollow">log4j</a>.properties复制到D:\Java\apache-<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-5.5.25\common\classes下面.</p><p style="line-height: normal; ">然后启动<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>,就可以在D:\Java\apache-<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-5.5.25\logs下看到lizongbo.log了.</p><p style="line-height: normal; ">在这个时候,再通过日志文件来分析,则会发现出现这种错误的情况可能有:<br />(以下是我遇到的出错情况,大多是些低级错误)<br />1.webapps要用到的classe文件根本没有复制到WEB-INF/classes目录下面<br />(java.lang.NoClassDefFoundError,而这个信息可能默认没输出到控制台,尤其是用了spring的,昨天就是这个粗心的低级错误)<br />2.要用到lib文件没有复制完,缺少lib<br />3.lib下的同一个库的jar文件存在多个不同版本,引起版本冲突.<br />4.lib下的jar与<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>版本不相对应(我遇到的问题是web应用在Tomcat5.5上运行正常,换到Tomcat6.0上就出错,<br />例如一个用了struts的webapp在<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">Tomcat</a>&nbsp;6上报下面的错误<br />&#8220;Parse Fatal Error at line 17 column 6: The processing instruction<br />target matching &#8220;[xX][mM][lL]&#8221; is not allowed&#8221; )</p><p style="line-height: normal; ">愿意看英文的可以参考官方网站说明:<br />http://<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>.apache.org/<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-6.0-doc/logging.html<br />http://<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>.apache.org/<a internal_tag"="" title="标签 Tomcat 下的日志" href="http://618119.com/tag/tomcat" rel="tag nofollow">tomcat</a>-5.5-doc/logging.html</p></div></td></tr></tbody></table><img src ="http://www.blogjava.net/kxbin/aggbug/372390.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2012-03-21 18:00 <a href="http://www.blogjava.net/kxbin/articles/372390.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>html中area标签使用 </title><link>http://www.blogjava.net/kxbin/articles/369640.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Thu, 09 Feb 2012 02:24:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/369640.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/369640.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/369640.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/369640.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/369640.html</trackback:ping><description><![CDATA[<div><pre id="question-content" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; word-wrap: break-word; zoom: 1; font-size: 14px; line-height: 24px; background-color: #fcfefc; "><div><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">&lt;html&gt;</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">&lt;body&gt;</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; ">&nbsp;<span style="font-size: 10.5pt; ">&lt;p&gt;</span><span style="font-size: 10.5pt; ">请点击图像上的星球，把它们放大。</span><span style="font-size: 10.5pt; ">&lt;/p&gt;</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; ">&nbsp;&lt;img</pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">src="<a href="http://www.w3school.com.cn/i/eg_planets.jpg" target="_blank"><span style="color:#133DB6;text-decoration:none;text-underline:none">http://www.w3school.com.cn/i/eg_planets.jpg</span></a>"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">border="0" usemap="#planetmap"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">alt="Planets" /&gt;</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; ">&nbsp;&lt;map name="planetmap" id="planetmap"&gt;</pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; ">&nbsp;&lt;area</pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">shape="circle"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">coords="180,139,14"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">href ="<a href="http://www.w3school.com.cn/example/html/venus.html" target="_blank"><span style="color:#133DB6;text-decoration:none;text-underline:none">http://www.w3school.com.cn/example/html/venus.html</span></a>"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">target ="_blank"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">alt="Venus" /&gt;</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; ">&nbsp;&lt;area</pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">shape="circle"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">coords="129,161,10"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">href ="<a href="http://www.w3school.com.cn/example/html/mercur.html" target="_blank"><span style="color:#133DB6;text-decoration:none;text-underline:none">http://www.w3school.com.cn/example/html/mercur.html</span></a>"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">target ="_blank"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">alt="Mercury" /&gt;</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; ">&nbsp;&lt;area</pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">shape="rect"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">coords="0,0,110,260"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">href ="<a href="http://www.w3school.com.cn/example/html/sun.html" target="_blank"><span style="color:#133DB6;text-decoration:none;text-underline:none">http://www.w3school.com.cn/example/html/sun.html</span></a>"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">target ="_blank"</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">alt="Sun" /&gt;</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; ">&nbsp;&lt;/map&gt;</pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; ">&nbsp;<span style="font-size: 10.5pt; ">&lt;p&gt;&lt;b&gt;</span><span style="font-size: 10.5pt; ">注释：</span><span style="font-size: 10.5pt; ">&lt;/b&gt;img </span><span style="font-size: 10.5pt; ">元素中的</span><span style="font-size: 10.5pt; "> "usemap" </span><span style="font-size: 10.5pt; ">属性引用</span><span style="font-size: 10.5pt; "> map </span><span style="font-size: 10.5pt; ">元素中的</span><span style="font-size: 10.5pt; "> "id" </span><span style="font-size: 10.5pt; ">或</span><span style="font-size: 10.5pt; "> "name" </span><span style="font-size: 10.5pt; ">属性（根据浏览器），所以我们同时向</span><span style="font-size: 10.5pt; "> map </span><span style="font-size: 10.5pt; ">元素添加了</span><span style="font-size: 10.5pt; "> "id" </span><span style="font-size: 10.5pt; ">和</span><span style="font-size: 10.5pt; "> "name" </span><span style="font-size: 10.5pt; ">属性。</span><span style="font-size: 10.5pt; ">&lt;/p&gt;</span></pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; ">&nbsp;&lt;/body&gt;</pre><pre style="font-family: Arial; line-height: 18pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; "><span style="font-size: 10.5pt; font-family: Arial; ">&lt;/html&gt;<br /><br /></span><div><pre id="best-answer-content"  mb10"="" style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; white-space: pre-wrap; word-wrap: break-word; zoom: 1; line-height: 22px; font-size: 14px; background-color: #fffcf6; "><div><pre style="margin-bottom: 7.5pt; line-height: 16.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 10.5pt; font-family: Arial; ">1.</span><span style="font-size: 10.5pt; ">第一个</span><span style="font-size: 10.5pt; font-family: Arial; ">area</span><span style="font-size: 10.5pt; ">是圆形</span></pre><pre style="margin-bottom: 7.5pt; line-height: 16.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 10.5pt; font-family: Arial; ">shape="circle"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*</span><span style="font-size: 10.5pt; ">说明是圆形</span><span style="font-size: 10.5pt; font-family: Arial; ">*/</span></pre><pre style="margin-bottom: 7.5pt; line-height: 16.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 10.5pt; font-family: Arial; ">coords="180,139,14"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*</span><span style="font-size: 10.5pt; ">圆心坐标是</span><span style="font-size: 10.5pt; font-family: Arial; ">(180,139)</span><span style="font-size: 10.5pt; ">，半径</span><span style="font-size: 10.5pt; font-family: Arial; ">14*/</span></pre><pre style="margin-bottom: 7.5pt; line-height: 16.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 10.5pt; font-family: Arial; ">2.</span><span style="font-size: 10.5pt; ">第二</span><span style="font-size: 10.5pt; font-family: Arial; ">area</span><span style="font-size: 10.5pt; ">个是矩形</span></pre><pre style="margin-bottom: 7.5pt; line-height: 16.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 10.5pt; font-family: Arial; ">shape="rect"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*</span><span style="font-size: 10.5pt; ">说明是矩形</span><span style="font-size: 10.5pt; font-family: Arial; ">*/</span></pre><pre style="margin-bottom: 7.5pt; line-height: 16.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 10.5pt; font-family: Arial; ">coords="0,0,110,260"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*</span><span style="font-size: 10.5pt; ">左上角坐标是</span><span style="font-size: 10.5pt; font-family: Arial; ">(0,0)</span><span style="font-size: 10.5pt; ">，右下角坐标是</span><span style="font-size: 10.5pt; font-family: Arial; ">(110,260)/</span></pre><pre style="margin-bottom: 7.5pt; line-height: 16.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-position: initial initial; background-repeat: initial initial; ">&nbsp;注。单位是像素，坐标可以是负值</pre></div></pre></div></pre></div></pre></div><img src ="http://www.blogjava.net/kxbin/aggbug/369640.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2012-02-09 10:24 <a href="http://www.blogjava.net/kxbin/articles/369640.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>web.xml中Servlet Filter的调用顺序(转载)</title><link>http://www.blogjava.net/kxbin/articles/367378.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Wed, 28 Dec 2011 00:58:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/367378.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/367378.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/367378.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/367378.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/367378.html</trackback:ping><description><![CDATA[<div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">Filter是一个很有用的东西，使用filter可以修改request, response, session, application中的内容。<br /><br /><span style="font-weight: bold; ">1. javax.servlet.Filter有两个重要的方法</span>&nbsp;<br />public void init(FilterConfig config)<br />public void doFilter(ServletRequest request, ServletResponse response,&nbsp;</p><div id="sina_keyword_ad_area2"  "="" style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp; FilterChain chain)<br />其中init方法用来作一些初始化的方法，而doFilter方法用来执行真正的过滤操作。<br /><br /><span style="font-weight: bold; ">2. Filter的部署方法</span>&nbsp;<br />在web.xml中要声明filter元素，并分配需要其处理的url，如下：<br />&lt;filter&gt;<br />&nbsp;&nbsp;&nbsp; &lt;filter-name&gt;Filter1&lt;/filter-name&gt;<br />&nbsp;&nbsp;&nbsp; &lt;filter-class&gt;com.baidu.Filter1&lt;/filter-class&gt;<br />&lt;/filter&gt;<br />&lt;filter&gt;<br />&nbsp;&nbsp;&nbsp; &lt;filter-name&gt;Filter2&lt;/filter-name&gt;<br />&nbsp;&nbsp;&nbsp; &lt;filter-class&gt;com.baidu.Filter2&lt;/filter-class&gt;<br />&lt;/filter&gt;<br />&lt;filter-mapping&gt;<br />&nbsp;&nbsp;&nbsp; &lt;filter-name&gt;Filter1&lt;/filter-name&gt;<br />&nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br />&lt;/filter-mapping&gt;<br />&lt;filter-mapping&gt;<br />&nbsp;&nbsp;&nbsp; &lt;filter-name&gt;Filter2&lt;/filter-name&gt;<br />&nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;/*&lt;/url-pattern&gt;<br />&lt;/filter-mapping&gt;<br /><br /><span style="font-weight: bold; ">3. doFilter函数的执行顺序</span>&nbsp;<br />当某个url请求匹配了多个Filter时，应用服务器将多个Filter组织成FilterChain，这个链的执行顺序是由其&lt;filter-mapping&gt;元素在web.xml文件中的顺序决定的。<br />doFilter函数可以过滤请求或者响应，当其过滤完请求后将调用FilterChain的doFilter函数让FilterChain中的下一个Filter来过滤请求。最先过滤请求的Filter将最后过滤相应，下面是个简单的例子。<br />public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; system.out.println(&#8220;filter request here ----&#8221;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // todo:<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; chain.doFilter(request,response);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; system.out.println(&#8220;filter response here ----&#8221;);<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // todo:<br /><br />}<br /><br /><span style="font-weight: bold; ">4.init函数的执行顺序</span>&nbsp;<br />&nbsp;&nbsp;&nbsp; 对于不同的应用服务器，Filter的init函数的执行时间是不同的，例如：tomcat会在tomcat启动的时候执行init函数，而weblogic等一些其他的应用服务器则会在该Filter匹配的url被首次请求的时候加载。<br /><span style="color: #0000ff; ">（下面的部分是我通过实验猜想的，不一定正确。）</span>&nbsp;<br />&nbsp;&nbsp;&nbsp; 对于tomcat而言，tomcat启动时会解析web.xml文件，然后按照&lt;filter&gt;元素的顺序将各个Filter元素加载到一个 HashMap中。解析完成后，会从HashMap中一个个的拿出Filter元素，串行的执行其init函数（这里的执行有先后关系，是在一个线程中执 行的）。所以在tomcat中定义的多个Filter其init函数的执行顺序就是其在HashMap中的散列顺序，具体来说与其在web.xml文件中 的定义位置及其名字有关。<br />&nbsp;&nbsp;&nbsp; 对于HashMap来说，如果其元素固定不变，则其顺序也是固定不变的，但当元素个数发生变化时，便不能保证其顺序（例如：当有两个元素时，A在B的前面，当再加入20个元素的时候A就不一定在B的前面了），所以init函数的执行顺序是无法保证的。</div></div><img src ="http://www.blogjava.net/kxbin/aggbug/367378.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2011-12-28 08:58 <a href="http://www.blogjava.net/kxbin/articles/367378.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>网站用户单点登录系统解决方案(转)</title><link>http://www.blogjava.net/kxbin/articles/367377.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Wed, 28 Dec 2011 00:53:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/367377.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/367377.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/367377.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/367377.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/367377.html</trackback:ping><description><![CDATA[<div><div style="font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><span style="color: #003399; "><strong style="font-weight: bold; ">网站用户单点登录系统解决方案<br /></strong></span></div><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">1 背景</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">　　在网站建设的过程中，多个应用系统一般是在不同的时期开发完成的。各应用系统由于功能侧重、设计方法和开发技术有所不同，也就形成了各自独立的 用户库和用户认证体系。随着网站的发展，会出现这样的用户群体：以其中的一个用户为例，他（她）使用网站的多个应用系统，但在每个应用系统中有独立的账 号，没有一个整体上的网站用户账号的概念，进入每一个应用系统前都需要以该应用系统的账号来登录。这带给用户不方便的使用感受，用户会想：既然我使用的是 同一个网站上的应用，为什么不能在一次在网站上登录之后不必再经过应用系统认证直接进入应用系统呢？用户的要求我们称之为 "单点登录"。</p><table border="0" cellspacing="0" cellpadding="0" width="100%" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><tbody><tr><td align="center" style="font-size: 1em; "><img src="http://www.ronghai.com/solution/2004-09/627/g1.GIF" alt="" width="465" height="307" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /></td></tr><tr><td align="center" style="font-size: 1em; "><strong style="font-weight: bold; ">图 1.1 网站用户要求单点登录</strong></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">2 分析</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">　　在多个拥有各自独立的用户体系的应用系统间实现单点登录，我们要考虑以下的问题：</p><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">单点登录系统的实现在各应用系统都采用B/S模式这一前提下进行。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">需要在各应用系统间统一用户认证标志，用户登录后可以得到用户令牌，各应用系统认可统一的用户令牌。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">用户令牌应当是安全加密的，并且要限定时效期。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">由于每个应用系统都有自己的用户库，一个用户可能在不同的应用系统中使用不同的账号，因此每个要使用多个应用系统的用户要设置一个统一的用户账号并以此账号进行单点登录，该账号与该用户在各应用系统中的一个账号形成映射关系。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">各应用系统可能属于不同的域，因此要实现跨域的单点登录。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">已经上线运行的应用系统需要进行改造来支持单点登录，正在开发的应用系统则可以在开发阶段增加对单点登录的支持，但应用系统之间应该是松耦合。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">由于各应用系统往往都已经处于稳定运行期，单点登录系统的实现应该对各应用系统的登录认证体系冲击最小，各应用系统原有的登录流程依然可用。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">一些应用服务器平台虽然提供对单点登录的支持，但要求应用系统用户认证的设计符合其规范，这对已经处于运行期的应用系统来说难以实现。</li></ul><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">3 设计</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">　　以下是系统的整体设计结构：</p><table border="0" cellspacing="0" cellpadding="0" width="100%" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><tbody><tr><td align="center" style="font-size: 1em; "><img src="http://www.ronghai.com/solution/2004-09/627/g2.GIF" alt="" width="348" height="234" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /></td></tr><tr><td align="center" style="font-size: 1em; "><strong style="font-weight: bold; ">图 3.1 系统结构图</strong></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><br /><br /><strong style="font-weight: bold; ">3.1 单点登录管理应用</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">　　我们首先设计单点登录管理应用：</p><table border="0" cellspacing="0" cellpadding="0" width="100%" style="color: #000000; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><tbody><tr><td align="center" style="font-size: 1em; "><img src="http://www.ronghai.com/solution/2004-09/627/g3.GIF" alt="" width="352" height="296" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /></td></tr><tr><td align="center" style="font-size: 1em; "><strong style="font-weight: bold; ">图 3.2 单点登录管理应用</strong></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">　　用户在其中注册一个单点登录账号，然后针对每个应用系统绑定一个该应用系统中原有的账号，并维护这些注册和绑定信息。绑定的过程需要单点登录管理应用服务器到应用系统服务器上验证用户提供的该应用系统中原有账号和密码，应用服务器均以相同的Web Service接口提供该功能支持。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">3.2 用户单点登录流程</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">　　 之后以用户单点登录管理应用和令牌传输识别的标准来实现用户单点登录流程。</p><blockquote style="border-left-width: 1px; border-left-color: #cccccc; margin-left: 10px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; background-color: #ffffff; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; "><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">1、用户访问应用系统。</p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td align="center" style="font-size: 1em; "><img src="http://www.ronghai.com/solution/2004-09/627/g4.GIF" alt="" width="146" height="83" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /></td></tr><tr><td align="center" style="font-size: 1em; "><strong style="font-weight: bold; ">图 3.3 用户单点登录流程 - 步骤一</strong></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">2、应用系统如果检查到用户没有在自己的服务器登录，则将用户请求重定向到单点登录服务器上。（使用重定向就可以处理各服务器跨域的情况）<br /></p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td align="center" style="font-size: 1em; "><img src="http://www.ronghai.com/solution/2004-09/627/g5.GIF" alt="" width="238" height="95" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /></td></tr><tr><td align="center" style="font-size: 1em; "><strong style="font-weight: bold; ">图 3.4 用户单点登录流程 - 步骤二</strong></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><br />3、单点登录服务器检查到用户已经单点登录（如果用户没有单点登录则要求用户登录，登录标志存储为客户端浏览器的Cookie），找到该用户在相应应用系统上绑定的账号。</p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td align="center" style="font-size: 1em; "><img src="http://www.ronghai.com/solution/2004-09/627/g6.GIF" alt="" width="278" height="182" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /></td></tr><tr><td align="center" style="font-size: 1em; "><strong style="font-weight: bold; ">图 3.5 用户单点登录流程 - 步骤三</strong></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">4、单点登录服务器根据第三步的结果生成用户令牌，重定向回应用系统。</p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td align="center" style="font-size: 1em; "><img src="http://www.ronghai.com/solution/2004-09/627/g7.GIF" alt="" width="238" height="95" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /></td></tr><tr><td align="center" style="font-size: 1em; "><strong style="font-weight: bold; ">图 3.6 用户单点登录流程 - 步骤四</strong></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">5、应用系统接收统一格式的用户令牌，取得用户在本系统上的登录账号，将用户在本系统上状态置为登录，返回用户请求访问的页面。</p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td align="center" style="font-size: 1em; "><img src="http://www.ronghai.com/solution/2004-09/627/g8.GIF" alt="" width="146" height="92" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; " /></td></tr><tr><td align="center" style="font-size: 1em; "><strong style="font-weight: bold; ">图 3.7 用户单点登录流程 - 步骤五</strong></td></tr></tbody></table><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">&nbsp;</p></blockquote><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">　　如果用户在访问应用系统之前已经在单点登录服务器上登录过，第二步到第四布对用户来说就是透明的，用户感觉只是向应用系统发出了访问请求，然后得到了页面反馈。</p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; "><br />4 实现</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">(略)</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><strong style="font-weight: bold; ">5 总结</strong></p><p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; ">　　本方案设计的用户单点登录系统做到了：</p><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 1.5em; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; font-size: 14px; line-height: 25px; text-align: left; background-color: #ffffff; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">真正了实现单点登录、全网访问，方便用户的使用过程。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">各系统之间耦合度低，应用系统的改造不破坏其固有流程和结构，整个系统的实施过程安全平滑。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">统一了单点登录服务器到应用服务器的用户认证信息访问标准，统一了令牌安全加密的传输和识别标准，为将来更多应用系统提供了统一的单点登录框架。</li><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 30px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">整合了过去分散在各应用系统中虽然有内在关联却难以判别的用户信息资源，为更进一步的用户个性化服务打下了基础。</li></ul></div><img src ="http://www.blogjava.net/kxbin/aggbug/367377.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2011-12-28 08:53 <a href="http://www.blogjava.net/kxbin/articles/367377.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> org.hibernate.exception.GenericJDBCException: Cannot release connection（转）</title><link>http://www.blogjava.net/kxbin/articles/365940.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Fri, 09 Dec 2011 01:01:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/365940.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/365940.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/365940.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/365940.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/365940.html</trackback:ping><description><![CDATA[<div><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; font: normal normal normal 20px/30px 'Microsoft YaHei'; text-align: left; background-color: #ffffff; "><h3><a href="http://blog.csdn.net/woshisap/article/details/6825292" title="org.hibernate.exception.GenericJDBCException: Cannot release connection" style="color: #000000; text-decoration: none; ">org.hibernate.exception.GenericJDBCException: Cannot release connection</a></h3></div><div id="article_content" style="margin-top: 20px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font-family: 'Courier New', Console, Verdana, 微软雅黑; font: normal normal normal 14px/26px Arial; color: #333333; text-align: left; background-color: #ffffff; "><span style="font-family: 微软雅黑; "><strong>问题：</strong><br />&nbsp;&nbsp;&nbsp;&nbsp;系统采用Spring MVC 2.5 + Spring 2.5 + Hibernate 3.2架构，其中数据源连接池采用的是Apache commons DBCP。问题是这样的，系统运行一段时间后（大致每隔8小时），访问系统会出现如下错误，再次访问恢复正常。<br /></span><div bg_html"="" style="width: 687px; "><div><div><a href="http://blog.csdn.net/woshisap/article/details/6825292#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" style="border-width: initial; border-color: initial; "><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; ">org.springframework.web.util.NestedServletException:&nbsp;Request&nbsp;processing&nbsp;failed;&nbsp;nested&nbsp;exception&nbsp;is&nbsp;org.hibernate.exception.GenericJDBCException:&nbsp;Cannot&nbsp;release&nbsp;connection&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;javax.servlet.http.HttpServlet.service(HttpServlet.java:617)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;javax.servlet.http.HttpServlet.service(HttpServlet.java:717)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">Caused&nbsp;by:&nbsp;org.hibernate.exception.GenericJDBCException:&nbsp;Cannot&nbsp;release&nbsp;connection&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:449)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:379)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.hibernate.jdbc.ConnectionManager.manualDisconnect(ConnectionManager.java:333)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.hibernate.impl.SessionImpl.disconnect(SessionImpl.java:375)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.orm.hibernate3.HibernateTransactionManager.doCleanupAfterCompletion(HibernateTransactionManager.java:744)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.transaction.support.AbstractPlatformTransactionManager.cleanupAfterCompletion(AbstractPlatformTransactionManager.java:989)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:855)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:800)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:339)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;sun.reflect.NativeMethodAccessorImpl.invoke0(Native&nbsp;Method)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;java.lang.reflect.Method.invoke(Method.java:585)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:421)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:136)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:326)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:313)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;36&nbsp;more&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">Caused&nbsp;by:&nbsp;java.sql.SQLException:&nbsp;Already&nbsp;closed.&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:77)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:180)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.closeConnection(LocalDataSourceConnectionProvider.java:96)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;at&nbsp;org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:445)&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;62&nbsp;more&nbsp;&nbsp;</span></li></ol></div>解决：<br /><p>&nbsp;&nbsp;&nbsp; 造成Cannot release connection的原因有很多，要具体问题具体分析。从异常分析，造成这个异常 org.hibernate.exception.GenericJDBCException: Cannot release connection 归根结底是Caused by: java.sql.SQLException: Already closed. 即连接已关闭。所以解决的办法就要从DBCP的参数配置入手，见下面的参数配置properties文件。</p><p>&nbsp;</p><div bg_html"="" style="width: 687px; "><div><div><a href="http://blog.csdn.net/woshisap/article/details/6825292#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" style="border-width: initial; border-color: initial; "><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; ">####&nbsp;::&nbsp;Apache&nbsp;DBCP&nbsp;::&nbsp;####&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.driverClassName</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">oracle</span><span style="border-width: initial; border-color: initial; ">.jdbc.driver.OracleDriver&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: blue; ">jdbc</span><span style="border-width: initial; border-color: initial; color: red; ">jdbc.url</span><span style="border-width: initial; border-color: initial; ">=jdbc:oracle:thin:@10.165.153.9:1521:PRDC&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.username</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">guser</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.password</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">guser</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#初始化连接&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.initialSize</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">0</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#连接池的最大活动个数&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.maxActive</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">20</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#没有人用连接的时候，最大闲置的连接个数。&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.maxIdle</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">100</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#没有人用连接的时候，最小闲置的连接个数。&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.minIdle</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">0</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#超时等待时间以毫秒为单位&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.maxWait</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">10000</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#是否自动回收超时连接&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.removeAbandoned</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">true</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#设置被遗弃的连接的超时的时间（以秒数为单位），即当一个连接被遗弃的时间超过设置的时间，则它会自动转换成可利用的连接。默认的超时时间是300秒。&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.removeAbandonedTimeout</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">60</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#是否在自动回收超时连接的时候打印连接的超时错误&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.logAbandoned</span><span style="border-width: initial; border-color: initial; ">&nbsp;=&nbsp;</span><span style="border-width: initial; border-color: initial; color: blue; ">true</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#给出一条简单的sql语句进行验证&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.validationQuery</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">select</span><span style="border-width: initial; border-color: initial; ">&nbsp;1&nbsp;from&nbsp;dual&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">#在取出连接时进行有效验证&nbsp;&nbsp;</span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; color: red; ">jdbc.testOnBorrow</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">true</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li></ol></div><span style="font-family: 微软雅黑; ">其中标红的两个参数的作用是对池化连接进行验证，This will ensure that DBCP only hands out good connections to Hibernate. 故加上这两个参数后，这个异常就不会再出现了。在Spring中指定数据源如下：</span><p>&nbsp;</p><p>&nbsp;</p><div bg_html"="" style="width: 687px; "><div><div><a href="http://blog.csdn.net/woshisap/article/details/6825292#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); border-width: initial; border-color: initial; padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a></div></div><ol start="1" style="border-width: initial; border-color: initial; "><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; "><span style="border-width: initial; border-color: initial; ">&lt;!-- &nbsp;使用Apache&nbsp;DBCP連接池&nbsp;--&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">bean</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">id</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"dataSource"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">class</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"org.apache.commons.dbcp.BasicDataSource"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">destroy-method</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"close"</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"driverClassName"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.driverClassName}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"url"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.url}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"username"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.username}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"password"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.password}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"maxActive"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.maxActive}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"maxIdle"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.maxIdle}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"maxWait"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.maxWait}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"removeAbandoned"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.removeAbandoned}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"removeAbandonedTimeout"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.removeAbandonedTimeout}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"logAbandoned"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.logAbandoned}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"validationQuery"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.validationQuery}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">property</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">name</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"testOnBorrow"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: red; ">value</span><span style="border-width: initial; border-color: initial; ">=</span><span style="border-width: initial; border-color: initial; color: blue; ">"${jdbc.testOnBorrow}"</span>&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">/&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&lt;/</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">bean</span><span style="border-width: initial; border-color: initial; color: #993300; font-weight: bold; ">&gt;</span><span style="border-width: initial; border-color: initial; ">&nbsp;&nbsp;</span></span></li></ol></div><p>&nbsp;</p></div></div><img src ="http://www.blogjava.net/kxbin/aggbug/365940.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2011-12-09 09:01 <a href="http://www.blogjava.net/kxbin/articles/365940.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>beanutils,StringUtils等工具包的学习</title><link>http://www.blogjava.net/kxbin/articles/365373.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Fri, 02 Dec 2011 06:11:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/365373.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/365373.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/365373.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/365373.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/365373.html</trackback:ping><description><![CDATA[1.beanutils<br />2.StringUtils<img src ="http://www.blogjava.net/kxbin/aggbug/365373.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2011-12-02 14:11 <a href="http://www.blogjava.net/kxbin/articles/365373.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>saveToken介绍一</title><link>http://www.blogjava.net/kxbin/articles/365348.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Fri, 02 Dec 2011 01:32:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/365348.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/365348.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/365348.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/365348.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/365348.html</trackback:ping><description><![CDATA[<div><div>1》防止多次点击&#8220;提交&#8221;,让多次&#8220;提交&#8221;变成只一次&#8220;提交&#8221;</div><div>saveToken(rquest)</div><div>的目的是页面上的按钮只相应一次，比如说，在页面上有个新增按钮，如果你连续点击数次，后台程序可能会响应n次，加了这句话，在页面</div><div></div><div>上自动生成一个hidden变量</div><div>2》防止页面重复提交</div><div>利用同步令牌（Token）机制来解决Web应用中重复提交的问题，Struts也给出了一个参考实现。</div><div></div><div>　　基本原理：　</div><div></div><div>　　服务器端在处理到达的请求之前，会将请求中包含的令牌值与保存在当前用户会话中的令牌值进行比较，看是否匹配。在处理完该请求后</div><div></div><div>，且在答复发送给客户端之前，将会产生一个新的令牌，该令牌除传给客户端以外，也会将用户会话中保存的旧的令牌进行替换。这样如果用</div><div></div><div>户回退到刚才的提交页面并再次提交的话，客户端传过来的令牌就和服务器端的令牌不一致，从而有效地防止了重复提交的发生。　</div><div></div><div>　　if (isTokenValid(request, true)) {</div><div>　　</div><div>　　// 表单不是重复提交</div><div>　　</div><div>　　//这里是保存数据的代码</div><div>　　</div><div>　　} else {</div><div>　　</div><div>　　//表单重复提交</div><div>　　</div><div>　　saveToken(request);</div><div>　　</div><div>　　//其它的处理代码</div><div>　　</div><div>　　}</div><div>&nbsp;</div><div>&nbsp;</div><div>网上例子为证：</div><div>&nbsp; &nbsp; public ActionForward execute(ActionMapping mapping, ActionForm form,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpServletRequest request, HttpServletResponse response) {</div><div>&nbsp; &nbsp; &nbsp; &nbsp; UserForm userForm = (UserForm)form;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; if(!isTokenValid(request)){ &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; saveToken(request);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; userForm.setMessage("重复提交");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return mapping.findForward("failure");</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; else{</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resetToken(request);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&nbsp; &nbsp; &nbsp; &nbsp; request.setAttribute("user", userForm);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; return mapping.findForward("success");</div><div>&nbsp; &nbsp; }</div><div>}</div><div>模板经典例子：</div><div>public ActionForward save(ActionMapping mapping, ActionForm form,</div><div>&nbsp; &nbsp;HttpServletRequest request, HttpServletResponse response)</div><div>&nbsp; &nbsp;throws BaseException {</div><div>&nbsp; if (!isTokenValid(request)) { // 如果指令无效，则属于重复提交</div><div>&nbsp; &nbsp;return (new ActionForward(mapping.getInput()));</div><div>&nbsp; } else {</div><div>&nbsp; &nbsp;resetToken(request);</div><div>&nbsp; }</div><div>&nbsp; BaseDao dao = DAOFactory.getDao(getEntityDAOClassName());</div><div>&nbsp; dao.begingTransaction();</div><div>&nbsp; Class cls = dao.getEntityClass();</div><div>&nbsp; try {</div><div>&nbsp; &nbsp;BaseVO vo = (BaseVO) cls.newInstance();</div><div>&nbsp; &nbsp;</div><div>&nbsp; &nbsp;DataTrans.copyProperties(vo, form);</div><div>&nbsp; &nbsp;this.saveEx(mapping, form, request, response, vo);</div><div>&nbsp; &nbsp;dao.save(vo);</div><div>&nbsp; &nbsp;dao.commitTransaction();</div><div>&nbsp; } catch (Exception e) {</div><div>&nbsp; &nbsp;dao.rollback();</div><div>&nbsp; &nbsp;throw new BaseException("保存数据出现异常");</div><div>&nbsp; } finally {</div><div>&nbsp; &nbsp;dao.sessionClose();</div><div>&nbsp; }</div><div>&nbsp; return mapping.findForward("saveSuccess");</div><div>&nbsp;}</div></div><div></div><img src ="http://www.blogjava.net/kxbin/aggbug/365348.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2011-12-02 09:32 <a href="http://www.blogjava.net/kxbin/articles/365348.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>saveToken介绍二</title><link>http://www.blogjava.net/kxbin/articles/365349.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Fri, 02 Dec 2011 01:32:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/365349.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/365349.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/365349.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/365349.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/365349.html</trackback:ping><description><![CDATA[<div><pre><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Struts</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">的</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Token</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">（令牌）机制能够很好的解决表单重复提交的问题，基本原理是：服务器端在处理到达的请求之前，会将请求中包含的令牌值与保存在当前用户会话中的令牌值进行比较，看是否匹配。在处理完该请求后，且在答复发送给客户端之前，将会产生一个新的令牌，该令牌除传给客户端以外，也会将用户会话中保存的旧的令牌进行替换。这样如果用户回退到刚才的提交页面并再次提交的话，客户端传过来的令牌就和服务器端的令牌不一致，从而有效地防止了重复提交的发生。</span></pre><pre><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">这时其实也就是两点，第一：你需要在请求中有这个令牌值，请求中的令牌值如何保存，其实就和我们平时在页面中保存一些信息是一样的，通过隐藏字段来保存，保存的形式如：</span> <span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〈</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">input type="hidden" name="org.apache.struts.taglib.html.TOKEN" value="6aa35341f25184fd996c4c918255c3ae"</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉，这个</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">value</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">是</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">TokenProcessor</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">类中的</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">generateToken()</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">获得的，是根据当前用户的</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">session id</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">和当前时间的</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">long</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">值来计算的。第二：在客户端提交后，我们要根据判断在请求中包含的值是否和服务器的令牌一致，因为服务器每次提交都会生成新的</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Token</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，所以，如果是重复提交，客户端的</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Token</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">值和服务器端的</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Token</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">值就会不一致。下面就以在数据库中插入一条数据来说明如何防止重复提交。</span></pre>  <p><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">中的</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">add</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法中，我们需要将</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Token</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">值明确的要求保存在页面中，只需增加一条语句：</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">saveToken(request);</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，如下所示：</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;"> <br /> public ActionForward add(ActionMapping mapping, ActionForm form, <br /> HttpServletRequest request, HttpServletResponse response)<br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">前面的处理省略</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> saveToken(request);<br /> return mapping.findForward("add");<br /> }</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">的</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">insert</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法中，我们根据表单中的</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Token</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">值与服务器端的</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Token</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">值比较，如下所示：</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> public ActionForward insert(ActionMapping mapping, ActionForm form, <br /> HttpServletRequest request, HttpServletResponse response)<br /> if (isTokenValid(request, true)) {<br /> // </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">表单不是重复提交</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">这里是保存数据的代码</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> } else {<br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">表单重复提交</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> saveToken(request);<br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">其它的处理代码</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> }<br /> }</span></p>  <pre><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">其实使用起来很简单，举个最简单、最需要使用这个的例子：</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">一般控制重复提交主要是用在对数据库操作的控制上，比如插入、更新、删除等，由于更新、删除一般都是通过</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">id</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">来操作（例如：</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">updateXXXById, removeXXXById</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">），所以这类操作控制的意义不是很大（不排除个别现象），重复提交的控制也就主要是在插入时的控制了。</span></pre><pre><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">先说一下，我们目前所做项目的情况：</span><span style="font-size: 13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">目前的项目是用</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Struts</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">＋</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">Spring</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">＋</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Ibatis</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，页面用</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">jstl</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Struts</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">复杂</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">View</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">层，</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Spring</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">在</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">Service</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">层提供事务控制，</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Ibatis</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">是用来代替</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">JDBC</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，所有页面的访问都不是直接访问</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">jsp</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，而是访问</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Structs</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">的</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，再由</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">来</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Forward</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">到一个</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">Jsp</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，所有针对数据库的操作，比如取数据或修改数据，都是在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里面完成，所有的</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">一般都继承</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">BaseDispatchAction</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，这个是自己建立的类，目的是为所有的</span><span style="font-size: 13.5pt;font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">做一些统一的控制，在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Struts</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">层，对于一个功能，我们一般分为两个</span><span style="font-size: 13.5pt;font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，一个</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里的功能是不需要调用</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Struts</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">的验证功能的（常见的方法名称有</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">add,edit,remove,view,list</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">），另一个是需要调用</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Struts</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">的验证功能的（常见的方法名称有</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">insert,update</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">）。</span></pre><pre><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">就拿论坛发贴来说吧，论坛发贴首先需要跳转到一个页面，你可以填写帖子的主题和内容，填写完后，单击</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">&#8220;</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">提交</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">&#8221;</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，贴子就发表了，所以这里经过两个步骤：</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> 1</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">、转到一个新增的页面，在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里我们一般称为</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">add</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，例如：</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> public ActionForward add(ActionMapping mapping, ActionForm form,<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpServletRequest request, HttpServletResponse response)<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throws Exception {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">这一句是输出调试信息，表示代码执行到这一段了</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; log.debug(":: action - subject add");&nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //your code here</span></pre><pre><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">这里保存</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Token</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">值</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; saveToken(request);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span style="font-size: 13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">跳转到</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">add</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">页面，在</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Structs-config.xml</span><span style="font-size: 13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里面定义，例如，跳转到</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">subjectAdd.jsp<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return mapping.findForward("add");<br /> &nbsp;&nbsp;&nbsp;&nbsp; }</span></pre><pre><span style="font-size: 13.5pt;font-family:&quot;Comic Sans MS&quot;">2</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">、在填写标题和内容后，选择</span> <span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">提交</span> <span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，会提交到</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">insert</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法，在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">insert</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法里判断，是否重复提交了。</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;"><br /> public ActionForward insert(ActionMapping mapping, ActionForm form, <br /> HttpServletRequest request, HttpServletResponse response){<br /> if (isTokenValid(request, true)) {<br /> // </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">表单不是重复提交</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">这里是保存数据的代码</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> } else {<br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">表单重复提交</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> saveToken(request);<br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">其它的处理代码</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> }<br /> }</span></pre><pre><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">下面更详细一点（注意，下面所有的代码使用全角括号）：</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> 1</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">、你想发贴时，点击</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">&#8220;</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">我要发贴</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">&#8221;</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">链接的代码可以里这样的：</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〈</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">html:link action="subject.do?method=add"</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉我要发贴〈</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">/html:link</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> subject.do </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">和</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"> method </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">这些在</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">struct-config.xml</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">如何定义我就不说了，点击链接后，会执行</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">subject.do</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">的</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">add</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法，代码如上面说的，跳转到</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">subjectAdd.jsp</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">页面。页面的代码大概如下：</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;"><br /> </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〈</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">html:form action="subjectForm.do?method=insert"</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;"><br /> &nbsp;&nbsp; </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〈</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">html:text property="title" /</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;"><br /> &nbsp;&nbsp; </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〈</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">html:textarea property="content" /</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;"><br /> &nbsp;&nbsp; </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〈</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">html:submit property="</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">发表</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">" /</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> &nbsp;&nbsp; </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〈</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">html:reset property="</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">重填</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">" /</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〈</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">html:form</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;"><br /> </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">如果你在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">add</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法里加了</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">&#8220;saveToken(request);&#8221;</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">这一句，那在</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">subjectAdd.jsp</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">生成的页面上，会多一个隐藏字段，类似于这样〈</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">input type="hidden" name="org.apache.struts.taglib.html.TOKEN" value="6aa35341f25184fd996c4c918255c3ae"</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">〉，</span></pre><pre><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">2</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">、点击发表后，表单提交到</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">subjectForm.do</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里的</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">insert</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法后，你在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">insert</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法里要将表单的数据插入到数据库中，如果没有进行重复提交的控制，那么每点击一次浏览器的刷新按钮，都会在数据库中插入一条相同的记录，增加下面的代码，你就可以控制用户的重复提交了。</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> if (isTokenValid(request, true)) {<br /> // </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">表单不是重复提交</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">这里是保存数据的代码</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> } else {<br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">表单重复提交</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> saveToken(request);<br /> //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">其它的处理代码</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> }<br /> </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">注意，你必须在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">add</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法里使用了</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">saveToken(request)</span><span style="font-size: 13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，你才能在</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">insert</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里判断，否则，你每次保存操作都是重复提交。</span><span style="font-size: 13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">记住一点，</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Struts</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">在你每次访问</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">的时候，都会产生一个令牌，保存在你的</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Session</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里面，如果你在</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里的函数里面，使用了</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">saveToken(request);</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，那么这个令牌也会保存在这个</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">所</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Forward</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">到的</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">jsp</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">所生成的静态页面里。</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">如果你在你</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">的方法里使用了</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">isTokenValid</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，那么</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Struts</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">会将你从你的</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">request</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里面去获取这个令牌值，然后和</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">Session</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">里的令牌值做比较，如果两者相等，就不是重复提交，如果不相等，就是重复提交了。</span></pre><pre><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">由于我们项目的所有</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">Action</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">都是继承自</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">BaseDispatchAction</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">这个类，所以我们基本上都是在这个类里面做了表单重复提交的控制，默认是控制</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">add</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法和</span><span style="font-size:13.5pt;font-family: &quot;Comic Sans MS&quot;">insert</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">方法，如果需要控制其它的方法，就自己手动写上面这些代码，否则是不需要手写的，控制的代码如下：</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"><br /> public abstract class BaseDispatchAction extends BaseAction {<br /> protected ActionForward perform(ActionMapping mapping, ActionForm form,<br /> &nbsp;&nbsp;&nbsp;&nbsp; HttpServletRequest request, HttpServletResponse response)<br /> &nbsp;&nbsp;&nbsp;&nbsp; throws Exception {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String parameter = mapping.getParameter();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String name = request.getParameter(parameter);<br /> if (null == name) { //</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">如果没有指定</span><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;"> method </span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">，则默认为</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;"> list<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; name = "list";<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></pre><pre><span style="font-size:13.5pt;font-family:&quot;Comic Sans MS&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ("add".equals(name)) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ("add".equals(name)) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; saveToken(request);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else if ("insert".equals(name)) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (!isTokenValid(request, true)) {<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; resetToken(request);<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; saveError(request, new ActionMessage("error.repeatSubmit"));<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; log.error("</span><span style="font-size:13.5pt;Comic Sans MS&quot;;Comic Sans MS&quot;">重复提交！</span><span style="font-size:13.5pt; font-family:&quot;Comic Sans MS&quot;">");<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return mapping.findForward("error");<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return dispatchMethod2(mapping, form, request, response, name);<br /> &nbsp;&nbsp;&nbsp;&nbsp; }<br /> }</span></pre>  <p>&nbsp;</p></div><img src ="http://www.blogjava.net/kxbin/aggbug/365349.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2011-12-02 09:32 <a href="http://www.blogjava.net/kxbin/articles/365349.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用连接池连接MySQL</title><link>http://www.blogjava.net/kxbin/articles/325296.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Mon, 05 Jul 2010 08:15:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/325296.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/325296.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/325296.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/325296.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/325296.html</trackback:ping><description><![CDATA[TomCat6.0数据库连接池配置有几种方式，在这里我只介绍其中的一种供大家参考： 
<br />下面我把配置过程分成三个步骤来完成： 
<br />第一步：在你安装TomCat的目录下找到context.xml配置文件。（例如：D:\Tomcat 
6.0\conf\context.xml）然后打开context.xml，在标
签&lt;context&gt;&lt;/&lt;context&gt;之间加入以下内容：(为了大家容易理解，我加了较详细的注释) 
<br />&lt;Resource 
<br />name="jdbc/course" //数据源名称（自定义）到时候要用到的，所以最好起 
<br />//个有含义的名字，例如我这个数据源名字，jdbc表示与//数据库连接有关的，而course是我这个项目的名字。 
<br />auth="Container" //这个默认就好了 
<br />type="javax.sql.DataSource" //这个也默认就好了 
<br />              
driverClassName="com.mysql.jdbc.Driver"//这里用到的是mysql数据库的驱动包。 
<br />              url="jdbc:mysql://localhost/course" 
//这里是连接到mysql数据库的url，其中url="jdbc:mysql://localhost/"是固定的，而course是我这个 
//项目的数据库名称，所以这里改为你们的数据库名称就好了。 
<br />              username="root"//登陆数据库的用户名  
<br />     password="birchhua" //登陆数据库的密码 
<br />     maxIdle="5"//这个也默认就好了 
<br />              maxWait="5000"//这个也默认就好了 
<br />              maxActive="10"/&gt;//这个也默认就好了 
<br /><br />第二步：在你的项目WEB-INF目录下找到web.xml配置文件，然后打开，在标签&lt;web-app&gt;&lt;/web-
app&gt;之间加入以下内容： 
<br />&lt;resource-ref&gt; 
<br />&lt;description&gt;DB Connection&lt;/description&gt; 
<br />&lt;res-ref-name&gt;jdbc/course&lt;/res-ref-name&gt; 
<br />&lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt; 
<br />&lt;res-auth&gt;Container&lt;/res-auth&gt; 
<br />&lt;/resource-ref&gt; 
<br />其中：DB Connection 
是自定义的，而jdbc/course是对应上面&lt;Resource&gt;&lt;/Resource&gt;标签中的name属性的值，还有
javax.sql.DataSource就对应type属性的值，而最后Container对应的是auth属性的值。 
<br /><br />第三步：上网下载一个叫mysql-connector-java-3.1.10-bin.jar的jar包，然后将该jar包放到TomCat
安装目录下的lib文件夹里。（例如：D:\Tomcat 
6.0\lib\mysql-connector-java-3.1.10-bin.jar）完成这三步就配置好了TomCat数据源了。 
<br /><br /><br />&lt;%@ page contentType="text/html; charset=gb2312" %&gt;<br />&lt;%@ page import="javax.naming.Context" %&gt;<br />&lt;%@ page import="javax.sql.DataSource"%&gt;<br />&lt;%@ page import="javax.naming.InitialContext"%&gt;<br />&lt;%@ page import="java.sql.*"%&gt;<br />&lt;html&gt;<br />&lt;body&gt;<br />&lt;%<br />       DataSource ds = null;<br />       try{<br />          Context initCtx = new InitialContext();<br />          Context envCtx = (Context) initCtx.lookup("java:comp/env/");<br />         //从Context中lookup数据源。<br />          ds = (DataSource)envCtx.lookup("jdbc/kxbin");<br />          if(ds!=null){<br />            out.println("已经获得DataSource!");<br />            out.println("&lt;br&gt;");<br />            Connection conn = ds.getConnection();<br />            PreparedStatement pstmt = conn.prepareStatement("select * from student");<br />            ResultSet rs = pstmt.executeQuery();<br />            while(rs.next()){<br />                out.println(rs.getString("id"));<br />                out.println(rs.getString("stuName"));<br />                out.println(rs.getString("password"));<br />                out.println("&lt;br/&gt;");<br />            }<br />            }<br />        }catch(Exception ne){<br />           out.println("出现如下错误：&lt;br&gt;");<br />           out.println(ne);<br />       }  <br /><br />%&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;<br /><br /><br /><img src ="http://www.blogjava.net/kxbin/aggbug/325296.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2010-07-05 16:15 <a href="http://www.blogjava.net/kxbin/articles/325296.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JAVA 编码不可不注意的规范</title><link>http://www.blogjava.net/kxbin/articles/313444.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Sat, 20 Feb 2010 05:45:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/313444.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/313444.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/313444.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/313444.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/313444.html</trackback:ping><description><![CDATA[
		<p>一、规范存在的意义</p>
		<p>应用编码规范对于软件本身和软件开发人员而言尤为重要，有以下几个原因：</p>
		<p>1、好的编码规范可以尽可能的减少一个软件的维护成本 , 并且几乎没有任何一个软件，在其整个生命周期中，均由最初的开发人员来维护；</p>
		<p>2、好的编码规范可以改善软件的可读性，可以让开发人员尽快而彻底地理解新的代码；</p>
		<p>3、好的编码规范可以最大限度的提高团队开发的合作效率；</p>
		<p>4、长期的规范性编码还可以让开发人员养成好的编码习惯，甚至锻炼出更加严谨的思维；</p>
		<p>二、命名规范</p>
		<p>1、一般概念</p>
		<p>1、尽量使用完整的英文描述符</p>
		<p>2、采用适用于相关领域的术语</p>
		<p>3、采用大小写混合使名字可读</p>
		<p>4、尽量少用缩写，但如果用了，必须符合整个工程中的统一定义</p>
		<p>5、避免使用长的名字（小于 15 个字母为正常选择）</p>
		<p>6、避免使用类似的名字，或者仅仅是大小写不同的名字</p>
		<p>7、避免使用下划线（除静态常量等）</p>
		<p>2、标识符类型说明</p>
		<p>1、包（ Package ）的命名</p>
		<p>Package 的名字应该采用完整的英文描述符，都是由一个小写单词组成。并且包名的前缀总是一个顶级域名，</p>
		<p>通常是 com、edu、gov、mil、net、org 等；<br />如： com.yjhmily.test</p>
		<p>2、类（ Class ）的命名</p>
		<p>类名应该是个一名词，采用大小写混合的方式，每个单词的首字母大写。尽量保证类名简洁而富于描述。</p>
		<p>使用完整单词，避免缩写词 ( 除非工程内有统一缩写规范或该缩写词被更广泛使用，像 URL ， HTML)</p>
		<p>如： FileDescription</p>
		<p>3、接口（ Interface ）的命名</p>
		<p>基本与 Class 的命名规范类似。在满足 Classd 命名规则的基础之上，保证开头第一个字母为 ”I”，</p>
		<p>便于与普通的 Class区别开。其实现类名称取接口名的第二个字母到最后，且满足类名的命名规范；</p>
		<p>如： IMenuEngine</p>
		<p>4、枚举（ Enum ）的命名</p>
		<p>基本与 Class 的命名规范类似。在满足 Classd 命名规则的基础之上，保证开头第一个字母为 ”E” ，</p>
		<p>便于与普通的 Class区别开。<br />如： EUserRole</p>
		<p>5、异常（ Exception ）的命名</p>
		<p>异常（ Exception ） 通常采用字母 e 表示异常，对于自定义的异常类，其后缀必须为 Exception</p>
		<p>如： BusinessException</p>
		<p>6、方法（ Method ）的命名</p>
		<p>方法名是一个动词，采用大小写混合的方式，第一个单词的首字母小写，其后单词的首字母大写。</p>
		<p>方法名尽可能的描述出该方法的动作行为。返回类型为 Boolean 值的方法一般由“ is ”或“ has ”来开头</p>
		<p>如： getCurrentUser() 、 addUser() 、 hasAuthority()</p>
		<p>7、参数（ Param ）的命名</p>
		<p>第一个单词的首字母小写，其后单词的首字母大写。参数量名不允许以下划线或美元符号开头，</p>
		<p>虽然这在语法上是允许的。参数名应简短且富于描述。</p>
		<p>如： public UserContext getLoginUser(String loginName); </p>
		<p>8、常量字段 （ Constants ）的命名</p>
		<p>静态常量字段（ static final ） 全部采用大写字母，单词之间用下划线分隔；</p>
		<p>如： public static final Long FEEDBACK; <br />public static Long USER_STATUS; </p>
		<p>三、注释规范</p>
		<p>一个很好的可遵循的有关注释的经验法则是：</p>
		<p>问问你自己，你如果从未见过这段代码，要在合理的时间内有效地明白这段代码，你需要一些什么信息？？？</p>
		<p>1、一般概念</p>
		<p>1、注释应该增加代码的清晰度</p>
		<p>2、保持注释的简洁</p>
		<p>3、在写代码之前或同时写注释</p>
		<p>4、注释出为什么做了一些事，而不仅仅是做了什么</p>
		<p>2、注释哪些部分</p>
		<p>1、Java 文件：必须写明版权信息以及该文件的创建时间和作者；</p>
		<p>2、类：类的目的、即类所完成的功能，以及该类创建的时间和作者名称；多人一次编辑或修改同一个类时，</p>
		<p>应在作者名称处出现多人的名称；</p>
		<p>3、接口： 在满足类注释的基础之上，接口注释应该包含设置接口的目的、它应如何被使用以及如何不被使用。</p>
		<p>在接口注释清楚的前提下对应的实现类可以不加注释；</p>
		<p>4、方法注释： 对于设置 (Set 方法 ) 与获取 (Get 方法 ) 成员的方法，在成员变量已有说明的情况下，</p>
		<p>可以不加注释；普通成员方法要求说明完成什么功能，参数含义是什么且返回值什么；另外方法的创建</p>
		<p>时间必须注释清楚，为将来的维护和阅读提供宝贵线索；</p>
		<p>5、方法内部注释： 控制结构，代码做了些什么以及为什么这样做，处理顺序等，特别是复杂的逻辑处理部分，</p>
		<p>要尽可能的给出详细的注释；</p>
		<p>6、参数： 参数含义、及其它任何约束或前提条件；</p>
		<p>7、属性： 字段描述；</p>
		<p>8、局部 ( 中间 ) 变量： 无特别意义的情况下不加注释；</p>
		<p>3、注释格式</p>
		<p>遵循工程规定的统一注释格式，一般情况下会以 codetemplates.xml 格式的文件导入 IDE(Eclipse) </p>
		<p>或者用Eclipse默认的；</p>
		<p>四、代码格式规范</p>
		<p>遵循工程规定的统一代码格式，一般情况下直接使用 IDE(Eclipse) 自带的默认代码格式对代码进行格式化；</p>
		<p>五、其他规范</p>
		<p>JSP 文件命名</p>
		<p>采用完整的英文描述说明 JSP 所完成的功能，尽可能包括一个生动的动词，第一个字母小写，</p>
		<p>如： viewMessage.jsp 、editUser.jsp 等。</p>
		<p>六、工程特有命名规范</p>
		<p>1、持久层</p>
		<p>1、 Hibernate 映射文件及实体</p>
		<p>与数据库表名称完全对应；<br />如： Advertisement.hbm.xml 、 Advertisement.java</p>
		<p>2、数据访问 DAO</p>
		<p>DAO 接口和实现类名称必须完全符合正常接口和实现类的命名规则，且最后以 ”DAO” 结尾</p>
		<p>DAO 内的数据访问方法必须足够抽象的描述出对数据库的基本 CRUD 操作；<br />如： ICrossAdDAO( 接口 ) 、 CrossAdDAO( 实现类 )</p>
		<p>3、各种操作数据库的 HQL 配置文件</p>
		<p>HQL 文件的个数原则上与系统的 Services 层的服务个数相等，且以服务名称命名 HQL 文件；</p>
		<p>如： resource.hbm.xml</p>
		<p>2、服务层</p>
		<p>1、服务接口和实现</p>
		<p>服务接口和实现类必须完全符合正常接口和实现类的命名规则；以工程定义的服务名为主体，</p>
		<p>并统一以 ”Serv” 结尾<br />如： IResourceServ( 服务接口 ) 、 ResourceServ( 接口实现类 )</p>
		<p>2、服务接口方法</p>
		<p>方法名是一个动词，采用大小写混合的方式，第一个单词的首字母小写，其后单词的首字母大写。</p>
		<p>方法名尽可能的描述出该方法的动作行为。</p>
		<p>返回类型为 Boolean 值：用“ is ”或“ has ”来开头<br />得到某数据： get+ 数据描述名词复数 + 数据类型；<br />得到所有数据： get+All+ 数据描述名词复数 + 数据类型；<br />通过 XXX 得到 / 查询某数据： get/query+ 数据描述名词复数 + 数据类型 +By+ 条件；<br />添加某数据： save/add+ 数据描述名词 ()<br />更新某数据： save/update+ 数据描述名词；<br />删除某数据： delete/remove+ 数据描述名词；</p>
		<p>3、业务对象</p>
		<p>业务名称 +BO</p>
		<p>4、查询参数对象</p>
		<p>凡是继承 Abst***QuerySpec 的查询参数类全部满足以下规则：<br />Query+ 所要查询的数据描述名词 +Spec<br />作为参数传入时，参数名必须为：所要查询的数据描述名词 +Spec<br />如： QueryProgramSpec</p>
		<p>3、MVC 层 </p>
		<p>1、Action 控制层</p>
		<p>Action 类名：功能模块名称 +Action ；<br />Actoin 方法名称尽可能的描述出页面迁移的去向<br />如： LoginAction( 登录用 action) ， toWelcome( 转向欢迎页的 action 方法 )</p>
		<p>2、资源文件</p>
		<p>系统全局资源文件： globalMessages_+ 字符编码类型 +.properties<br />功能模块内部的资源文件： package.properties</p>
		<p>4、Spring 配置文件</p>
		<p>1、Action 相关配置文件<br />文件目录： WebRoot/WEB-INF/spring/action/ 功能模块名称 +_ApplicationContext.xml</p>
		<p>2、Services 相关配置文件</p>
		<p>文件目录： WebRoot/WEB-INF/spring/services/Services_ApplicationContext.xml</p>
		<p>3、全局性配置文件</p>
		<p>文件目录： WebRoot/WEB-INF/spring/工程名+_ApplicationContext.xml</p>
		<p>5、JSP 文件</p>
		<p>采用完整的英文描述说明 JSP 所完成的功能，尽可能包括一个生动的动词，第一个字母小写，<br />如： viewMessage.jsp 、editUser.jsp 等。</p>
		<p>
				<br />本文来自CSDN博客，转载请标明出处：<a href="http://blog.csdn.net/lyjia2001/archive/2007/11/02/1863402.aspx">http://blog.csdn.net/lyjia2001/archive/2007/11/02/1863402.aspx</a></p>
<img src ="http://www.blogjava.net/kxbin/aggbug/313444.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2010-02-20 13:45 <a href="http://www.blogjava.net/kxbin/articles/313444.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>EL表达式</title><link>http://www.blogjava.net/kxbin/articles/297763.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Sun, 11 Oct 2009 03:56:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/297763.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/297763.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/297763.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/297763.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/297763.html</trackback:ping><description><![CDATA[
		<p>
				<span style="font-size: medium;">
						<span style="font-size: large;">
								<strong>
										<br />
								</strong>
						</span>
				</span>
		</p>
		<p>
				<span style="font-size: medium;">
						<span style="font-size: large;">
								<strong>作用域</strong>
						</span>
						<br />
						<br />
				</span>使用el的时候，默认会以一定顺序搜索四个作用域，将最先找到的变量值显示出来。</p>
		<div class="mediaobject">
				<img src="http://www.family168.com/tutorial/jsp/shared/images/jsp-ch-13-02-scope-01.png" alt="" align="middle" />
		</div>
		<p>如果我们有${username}这样一个正则表达式，它回去依次调用pageContext.getAttribute("username")
-&gt; request.getAttribute("username") -&gt;
session.getAttribute("username") -&gt;
application.getAttribute("username")，只要找到某一个不为空的值就立刻返回。</p>
		<p>这样的确方便我们的操作，但是随之也出现了另外一个问题，如果pageContext和request中有同名变量，但是我想取得request中的变量该如何是好呢？这就需要为el表达式引入作用域的概念了。</p>
		<pre class="programlisting">${pageScope.username}<br /><br />${requestScope.username}<br /></pre>
		<p>我们可以直接访问13-04这个应用，看看el表达式支持的所有对象。</p>
		<div class="mediaobject">
				<img src="http://www.family168.com/tutorial/jsp/shared/images/jsp-ch-13-02-scope-02.png" alt="" align="middle" />
		</div>
		<p>下面我们分别对每个作用域对象进行讲解。</p>
		<div class="table">
				<a name="d4e1749">
				</a>
				<p class="title">
						<strong>表 13.1. el中的作用域</strong>
				</p>
				<div class="table-contents">
						<table summary="el中的作用域" border="1">
								<colgroup span="1">
										<col span="1" />
										<col span="1" />
								</colgroup>
								<thead>
										<tr>
												<th align="center">el中的作用域</th>
												<th align="center">对应关系</th>
										</tr>
								</thead>
								<tbody>
										<tr>
												<td align="center">pageContext<a name="co-jsp-ch-13-02-01"></a>(1)</td>
												<td align="center">当前页的pageContext对象</td>
										</tr>
										<tr>
												<td align="center">pageScope</td>
												<td align="center">把page作用域中的数据映射为一个map对象</td>
										</tr>
										<tr>
												<td align="center">requestScope<a name="co-jsp-ch-13-02-02"></a>(2)</td>
												<td align="center">把request作用域中的数据映射为一个map对象</td>
										</tr>
										<tr>
												<td align="center">sessionScope</td>
												<td align="center">把session作用域中的数据映射为一个map对象</td>
										</tr>
										<tr>
												<td align="center">applicationScope</td>
												<td align="center">把application作用域中的数据映射为一个map对象</td>
										</tr>
										<tr>
												<td align="center">param</td>
												<td align="center">对应request.getParameter()</td>
										</tr>
										<tr>
												<td align="center">paramValues<a name="co-jsp-ch-13-02-03"></a>(3)</td>
												<td align="center">对应request.getParameterValues()</td>
										</tr>
										<tr>
												<td align="center">header<a name="co-jsp-ch-13-02-04"></a>(4)</td>
												<td align="center">对应request.getHeader()</td>
										</tr>
										<tr>
												<td align="center">headerValues</td>
												<td align="center">对应request.getHeaderValues()</td>
										</tr>
										<tr>
												<td align="center">cookie<a name="co-jsp-ch-13-02-05"></a>(5)</td>
												<td align="center">对应request.getCookies()</td>
										</tr>
										<tr>
												<td align="center">initParam<a name="co-jsp-ch-13-02-06"></a>(6)</td>
												<td align="center">对应ServletContext.getInitParamter()</td>
										</tr>
								</tbody>
						</table>
				</div>
		</div>
		<p>
				<br class="table-break" />
		</p>
		<div class="calloutlist">
				<table summary="Callout list" border="0">
						<tbody>
								<tr>
										<td align="left" valign="top" width="5%">
												<p>
														<a href="http://www.family168.com/tutorial/jsp/html/jsp-ch-13.html#co-jsp-ch-13-02-01">
																<span style="color: rgb(16, 138, 198);">(1)</span>
														</a>
												</p>
										</td>
										<td align="left" valign="top">
												<p>例子中的${pageContext.request.contextPath}返回的是request.getContextPath()的值，在此例中就是/13-04，我们经常使用这个来拼接jsp中的绝对路径。</p>
												<p>这里的${pageContext.request.contextPath}是一种特殊用法，不能使用${request.contextPath}的形式替代。</p>
										</td>
								</tr>
								<tr>
										<td align="left" valign="top" width="5%">
												<p>
														<a href="http://www.family168.com/tutorial/jsp/html/jsp-ch-13.html#co-jsp-ch-13-02-02">
																<span style="color: rgb(16, 138, 198);">(2)</span>
														</a>
												</p>
										</td>
										<td align="left" valign="top">
												<p>pageScope, requestScope, sessionScope,
appliationScope都可以看作是Map型变量，调用其中的数据可以使用${pageScope.name}
或${pageScope["name"]}的形式，这两种写法是等价的。</p>
												<p>在某些情况下只能使用${pageScope["content-type"]}，这里不能写成${pageScope.content-type}，jsp无法解析连字符（-）会出现错误。</p>
										</td>
								</tr>
								<tr>
										<td align="left" valign="top" width="5%">
												<p>
														<a href="http://www.family168.com/tutorial/jsp/html/jsp-ch-13.html#co-jsp-ch-13-02-03">
																<span style="color: rgb(16, 138, 198);">(3)</span>
														</a>
												</p>
										</td>
										<td align="left" valign="top">
												<p>需要注意的是${paramValues.name}得到的是一个字符串数组，如果需要获得其中某个值，还需要使用${paramValues.name[0]}指定数组中的索引。</p>
												<p>这与下面的${headerValues.name}是相似的。</p>
										</td>
								</tr>
								<tr>
										<td align="left" valign="top" width="5%">
												<p>
														<a href="http://www.family168.com/tutorial/jsp/html/jsp-ch-13.html#co-jsp-ch-13-02-04">
																<span style="color: rgb(16, 138, 198);">(4)</span>
														</a>
												</p>
										</td>
										<td align="left" valign="top">
												<p>${header.name}会取得http请求中的header参数，现实工作中很少用到这里的数据。</p>
												<p>例子中使用Host是指请求访问的主机地址，包括ip和端口号。而Referer比较有趣，如果用户通过超链接跳转过来的，Referer会保存上次访问页面的地址，我们就可以通过它来统计哪些用户是从哪里转来的了。</p>
										</td>
								</tr>
								<tr>
										<td align="left" valign="top" width="5%">
												<p>
														<a href="http://www.family168.com/tutorial/jsp/html/jsp-ch-13.html#co-jsp-ch-13-02-05">
																<span style="color: rgb(16, 138, 198);">(5)</span>
														</a>
												</p>
										</td>
										<td align="left" valign="top">
												<p>${cookie.name}将获得对应cookie的对象，比如我们用jsp将一段cookie发送给客户端。</p>
												<pre class="programlisting">Cookie cookie = <span class="hl-keyword">new</span> Cookie(<span class="hl-string">"username"</span>, <span class="hl-string">"Username in cookie"</span>);<br />response.addCookie(cookie);<br /></pre>
												<p>创建一个名称为username，值为"Username in cookie"的Cookie对象，然后发送给客户端。</p>
												<p>然后我们就可以使用${cookie.username}获得这个cookie了，${cookie.username.name}获得cookie名称，${cookie.username.value}获得cookie值。</p>
										</td>
								</tr>
								<tr>
										<td align="left" valign="top" width="5%">
												<p>
														<a href="http://www.family168.com/tutorial/jsp/html/jsp-ch-13.html#co-jsp-ch-13-02-06">
																<span style="color: rgb(16, 138, 198);">(6)</span>
														</a>
												</p>
										</td>
										<td align="left" valign="top">
												<p>ServletContext.getInitParamter()指的应用的初始变量，这些变量都是定义在web.xml中的。</p>
												<pre class="programlisting">&lt;<strong class="hl-tag" style="color: blue;">context-param</strong>&gt;<br />    &lt;<strong class="hl-tag" style="color: blue;">param-name</strong>&gt;username&lt;<strong class="hl-tag" style="color: blue;">/param-name</strong>&gt;<br />    &lt;<strong class="hl-tag" style="color: blue;">param-value</strong>&gt;username with context param&lt;<strong class="hl-tag" style="color: blue;">/param-value</strong>&gt;<br />&lt;<strong class="hl-tag" style="color: blue;">/context-param</strong>&gt;<br /></pre>
												<p>${initParam.username}就会得到这里的变量值。</p>
										</td>
								</tr>
						</tbody>
				</table>
		</div>
		<p>以上都是死记硬背的东西，建议实际用到的时候翻看一下就好了，演示代码都放在13-04下，为了获得param和cookie还要点击一下最下边的连接才可以。</p>
		<div class="titlepage" lang="zh-cn">
				<div>
						<div>
								<h2 class="title" style="clear: both;">
										<a name="jsp-ch-13-03">
										</a>运算符</h2>
						</div>
				</div>
		</div>
		<p class="sect1" lang="zh-cn">el表达式中支持java中所有的操作符，并且还有一些扩展，下面我们简要做一下对照。</p>
		<div class="table" lang="zh-cn">
				<a name="d4e1824">
				</a>
				<p class="title">
						<strong>表 13.2. 加减乘除四则运算</strong>
				</p>
				<div class="table-contents">
						<table summary="加减乘除四则运算" border="1">
								<colgroup span="1">
										<col span="1" />
										<col span="1" />
								</colgroup>
								<thead>
										<tr>
												<th align="center">符号</th>
												<th align="center">说明</th>
										</tr>
								</thead>
								<tbody>
										<tr>
												<td align="center">+</td>
												<td align="center">加</td>
										</tr>
										<tr>
												<td align="center">-</td>
												<td align="center">减</td>
										</tr>
										<tr>
												<td align="center">*</td>
												<td align="center">乘</td>
										</tr>
										<tr>
												<td align="center">/或div</td>
												<td align="center">除</td>
										</tr>
										<tr>
												<td align="center">%或mod</td>
												<td align="center">求余</td>
										</tr>
								</tbody>
						</table>
				</div>
		</div>
		<div class="sect1" lang="zh-cn">
				<br class="table-break" />
		</div>
		<div class="table" lang="zh-cn">
				<a name="d4e1849">
				</a>
				<p class="title">
						<strong>表 13.3. 比较运算</strong>
				</p>
				<div class="table-contents">
						<table summary="比较运算" border="1">
								<colgroup span="1">
										<col span="1" />
										<col span="1" />
								</colgroup>
								<thead>
										<tr>
												<th align="center">符号</th>
												<th align="center">说明</th>
										</tr>
								</thead>
								<tbody>
										<tr>
												<td align="center">==或eq</td>
												<td align="center">相等（equals）</td>
										</tr>
										<tr>
												<td align="center">!=或ne</td>
												<td align="center">不相等（not equals）</td>
										</tr>
										<tr>
												<td align="center">&lt;或lt</td>
												<td align="center">小于（less than）</td>
										</tr>
										<tr>
												<td align="center">&gt;或gt</td>
												<td align="center">大于（greater than）</td>
										</tr>
										<tr>
												<td align="center">&lt;=或le</td>
												<td align="center">小于等于（less than or equals）</td>
										</tr>
										<tr>
												<td align="center">&gt;=或ge</td>
												<td align="center">大于等于（greater than or equals）</td>
										</tr>
								</tbody>
						</table>
				</div>
		</div>
		<div class="sect1" lang="zh-cn">
				<br class="table-break" />
		</div>
		<div class="table" lang="zh-cn">
				<a name="d4e1877">
				</a>
				<p class="title">
						<strong>表 13.4. 逻辑运算</strong>
				</p>
				<div class="table-contents">
						<table summary="逻辑运算" border="1">
								<colgroup span="1">
										<col span="1" />
										<col span="1" />
								</colgroup>
								<thead>
										<tr>
												<th align="center">符号</th>
												<th align="center">说明</th>
										</tr>
								</thead>
								<tbody>
										<tr>
												<td align="center">&amp;&amp;或and</td>
												<td align="center">逻辑和</td>
										</tr>
										<tr>
												<td align="center">||或or</td>
												<td align="center">逻辑或</td>
										</tr>
										<tr>
												<td align="center">!或not</td>
												<td align="center">取反</td>
										</tr>
								</tbody>
						</table>
				</div>
		</div>
		<div class="sect1" lang="zh-cn">
				<br class="table-break" />
		</div>
		<div class="table" lang="zh-cn">
				<a name="d4e1896">
				</a>
				<p class="title">
						<strong>表 13.5. 特殊运算</strong>
				</p>
				<div class="table-contents">
						<table summary="特殊运算" border="1">
								<colgroup span="1">
										<col span="1" />
										<col span="1" />
								</colgroup>
								<thead>
										<tr>
												<th align="center">符号</th>
												<th align="center">说明</th>
										</tr>
								</thead>
								<tbody>
										<tr>
												<td align="center">empty</td>
												<td align="center">是否为null或空字符串</td>
										</tr>
										<tr>
												<td align="center">? :</td>
												<td align="center">三元运算符</td>
										</tr>
								</tbody>
						</table>
				</div>
		</div>
		<div class="sect1" lang="zh-cn">
				<br class="table-break" />
		</div>
		<p class="sect1" lang="zh-cn">下面上所有运算符的显示结果，顺便说一下如果想在jsp中显示${name}而不让jsp把它当作el计算出来，可以写成\${name}，这样最后显示的结果就是${name}了。</p>
		<img class="magplus" title="点击查看原始大小图片" src="http://www.family168.com/tutorial/jsp/shared/images/jsp-ch-13-03-operator-01.png" alt="" align="middle" height="338" width="700" />
<img src ="http://www.blogjava.net/kxbin/aggbug/297763.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2009-10-11 11:56 <a href="http://www.blogjava.net/kxbin/articles/297763.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>getAttribute和getParameter的区别 </title><link>http://www.blogjava.net/kxbin/articles/kxbin.html</link><dc:creator>kxbin</dc:creator><author>kxbin</author><pubDate>Sat, 10 Oct 2009 08:24:00 GMT</pubDate><guid>http://www.blogjava.net/kxbin/articles/kxbin.html</guid><wfw:comment>http://www.blogjava.net/kxbin/comments/297697.html</wfw:comment><comments>http://www.blogjava.net/kxbin/articles/kxbin.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kxbin/comments/commentRss/297697.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kxbin/services/trackbacks/297697.html</trackback:ping><description><![CDATA[2009年10月10日<br />
JSP中getParameter与getAttribute有何区别？<br />
<br />
——getParameter得到的都是String类型的。或者是http://a.jsp?id=123中的123，或者是某个表单提交过去的数据。<br />
——getAttribute则可以是对象。<br />
——getParameter()是获取POST/GET传递的参数值；<br />
——getAttribute()是获取对象容器中的数据值；<br />
——getParameter：用于客户端重定向时，即点击了链接或提交按扭时传值用，即用于在用表单或url重定向传值时接收数据用。<br />
——getAttribute：用于服务器端重定向时，即在sevlet中使用了forward函数,或struts中使用了mapping.findForward。getAttribute只能收到程序用setAttribute传过来的值。<br />
——getParameter()是获取POST/GET传递的参数值；<br />
——getAttribute()是获取SESSION的值；<br />
另外，可以用setAttribute,getAttribute发送接收对象.而getParameter显然只能传字符串。<br />
setAttribute 是应用服务器把这个对象放在该页面所对应的一块内存中去，当你的页面服务器重定向到另一个页面时，应用服务器会把这块内存拷贝另一个页面所对应的内存中。这样getAttribute就能取得你所设下的值，当然这种方法可以传对象。session也一样，只是对象在内存中的生命周期不一样而已。<br />
getParameter只是应用服务器在分析你送上来的request页面的文本时，取得你设在表单或url重定向时的值。<br />
<br />
getParameter&nbsp;&nbsp; 返回的是String,&nbsp;&nbsp; 用于读取提交的表单中的值;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br />
getAttribute&nbsp;&nbsp; 返回的是Object，需进行转换,可用setAttribute设置成任意对象，使用很灵活，可随时用；<br />
<br />
<img src ="http://www.blogjava.net/kxbin/aggbug/297697.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kxbin/" target="_blank">kxbin</a> 2009-10-10 16:24 <a href="http://www.blogjava.net/kxbin/articles/kxbin.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>