﻿<?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--随笔分类-struts</title><link>http://www.blogjava.net/jackstudio/category/12672.html</link><description /><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 03:39:29 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 03:39:29 GMT</pubDate><ttl>60</ttl><item><title>struts,ajax乱码解决方案 </title><link>http://www.blogjava.net/jackstudio/archive/2006/12/10/86629.html</link><dc:creator>jackstudio</dc:creator><author>jackstudio</author><pubDate>Sat, 09 Dec 2006 18:38:00 GMT</pubDate><guid>http://www.blogjava.net/jackstudio/archive/2006/12/10/86629.html</guid><wfw:comment>http://www.blogjava.net/jackstudio/comments/86629.html</wfw:comment><comments>http://www.blogjava.net/jackstudio/archive/2006/12/10/86629.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jackstudio/comments/commentRss/86629.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jackstudio/services/trackbacks/86629.html</trackback:ping><description><![CDATA[
		<p>
				<font size="2">转载：<a href="/errorfun/archive/2006/12/09/86584.html">http://www.blogjava.net/errorfun/archive/2006/12/09/86584.html</a><br />作者：errorfun<br /><br /><br />乱码问题好像跟我们中国程序员特别有缘，一直困扰着我们，从开始的<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">JSP</span><span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">乱码问题，</font></span><span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">STRUTS</span><span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">乱码问题，到现在的</font></span><span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">AJAX</span><span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">乱码问题，无一不是搞得许多程序员焦头烂额的，整天骂</font></span><span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">XXX</span><span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">产品对中文支持不了，UTF-8无法使用中文啊什么的，其实这里面被骂的产品中其实</font></span><span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">99</span><span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体">％以上是对中文支持非常好的，而出现乱码的原因只是因为自身对国际化支持以及文件编码等信息的认识不知造成的。要知道一个产品那么流行，怎么可能对中文支持不了呢，下面就开始一一帮大家解决这些问题。</font></span></font>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">
						<br />
						<br />1</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">、编码</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">
						<br />      －－</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">想要解决好中文问题，对编码肯定是不能一概不懂了，编码是解决中文乱码问题的根本。</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">
						<br />      </span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">编码比较常用的有：</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">UTF-8</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">，</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">GBK</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">，</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">GB2312</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">，</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">ISO-8859-1</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">，除了</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">iso-8859-1</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">之外的其它三个编码都能很好的支持中文，但它们都兼容</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">ISO-8859-1</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">的编码（就是说无论编码怎么改变，只要是</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">ISO-8859-1</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">中的字符，永远不会出现乱码）。</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">
						<br />      </span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">这四种编码中，</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">GB2312</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">是中国规定的汉字编码，也可以说是简体中文的字符集编码</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">;</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">GBK </span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">是</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">GB2312</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">的扩展</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">,</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">除了兼容</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">GB2312</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">外，它还能显示繁体中文，还有日文的假名</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">;</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">而</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">UTF-8</span>
				<font face="宋体">
						<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">虽然也支持中文，但却</span>
						<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">与</span>
				</font>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">GB</span>
				<font face="宋体">
						<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">码不兼容（编码值不同）</span>
						<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">。</span>
				</font>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">UTF-8</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">使用的是可变长的</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">UNICODE</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">编码，编码可能是</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">1</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">位</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">16</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">进制（即</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">ISO-8859-1</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">中的字符，其编码也是相同的）也有可能是</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">2</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">位或</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">3</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">位的</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">16</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana">
						<font face="宋体">进制。</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">UTF-8</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">的优点是：</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">1</span>
				<font face="宋体">
						<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: 'Times New Roman'; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">、</span>
						<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">与</span>
				</font>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">CPU</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">字节顺序无关</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">, </span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">可以在不同平台之间交流。</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">2</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">、容错能力高</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">, </span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">任何一个字节损坏后</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">, </span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">最多只会导致一个编码码位损失</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">, </span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">不会链锁错误</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">(</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">如</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">GB</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">码错一个字节就会整行乱码</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">)</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">，所以在国际化处理中基本都是建议使用</font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">UTF-8</span>
				<span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana; mso-font-kerning: 1.0pt; mso-bidi-font-family: 'Times New Roman'">
						<font face="宋体">作为编码。<br /></font>
				</span>
				<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana">
						<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /?>
						<o:p>
								<br />2、文件的编码<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"><br />      －－虽然说只要设置了正确的编码就可以使字符正确显示了，但如果忽略了文件保存时的编码的话，那可是会让你走进迷雾中的。<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"><br />      文件编码最常使用的有两种：ANSI和UTF-8，光看名字估计你都可以猜到了，ANSI就是我们保存文件时使用的默认编码，而UTF-8则需自己设置。对于编码的改变，我使用的工具是NOTEPAD和ECLIPSE，NOTEPAD使用最简单，只要打开文件后在另存为中选择相应的编码就行了，而且它对编码的支持非常好;而在ECLIPSE中，只要稍微设置一下就行了，打开首选项，然后选择：常规-&gt;内容类型(ContentType)，在右边选中你想改变保存编码的文件类型，然后在下方的缺省编码中改变其值，最后点击更新（UPDATE）按钮即可。<br /></span></span></o:p>
				</span>
		</p>
		<p align="center">
				<img src="http://errorfun.bokee.com/inc/eclipse.png" />
		</p>
		<p align="left">
				<br />
				<br />而在其它的编辑器中，默认保存的内容都是GB2312或者GBK（NOTEPAD中对应ANSI）.而根据前面所说的UTF-8和GBK,GB2312等的编码值是不同的这一点，可以知道，如果文件使用了UTF-8，那么字符编码就必须使用UTF-8，否则编码值的不同就可能造成乱码。而这也就是为什么那么多的人使用了UTF-8编码后还会产生乱码的根本原因。（JS和JSP都是这个道理）<br /><br />3、JSP,STRUTS等的中文乱码解决方案<span lang="EN-US" style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"><br />     其实解决的方法只有一个：</span><span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体"></font></span></p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000"> request.setCharacterEncoding(encoding);</span>
		</div>
		<p align="left">   方法只有一种，但处理方式就多种多样了，初学者会在JSP页面上直接使用，而有经验的程序员会使用过滤器。而现在所要说的方法也是过滤器。这里以统一使用UTF-8作为编码作为例子说明。具体过程就不多说了，网上有很多教程。偷懒一点的，到TOMCAT中复制就行了。在TOMCAT的目录下的\webapps\jsp-examples\WEB-INF\classes\filters\找到SetCharacterEncodingFilter.java 这个类，放到你的程序中并配置好映射路径。配置好后基本上你的乱码问题就解决了。但要映射路径中需要注意的就是不能使用 '*'</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">filter-mapping</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">filter-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">Set Character Encoding</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">filter-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">servlet-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">*</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />  </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">filter-mapping</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>
		<p align="left">像上面这样配置的话(可能也是网上大多教程的做法，想当年也是害苦了我)，可能你只有JSP的乱码解决了，要解决STRUTS的乱码需要映射 *.do 或者 servletActionName。然后在初始化参数中设置encoding的值就行了。</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">init-param</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />      </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">param-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">encoding</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">param-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />      </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">param-value</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">UTF-8</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">param-value</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">init-param</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>
		<p align="left">当然，最重要的是要记得根据前面所说的方法，改变你所使用的编辑器保存文件的编码要与使用的字符编码一致。<br />而在JSP内容中，还是使用如网上教程所说的那种技俩，在所有页面的页首加入：</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #808080">&lt;%</span>
				<span style="COLOR: #000000">@ page language</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">"java" contentType</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">"</span>
				<span style="FONT-WEIGHT: bold; COLOR: #000000">text</span>
				<span style="COLOR: #808080">/</span>
				<span style="COLOR: #000000">html; charset</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">UTF</span>
				<span style="COLOR: #808080">-</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">8</span>
				<span style="COLOR: #000000">"<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    pageEncoding</span>
				<span style="COLOR: #808080">=</span>
				<span style="COLOR: #000000">"UTF</span>
				<span style="COLOR: #808080">-</span>
				<span style="FONT-WEIGHT: bold; COLOR: #800000">8</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #808080">%&gt;</span>
		</div>
		<br />至此，相信JSP,ACTION都不太可能出现乱码了。<br /><br />4、资源文件的乱码解决方案<br />      资源文件谁都知道是国际化支持不可或缺的一部分，如果资源文件都出现乱码了那还了得？其实资源文件的乱码是很好解决的，其原因也是因为使用了UTF-8做为JSP编码后，没有相应地改变资源文件的文件编码造成的，所以只要对资源文件保存的编码进行更正后，乱码问题也就解决了。当然，你的中文要使用 native2ascii 命令进行正确的转换。<br /><br />5、调用JS时，JS内容乱码的解决方案。<br />     其实JS的乱码还是跟文件的编码有关系的，如果JS中有中文的话，那JS文件保存的编码就必须跟调用此JS的页面编码相同，否则，你的所有中文都要从JSP页面传给JS才会显示正常。可以看出对于调用JS出现的乱码是最容易解决的（也是建立在前面的辛苦之下的）。<br /><br />6、AJAX提交数据乱码，返回数据乱码的解决方案<br />     随着AJAX的流行，乱码问题也开始困扰着许多刚开始使用它的程序员，幸好我之前对JSP乱码有过一点研究，在遇到AJAX后，并没有给我带来多大的困扰，在此将我的一些心得共享给大家。<br />     万变不离其宗，AJAX的乱码问题自然跟编码有关了，其实很多人跟我一样想到了对文件编码进行设置，并且在接数据时设置了requet的编码，在返回的数据时设置了response的编码一切都以为会很顺利，可是这一切都是徒劳无功的，讨厌的乱码再一次出现在你眼前。在你试了N多种方法，包括JS自身的escape,unescape方法后，你发现乱码仍然猖狂地出现在屏幕上。<br />    其实在试过这N多方法后，很多人都没发现，解决的方法其实很简单，而且其答案就在我们之前处理的JSP乱码之中。让我们先看一下AJAX的经典请求代码<br /><span style="FONT-SIZE: 10pt; mso-ascii-font-family: Verdana; mso-hansi-font-family: Verdana"><font face="宋体"><p></p><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font size="2"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">xmlhttp.open( </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">post</span><span style="COLOR: #000000">"</span></font><font size="2"><span style="COLOR: #000000">, url, async );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />xmlhttp.setRequestHeader( </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Content-Type</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">text/html</span><span style="COLOR: #000000">"</span></font><span style="COLOR: #000000"><font size="2"> );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />xmlhttp.send( params );</font></span></div><br />通过前面的说明，不知道你现在看出端倪了没有。不知道是受了网上教程的影响还是其它方面影响，setRequestHeader并是万年不变的，也没人想过去改它，而问题就正好出在这个地方。回想一个JSP页面内容的编码设置，其中有这么一节： 
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font size="2"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">contentType</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">text/html; charset=UTF-8</span><span style="COLOR: #000000">"</span></font></div><br />现在知道问题了吧，所以我们要把第二句代码改为： 
<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font size="2"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">xmlhttp.setRequestHeader( </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Content-Type</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">text/html;charset=UTF-8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> );<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span></font></div></font></span><font size="2"><br /><font face="宋体">最后别忘了在返回数据时也设置上： </font><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><font face="宋体"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></font><span style="COLOR: #000000">response.setContentType( </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">text/xml</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />response.setCharacterEncoding( </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> );</span></div><br />是不是很简单，一点都不麻烦呢？<br />如果要问为什么的话，其实我们可以把xmlhttp看成是一个临时页面，它由浏览器动态生成，主要作用是在后台获得请求的数据（可以看成是一个高级的iframe）。所以对于普通页面设置的编码，对它也要同样设置。而在servlet中返回数据为什么要设置contentType和encoding其道理也是一样的。众所周知，jsp的最后形态就是servlet，而jsp页首设置的那个内容其实也就是让生成的servlet中生成这么两句话：<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">response.setContentType( </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">text/html</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> );<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />response.setCharacterEncoding( </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> );</span></div><br />而pageEncoding则是跟jvm说明了这个页面的内容要使用什么编码保存（这跟之后生成的CLASS有关系）。所以在servlet设置response的编码也是理所当然的了。<br /><br />一口气把自己一年以来遇到的乱码问题和解决的方案写出来了，希望对你有所帮助。</font><img src ="http://www.blogjava.net/jackstudio/aggbug/86629.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jackstudio/" target="_blank">jackstudio</a> 2006-12-10 02:38 <a href="http://www.blogjava.net/jackstudio/archive/2006/12/10/86629.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>spring有三种启动方式,使用ContextLoaderServlet,ContextLoaderListener和ContextLoaderPlugIn.</title><link>http://www.blogjava.net/jackstudio/archive/2006/11/09/80060.html</link><dc:creator>jackstudio</dc:creator><author>jackstudio</author><pubDate>Thu, 09 Nov 2006 02:40:00 GMT</pubDate><guid>http://www.blogjava.net/jackstudio/archive/2006/11/09/80060.html</guid><wfw:comment>http://www.blogjava.net/jackstudio/comments/80060.html</wfw:comment><comments>http://www.blogjava.net/jackstudio/archive/2006/11/09/80060.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jackstudio/comments/commentRss/80060.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jackstudio/services/trackbacks/80060.html</trackback:ping><description><![CDATA[
		<p>spring有三种启动方式,使用ContextLoaderServlet,ContextLoaderListener和ContextLoaderPlugIn.<br />看一下ContextLoaderListener的源码,这是一个ServletContextListener<br />/**<br />  * Initialize the root web application context.<br />  */<br /> public void contextInitialized(ServletContextEvent event) {<br />  this.contextLoader = createContextLoader();<br />  this.contextLoader.initWebApplicationContext(event.getServletContext());<br /> }<br /> <br />  /**<br />  * Create the ContextLoader to use. Can be overridden in subclasses.<br />  * @return the new ContextLoader<br />  */<br /> protected ContextLoader createContextLoader() {<br />  return new ContextLoader();<br /> }</p>
		<p> contextLoader的源码<br /> public WebApplicationContext initWebApplicationContext(ServletContext servletContext)<br />   throws BeansException {</p>
		<p>  long startTime = System.currentTimeMillis();<br />  if (logger.isInfoEnabled()) {<br />   logger.info("Root WebApplicationContext: initialization started");<br />  }<br />  servletContext.log("Loading Spring root WebApplicationContext");</p>
		<p>  try {<br />   // Determine parent for root web application context, if any.<br />   ApplicationContext parent = loadParentContext(servletContext);</p>
		<p>   WebApplicationContext wac = createWebApplicationContext(servletContext, parent);<br />   servletContext.setAttribute(<br />     WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);</p>
		<p>   if (logger.isInfoEnabled()) {<br />    logger.info("Using context class [" + wac.getClass().getName() +<br />      "] for root WebApplicationContext");<br />   }<br />   if (logger.isDebugEnabled()) {<br />    logger.debug("Published root WebApplicationContext [" + wac +<br />      "] as ServletContext attribute with name [" +<br />      WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE + "]");<br />   }</p>
		<p>   if (logger.isInfoEnabled()) {<br />    long elapsedTime = System.currentTimeMillis() - startTime;<br />    logger.info("Root WebApplicationContext: initialization completed in " + elapsedTime + " ms");<br />   }</p>
		<p>   return wac;<br />  }<br />  catch (RuntimeException ex) {<br />   logger.error("Context initialization failed", ex);<br />   servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, ex);<br />   throw ex;<br />  }<br />  catch (Error err) {<br />   logger.error("Context initialization failed", err);<br />   servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, err);<br />   throw err;<br />  }<br /> }<br /> 注意WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,这里面放了WebApplicationContext,需要使用时从ServletContext取出<br /> 可以使用WebApplicationContextUtils得到WebApplicationContext<br /> public static WebApplicationContext getWebApplicationContext(ServletContext sc) {<br />  Object attr = sc.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);<br />  if (attr == null) {<br />   return null;<br />  }<br />  if (attr instanceof RuntimeException) {<br />   throw (RuntimeException) attr;<br />  }<br />  if (attr instanceof Error) {<br />   throw (Error) attr;<br />  }<br />  if (!(attr instanceof WebApplicationContext)) {<br />   throw new IllegalStateException("Root context attribute is not of type WebApplicationContext: " + attr);<br />  }<br />  return (WebApplicationContext) attr;<br /> }<br /> 关键的问题在于struts如何启动的spring的,ContextLoaderPlugIn的源码<br /> <br /> // Publish the context as a servlet context attribute.<br />  String attrName = getServletContextAttributeName();<br />  getServletContext().setAttribute(attrName, wac);<br /> <br /> public String getServletContextAttributeName() {<br />  return SERVLET_CONTEXT_PREFIX + getModulePrefix();<br /> }<br /> 不同加载的Key竟然不同,原因就是WebApplicationContext放在那里的问题,可spring调用的时候会根据WebApplicationContext里面定义的那个名字去找的,问题出在这里</p>
		<p>
				<br /> 在struts-config.xml中配置<br />    &lt;plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"&gt;<br />      &lt;set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" /&gt;<br />    &lt;/plug-in&gt;</p>
		<p>    &lt;controller&gt;<br />        &lt;set-property property="processorClass" value="org.springframework.web.struts.DelegatingRequestProcessor" /&gt;<br />    &lt;/controller&gt;</p>
		<p>
				<br /> 原理是这样的,Struts虽然只能有一个ActionServlet实例,但是对于不同的子应用分别能有自己的RequestProcessor实例每个RequestProcessor实例分别对应不同的struts配置文件。<br />   子应用的ProcessorClass类必须重写一般就是继承RequestProcessor类，然后再其配置文件的controller元素中的&lt;processorClass&gt;属性中作出修改。那么当<br />  getRequestProcessor(getModuleConfig(request)).process(request,response);就能根据request选择相应的moduleconfig,再根据其&lt;processorClass&gt;属性选择相应的RequestProcessor子类来处理相应的请求了。</p>
		<p> </p>
<img src ="http://www.blogjava.net/jackstudio/aggbug/80060.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jackstudio/" target="_blank">jackstudio</a> 2006-11-09 10:40 <a href="http://www.blogjava.net/jackstudio/archive/2006/11/09/80060.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用ServletContextListener在服务器启动和关闭时创建和关闭缓存</title><link>http://www.blogjava.net/jackstudio/archive/2006/11/09/80058.html</link><dc:creator>jackstudio</dc:creator><author>jackstudio</author><pubDate>Thu, 09 Nov 2006 02:39:00 GMT</pubDate><guid>http://www.blogjava.net/jackstudio/archive/2006/11/09/80058.html</guid><wfw:comment>http://www.blogjava.net/jackstudio/comments/80058.html</wfw:comment><comments>http://www.blogjava.net/jackstudio/archive/2006/11/09/80058.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jackstudio/comments/commentRss/80058.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jackstudio/services/trackbacks/80058.html</trackback:ping><description><![CDATA[
		<div class="con_sample">
				<p>ServletContext 被 Servlet 程序用来与 Web 容器通信。例如写日志，转发请求。每一个 Web 应用程序含有一个Context，被Web应用内的各个程序共享。因为Context可以用来保存资源并且共享，所以我所知道的 ServletContext 的最大应用是Web缓存----把不经常更改的内容读入内存，所以服务器响应请求的时候就不需要进行慢速的磁盘I/O了。</p>
		</div>
		<div class="con_all">
				<p>
				</p>
				<p>ServletContext 被 Servlet 程序用来与 Web 容器通信。例如写日志，转发请求。每一个 Web 应用程序含有一个Context，被Web应用内的各个程序共享。因为Context可以用来保存资源并且共享，所以我所知道的 ServletContext 的最大应用是Web缓存----把不经常更改的内容读入内存，所以服务器响应请求的时候就不需要进行慢速的磁盘I/O了。 </p>
				<p>ServletContextListener 是 ServletContext 的监听者，如果 ServletContext 发生变化，如服务器启动时 ServletContext 被创建，服务器关闭时 ServletContext 将要被销毁。 </p>
				<p>在JSP文件中，application 是 ServletContext 的实例，由JSP容器默认创建。Servlet 中调用 getServletContext()方法得到 ServletContext 的实例。 </p>
				<p>我们使用缓存的思路大概是： </p>
				<ol>
						<li>
								<p>服务器启动时，ServletContextListener 的 contextInitialized()方法被调用，所以在里面创建好缓存。可以从文件中或者从数据库中读取取缓存内容生成类，用 ervletContext.setAttribute()方法将缓存类保存在 ServletContext 的实例中。 </p>
						</li>
						<li>
								<p>程序使用 ServletContext.getAttribute()读取缓存。如果是 JSP，使用a pplication.getAttribute()。如果是 Servlet，使用 getServletContext().getAttribute()。如果缓存发生变化(如访问计数)，你可以同时更改缓存和文件/数据库。或者你等 变化积累到一定程序再保存，也可以在下一步保存。 </p>
						</li>
						<li>
								<p>服务器将要关闭时，ServletContextListener 的 contextDestroyed()方法被调用，所以在里面保存缓存的更改。将更改后的缓存保存回文件或者数据库，更新原来的内容。 </p>
						</li>
				</ol>
				<pre>import User; //my own class<br />import DatabaseManager; // my own class<br />import javax.servlet.ServletContext;<br />import javax.servlet.ServletContextListener;<br /><br />public class MyContextListener<br /><br />	implements ServletContextListener {<br />	private ServletContext context = null;<br /><br />	public void contextInitialized(ServletContextEvent event) {<br />		context = event.getServletContext();<br />		User user = DatabaseManager.getUserById(1);<br />		context.setAttribute("user1", user);<br />	}<br /><br />	public void contextDestroyed(ServletContextEvent event) {<br />		User user = (User)context.getAttribute("user1");<br />		DatabaseManager.updateUserData(user);<br />		this.context = null;<br />	}<br />}<br /></pre>
				<h3 class="para">布署 ServletContextListener</h3>
				<p>你实现(implements)了 ServletContextListener 编译后，把它放在正确的WEB-INF/classes目录下，更改WEB-INF目录下的 web.xml文件，在web-app节点里添加 </p>
				<pre>&lt;listener&gt;<br />	&lt;listener-class&gt;MyServletContextListener&lt;/listener-class&gt;<br />&lt;/listener&gt;<br /></pre> 来自：<a href="http://www.ideawu.net/ideablog/">idea's blog</a></div>
<img src ="http://www.blogjava.net/jackstudio/aggbug/80058.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jackstudio/" target="_blank">jackstudio</a> 2006-11-09 10:39 <a href="http://www.blogjava.net/jackstudio/archive/2006/11/09/80058.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于Spring , Struts结合学习</title><link>http://www.blogjava.net/jackstudio/archive/2006/09/21/71106.html</link><dc:creator>jackstudio</dc:creator><author>jackstudio</author><pubDate>Thu, 21 Sep 2006 07:04:00 GMT</pubDate><guid>http://www.blogjava.net/jackstudio/archive/2006/09/21/71106.html</guid><wfw:comment>http://www.blogjava.net/jackstudio/comments/71106.html</wfw:comment><comments>http://www.blogjava.net/jackstudio/archive/2006/09/21/71106.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jackstudio/comments/commentRss/71106.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jackstudio/services/trackbacks/71106.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 关于Spring , Struts结合学习。		一、前言		刚刚接触了日本一个项目，用的框架名称是Northland Framework，主要用到以下部分		Struts、Spring、iBATIS、Velocity。Struts、Spring如何结合在一起？						二、				Spring				提供了三种整合				Struts				的方法：		...&nbsp;&nbsp;<a href='http://www.blogjava.net/jackstudio/archive/2006/09/21/71106.html'>阅读全文</a><img src ="http://www.blogjava.net/jackstudio/aggbug/71106.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jackstudio/" target="_blank">jackstudio</a> 2006-09-21 15:04 <a href="http://www.blogjava.net/jackstudio/archive/2006/09/21/71106.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>