﻿<?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-Rory's Blog-随笔分类-Other</title><link>http://www.blogjava.net/rory/category/8718.html</link><description>Happy study,Happy work,Happy life</description><language>zh-cn</language><lastBuildDate>Wed, 28 Feb 2007 07:42:26 GMT</lastBuildDate><pubDate>Wed, 28 Feb 2007 07:42:26 GMT</pubDate><ttl>60</ttl><item><title>xstream对xmlnode的属性(attribute)解析的问题[更新]。</title><link>http://www.blogjava.net/rory/archive/2007/01/17/howto-dealwith-xstream-xmlnode-attribute.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Wed, 17 Jan 2007 10:24:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2007/01/17/howto-dealwith-xstream-xmlnode-attribute.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/94475.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2007/01/17/howto-dealwith-xstream-xmlnode-attribute.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/94475.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/94475.html</trackback:ping><description><![CDATA[xstream是个好东西。对于配置文件的读取很方便。在mybog中我就用到了。不过今天打算用yupoo的api来做相册。发现xstream对于xmlnode的attribute解析支持不是那么的好。<br />对于这种节点格式的非常的简单<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">page</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">page</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">pages</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">pages</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">perpage</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">100</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">perpage</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">total</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">19</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">total</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">photos</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">photo</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">ff8080810fc8ac78010fd3f158d40a52</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">owner</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">ff8080810f1a387b010f1a83d6530dfc</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">owner</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">Gmail-2</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">host</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">host</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">20061230</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">filename</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">231905_1463411198</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">filename</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">photo</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">photos</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><br />简单的alias一下就可以读到值了<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 0);">File file </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> File(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">src/test/java/com/jdkcn/test/result.xml</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />BufferedReader reader </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> BufferedReader(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> InputStreamReader(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> FileInputStream(file), </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF-8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />XStream stream </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XStream();<br />stream.alias(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">result</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, YupooResult.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />stream.alias(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">photo</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">,YupooPhoto.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />YupooResult result </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (YupooResult)stream.fromXML(reader);</span></div>可是Yupoo的api返回的xmlrpc的结果是这样的<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">result </span><span style="color: rgb(255, 0, 0);">page</span><span style="color: rgb(0, 0, 255);">="1"</span><span style="color: rgb(255, 0, 0);"> pages</span><span style="color: rgb(0, 0, 255);">="1"</span><span style="color: rgb(255, 0, 0);"> perpage</span><span style="color: rgb(0, 0, 255);">="100"</span><span style="color: rgb(255, 0, 0);"> total</span><span style="color: rgb(0, 0, 255);">="19"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">photos</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">photo </span><span style="color: rgb(255, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">="ff8080810fc8ac78010fd3f158d40a52"</span><span style="color: rgb(255, 0, 0);"><br />            owner</span><span style="color: rgb(0, 0, 255);">="ff8080810f1a387b010f1a83d6530dfc"</span><span style="color: rgb(255, 0, 0);"> title</span><span style="color: rgb(0, 0, 255);">="Gmail-2"</span><span style="color: rgb(255, 0, 0);"> host</span><span style="color: rgb(0, 0, 255);">="4"</span><span style="color: rgb(255, 0, 0);"><br />            dir</span><span style="color: rgb(0, 0, 255);">="20061230"</span><span style="color: rgb(255, 0, 0);"> filename</span><span style="color: rgb(0, 0, 255);">="231905_1463411198"</span><span style="color: rgb(255, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">/&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">photos</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">&gt;</span></div>这样就load不到值了。没法去mailist里面找答案，果然有人问。<br /><pre><font color="#ff9900">Hello,

I am not sure about the subject but here is what I needed help for:

XML:

&lt;field name="value"&gt;I am a Field.&lt;/field&gt;

I have already tried several structures and nothing seem to work.

Is this possible for XStream? :)

How is the Java class form to support this?

Thanks!</font><br /><br /><br /><br /><br />有人回答是看Converter的文档。果然找到答案了。<br />自己写一个converter就可以了。<br />下面是我的converter<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> com.jdkcn.xstream;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.ArrayList;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> java.util.List;<br /><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.jdkcn.yupoo.YupooPhoto;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.jdkcn.yupoo.YupooResult;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.thoughtworks.xstream.converters.Converter;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.thoughtworks.xstream.converters.MarshallingContext;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.thoughtworks.xstream.converters.UnmarshallingContext;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.thoughtworks.xstream.io.HierarchicalStreamReader;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> com.thoughtworks.xstream.io.HierarchicalStreamWriter;<br /><br /></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /> * </span><span style="color: rgb(128, 128, 128);">@author</span><span style="color: rgb(0, 128, 0);"> &lt;a href="mailto:rory.cn@gmail.com"&gt;somebody&lt;/a&gt;<br /> * </span><span style="color: rgb(128, 128, 128);">@since</span><span style="color: rgb(0, 128, 0);"> Jan 16, 2007 6:12:35 PM<br /> * </span><span style="color: rgb(128, 128, 128);">@version</span><span style="color: rgb(0, 128, 0);"> $Id YupooResultConverter.java$<br /> </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);"> YupooResultConverter </span><span style="color: rgb(0, 0, 255);">implements</span><span style="color: rgb(0, 0, 0);"> Converter {<br />    </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> (non-Javadoc)<br />     * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object, com.thoughtworks.xstream.io.HierarchicalStreamWriter, com.thoughtworks.xstream.converters.MarshallingContext)<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);"> marshal(Object obj, HierarchicalStreamWriter writer, MarshallingContext context) {<br />        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> FIXME unfinish.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">    }<br /><br />    </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> (non-Javadoc)<br />     * @see com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader, com.thoughtworks.xstream.converters.UnmarshallingContext)<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {<br />        YupooResult result </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> YupooResult();<br />        result.setPage(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Integer(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">page</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)));<br />        result.setPages(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Integer(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">pages</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)));<br />        result.setPerpage(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Integer(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">perpage</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)));<br />        result.setTotal(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> Integer(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">total</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">)));<br />        reader.moveDown();<br />        List</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">YupooPhoto</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);"> photos </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> ArrayList</span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);">YupooPhoto</span><span style="color: rgb(0, 0, 0);">&gt;</span><span style="color: rgb(0, 0, 0);">();<br />        </span><span style="color: rgb(0, 0, 255);">while</span><span style="color: rgb(0, 0, 0);">(reader.hasMoreChildren()) {<br />            reader.moveDown();<br />            YupooPhoto photo </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> YupooPhoto();<br />            photo.setDir(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">dir</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />            photo.setFilename(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">filename</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />            photo.setHost(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">host</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />            photo.setId(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">id</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />            photo.setOwner(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">owner</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />            photo.setTitle(reader.getAttribute(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />            photos.add(photo);<br />            reader.moveUp();<br />        }<br />        result.setPhotos(photos);<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> result;<br />    }<br />    </span><span style="color: rgb(0, 128, 0);">/*</span><span style="color: rgb(0, 128, 0);"> (non-Javadoc)<br />     * @see com.thoughtworks.xstream.converters.ConverterMatcher#canConvert(java.lang.Class)<br />     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">boolean</span><span style="color: rgb(0, 0, 0);"> canConvert(Class clazz) {<br />        </span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);"> clazz.equals(YupooResult.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />    }<br />}<br /></span></div><br />然后调用的地方修改一下就ok了。<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 0);">XStream stream </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> XStream();<br />stream.registerConverter(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> YupooResultConverter());<br />stream.alias(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">result</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, YupooResult.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);</span></div><br /><br /><br />参考:<br /><a href="http://xstream.codehaus.org/converter-tutorial.html">http://xstream.codehaus.org/converter-tutorial.html</a></pre><br />2007年1月18日更新。<br />这里感谢网友 <a id="AjaxHolder_Comments_CommentList_ctl00_NameLink" href="http://fireshort.blogbus.com/" target="_blank">Ivan Chen（西滨）</a> 的提示。原来新版的xstream可以简单的解决了。在1.2.1的doc里面找到了这个两个方法。<br /><h3>useAttributeFor</h3><pre>public void <b>useAttributeFor</b>(java.lang.String fieldName,
                            java.lang.Class type)</pre><dl><dd>Use an XML attribute for a field or a specific type. 
<p></p></dd><dd><dl><dt><b>Parameters:</b></dt><dd><code>fieldName</code> - the name of the field
</dd><dd><code>type</code> - the Class of the type to be rendered as XML attribute 
</dd><dt><b>Throws:</b></dt><dd><code><a title="class in com.thoughtworks.xstream" href="http://xstream.codehaus.org/javadoc/com/thoughtworks/xstream/XStream.InitializationException.html">XStream.InitializationException</a></code> - if no <a title="class in com.thoughtworks.xstream.mapper" href="http://xstream.codehaus.org/javadoc/com/thoughtworks/xstream/mapper/AttributeMapper.html"><code>AttributeMapper</code></a> is available
</dd><dt><b>Since:</b></dt><dd>1.2</dd></dl></dd></dl><hr /><a name="useAttributeFor(java.lang.Class)"><!-- --></a><h3>useAttributeFor</h3><pre>public void <b>useAttributeFor</b>(java.lang.Class type)</pre><dl><dd>Use an XML attribute for an arbotrary type. 
<p></p></dd><dd><dl><dt><b>Parameters:</b></dt><dd><code>type</code> - the Class of the type to be rendered as XML attribute 
</dd><dt><b>Throws:</b></dt><dd><code><a title="class in com.thoughtworks.xstream" href="http://xstream.codehaus.org/javadoc/com/thoughtworks/xstream/XStream.InitializationException.html">XStream.InitializationException</a></code> - if no <a title="class in com.thoughtworks.xstream.mapper" href="http://xstream.codehaus.org/javadoc/com/thoughtworks/xstream/mapper/AttributeMapper.html"><code>AttributeMapper</code></a> is available
</dd><dt><b>Since:</b></dt><dd>1.2</dd></dl></dd></dl><br />这两个方法都是从1.2开始支持的。<br />也不用自己写converter了。这样就可以了<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; font-size: 13px; width: 98%; background-color: rgb(238, 238, 238);"><span style="color: rgb(0, 0, 0);">        stream.alias(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">result</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, YupooResult.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">page</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, Integer.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">pages</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, Integer.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">perpage</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, Integer.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">total</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, Integer.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.alias(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">photo</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, YupooPhoto.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">id</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, String.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">owner</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, String.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">title</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, String.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">host</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, String.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">dir</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, String.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br />        stream.useAttributeFor(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">filename</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, String.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);</span></div><a href="http://www.creativecommons.cn/licenses/by-nc-sa/1.0/" target="_blank"><br /><img alt="创造共用协议:署名,非商业,保持一致" src="http://leaf.jdk.cn/rights.gif" border="0" height="31" width="88" /></a>   除经特别注明外,本文章版权归<strong><a class="" href="http://jdkcn.com/"><font color="#6b6b52">莫多泡泡</font></a></strong>所有. <br /><font color="#ff0000">署名,非商业用途,保持一致.</font>   <a title="莫多泡泡" href="http://jdkcn.com/" target="_blank">somebody(莫多)</a><img src ="http://www.blogjava.net/rory/aggbug/94475.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rory/" target="_blank">莫多</a> 2007-01-17 18:24 <a href="http://www.blogjava.net/rory/archive/2007/01/17/howto-dealwith-xstream-xmlnode-attribute.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>又是乱码问题-Filter 配置也很重要</title><link>http://www.blogjava.net/rory/archive/2006/12/27/character_encoding_problem_filtermapping_position.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Wed, 27 Dec 2006 02:37:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/12/27/character_encoding_problem_filtermapping_position.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/90236.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/12/27/character_encoding_problem_filtermapping_position.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/90236.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/90236.html</trackback:ping><description><![CDATA[<p>  上周更新了一下myblog,添加了一个Filter，做统计访问用。可是后来发现出现乱码问题了。找了很久都没有找到问题。debug的时候看到 CharacterEncodingFilter确实是执行了。不过就是没有效果。执行之前是ISO-8859-1编码的，执行之后还是， CharacterEncodingFilter就没有起到作用。后来终于找到问题的原因了。原来是Filter配置先后顺序的原因。<br />       刚开始的配置是这样的:<br /></p>
		<div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)">
				<span style="COLOR: rgb(0,0,0)">    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">requestCounterFilter</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">*.jhtml</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
				</span>
				<span style="COLOR: rgb(0,0,255)">
						<span style="COLOR: rgb(0,0,0)">
								<br />   <br />    </span>
						<span style="COLOR: rgb(0,0,255)">&lt;</span>
						<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />        </span>
						<span style="COLOR: rgb(0,0,255)">&lt;</span>
						<span style="COLOR: rgb(128,0,0)">filter-name</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">encodingFilter</span>
						<span style="COLOR: rgb(0,0,255)">&lt;/</span>
						<span style="COLOR: rgb(128,0,0)">filter-name</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />        </span>
						<span style="COLOR: rgb(0,0,255)">&lt;</span>
						<span style="COLOR: rgb(128,0,0)">url-pattern</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">/dwr/*</span>
						<span style="COLOR: rgb(0,0,255)">&lt;/</span>
						<span style="COLOR: rgb(128,0,0)">url-pattern</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />    </span>
						<span style="COLOR: rgb(0,0,255)">&lt;/</span>
						<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />    <br />    </span>
						<span style="COLOR: rgb(0,0,255)">&lt;</span>
						<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />        </span>
						<span style="COLOR: rgb(0,0,255)">&lt;</span>
						<span style="COLOR: rgb(128,0,0)">filter-name</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">encodingFilter</span>
						<span style="COLOR: rgb(0,0,255)">&lt;/</span>
						<span style="COLOR: rgb(128,0,0)">filter-name</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />        </span>
						<span style="COLOR: rgb(0,0,255)">&lt;</span>
						<span style="COLOR: rgb(128,0,0)">url-pattern</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">*.jhtml</span>
						<span style="COLOR: rgb(0,0,255)">&lt;/</span>
						<span style="COLOR: rgb(128,0,0)">url-pattern</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />    </span>
						<span style="COLOR: rgb(0,0,255)">&lt;/</span>
						<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />    <br />    </span>
						<span style="COLOR: rgb(0,0,255)">&lt;</span>
						<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />        </span>
						<span style="COLOR: rgb(0,0,255)">&lt;</span>
						<span style="COLOR: rgb(128,0,0)">filter-name</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">encodingFilter</span>
						<span style="COLOR: rgb(0,0,255)">&lt;/</span>
						<span style="COLOR: rgb(128,0,0)">filter-name</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />        </span>
						<span style="COLOR: rgb(0,0,255)">&lt;</span>
						<span style="COLOR: rgb(128,0,0)">url-pattern</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">*.jsp</span>
						<span style="COLOR: rgb(0,0,255)">&lt;/</span>
						<span style="COLOR: rgb(128,0,0)">url-pattern</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
						<span style="COLOR: rgb(0,0,0)">
								<br />    </span>
						<span style="COLOR: rgb(0,0,255)">&lt;/</span>
						<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
						<span style="COLOR: rgb(0,0,255)">&gt;</span>
				</span>
		</div>
		<p>  先经过那个统计的filter然后再经过编码的filter。这样的话编码的filter就不起作用了。只要吧编码的filter放到最前面就没有问题了。改成这样就好。<br /></p>
		<div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)">
				<span style="COLOR: rgb(0,0,0)">    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">encodingFilter</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">/dwr/*</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    <br />    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">encodingFilter</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">*.jhtml</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    <br />    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">encodingFilter</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">*.jsp</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    <br />    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">requestCounterFilter</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-name</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />        </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">*.jhtml</span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">url-pattern</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
				<span style="COLOR: rgb(0,0,0)">
						<br />    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;/</span>
				<span style="COLOR: rgb(128,0,0)">filter-mapping</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
		</div>
		<p>
				<br />以后大家一定要注意啊。顺序问题也是很重要的。<br /><a href="http://www.creativecommons.cn/licenses/by-nc-sa/1.0/" target="_blank"><img height="31" alt="创造共用协议:署名,非商业,保持一致" src="http://leaf.jdk.cn/rights.gif" width="88" border="0" /></a>   除经特别注明外,本文章版权归<strong><a class="" href="http://jdkcn.com/"><font color="#6b6b52">莫多泡泡</font></a></strong>所有. <br /><font color="#ff0000">署名,非商业用途,保持一致.</font>   <a title="莫多泡泡" href="http://jdkcn.com/" target="_blank">somebody(莫多)</a></p><img src ="http://www.blogjava.net/rory/aggbug/90236.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rory/" target="_blank">莫多</a> 2006-12-27 10:37 <a href="http://www.blogjava.net/rory/archive/2006/12/27/character_encoding_problem_filtermapping_position.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>tuckey urlrewrite 3.x的问题</title><link>http://www.blogjava.net/rory/archive/2006/12/12/tuckey-urlrewrite_3-querystring-problem.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Tue, 12 Dec 2006 02:33:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/12/12/tuckey-urlrewrite_3-querystring-problem.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/87151.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/12/12/tuckey-urlrewrite_3-querystring-problem.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/87151.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/87151.html</trackback:ping><description><![CDATA[昨天晚上配置myblog的rewrite。发现一个奇怪的问题。由于现在使用的这个pjblog，为了让搜索引擎收录的连接有效。我想把原来的asp连接rewrite到我的新程序上面。所以有这样一条规则。<br /><br /><div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)"><span style="COLOR: rgb(0,0,0)">    </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">rule</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />        </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">from</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">^/article.asp\?id=(.*)$</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">from</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />        </span><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">to </span><span style="COLOR: rgb(255,0,0)">type</span><span style="COLOR: rgb(0,0,255)">="redirect"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)">/entry/$1.jhtml</span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">to</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />    </span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">rule</span><span style="COLOR: rgb(0,0,255)">&gt;</span></div>     但是我这样的连接总是匹配不到，只要去掉那个？就可以了。这个正则表达式是没有问题的。/article.asp?id=64是可以匹配的到的。<br />    后来看3.0的manual (http://tuckey.org/urlrewrite/manual/3.0/)才发现原来是这个的问题。<br /><h3>&lt;urlrewrite&gt; element</h3><p>The top level element.</p><table cellspacing="0"><tbody><tr><th>Attribute</th><th>Possible Value</th><th>Explanation</th></tr><tr><td rowspan="2">default-match-type <br /><small>(optional)</small></td><td><b>regex</b> (default)</td><td>All rules and thier conditions will be processed using the Java Regular Expression engine (unless <code>match-type</code> is specified on a rule).</td></tr><tr><td>wildcard</td><td>All rules and thier conditions will be processed using the <a href="http://tuckey.org/urlrewrite/manual/3.0/#wildcard">Wildcard Expression engine</a> (unless <code>match-type</code> is specified on a rule).</td></tr><tr><td rowspan="3">decode-using <br /><small>(optional)</small></td><td><b>utf8</b> (default)</td><td>When URL is decoded UTF-8 will be used.</td></tr><tr><td>null</td><td>Do not decode.</td></tr><tr><td>[encoding]</td><td>Any string representing a supported character encoding eg, ISO-8859-1. See <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/nio/charset/Charset.html">Java Charset Object</a> for more info. </td></tr><tr><td style="FONT-WEIGHT: bold; COLOR: rgb(0,0,255)" rowspan="2">use-query-string <br /><small>(optional)</small></td><td><b>false</b> (default)</td><td>The query string will <em>not</em> be appended to the url that the "from" element matches against.</td></tr><tr><td>true</td><td>The query string will be appended to the url that the "from" element matches against.</td></tr><tr><td rowspan="2">use-context <br /><small>(optional)</small></td><td><b>false</b> (default)</td><td>The context path will <em>not</em> be added to the url that the "from" element matches against.</td></tr><tr><td>true</td><td>The context path will be added to the url that the "from" element matches against.</td></tr></tbody></table><br />就是那个use-query-string 的问题，默认的是不使用query-string就是把?后面的都忽略了。所以就不能匹配到了。只要在&lt;urlrewrite&gt;里面加一个属性就可以了。<br /><div style="BORDER-RIGHT: rgb(204,204,204) 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: rgb(204,204,204) 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: rgb(204,204,204) 1px solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: rgb(204,204,204) 1px solid; BACKGROUND-COLOR: rgb(238,238,238)"><span style="COLOR: rgb(0,0,255)">&lt;</span><span style="COLOR: rgb(128,0,0)">urlrewrite </span><span style="COLOR: rgb(255,0,0)">use-query-string</span><span style="COLOR: rgb(0,0,255)">="true"</span><span style="COLOR: rgb(0,0,255)">&gt;</span><span style="COLOR: rgb(0,0,0)"><br />    <img alt="" src="http://www.blogjava.net/images/dot.gif" /><br /></span><span style="COLOR: rgb(0,0,255)">&lt;/</span><span style="COLOR: rgb(128,0,0)">urlrewrite</span><span style="COLOR: rgb(0,0,255)">&gt;</span></div><p><a href="http://www.creativecommons.cn/licenses/by-nc-sa/1.0/" target="_blank"><img height="31" alt="创造共用协议:署名,非商业,保持一致" src="http://leaf.jdk.cn/rights.gif" width="88" border="0" /></a>   除经特别注明外,本文章版权归<strong><a class="" href="http://jdkcn.com/"><font color="#6b6b52">莫多泡泡</font></a></strong>所有. <br /><font color="#ff0000">署名,非商业用途,保持一致.</font>   <a title="莫多泡泡" href="http://jdkcn.com/" target="_blank">somebody(莫多)</a></p><img src ="http://www.blogjava.net/rory/aggbug/87151.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rory/" target="_blank">莫多</a> 2006-12-12 10:33 <a href="http://www.blogjava.net/rory/archive/2006/12/12/tuckey-urlrewrite_3-querystring-problem.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>还是乱码问题</title><link>http://www.blogjava.net/rory/archive/2006/07/22/59567.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Sat, 22 Jul 2006 10:13:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/07/22/59567.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/59567.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/07/22/59567.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/59567.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/59567.html</trackback:ping><description><![CDATA[<p>     虽然项目全部采用了UTF-8编码，所有的源文件*.java,*.jsc,*.html,*.ftl都采用了UTF-8编码。可是还是出现了乱码问题。很是不爽，后来找到了tomcat，和resin的配置。</p>
		<ol>
				<li>Tomcat的配置。(conf/server.xml)<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000"> Define a non-SSL HTTP/1.1 Connector on port 8080 </span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">Connector </span><span style="COLOR: #ff0000">port</span><span style="COLOR: #0000ff">="80"</span><span style="COLOR: #ff0000"> maxHttpHeaderSize</span><span style="COLOR: #0000ff">="8192"</span><span style="COLOR: #ff0000"><br />               maxThreads</span><span style="COLOR: #0000ff">="150"</span><span style="COLOR: #ff0000"> minSpareThreads</span><span style="COLOR: #0000ff">="25"</span><span style="COLOR: #ff0000"> maxSpareThreads</span><span style="COLOR: #0000ff">="75"</span><span style="COLOR: #ff0000"><br />               enableLookups</span><span style="COLOR: #0000ff">="false"</span><span style="COLOR: #ff0000"> redirectPort</span><span style="COLOR: #0000ff">="8443"</span><span style="COLOR: #ff0000"> acceptCount</span><span style="COLOR: #0000ff">="100"</span><span style="COLOR: #ff0000"><br />               connectionTimeout</span><span style="COLOR: #0000ff">="20000"</span><span style="COLOR: #ff0000"> disableUploadTimeout</span><span style="COLOR: #0000ff">="true"</span><span style="COLOR: #ff0000"> URIEncoding</span><span style="COLOR: #0000ff">="UTF-8"</span><span style="COLOR: #0000ff">/&gt;</span></div></li>
				<li>Resin的配置。(conf/resin.conf)<br /><p></p><table class=" FCK__ShowTableBorders" cellspacing="0" cellpadding="0" width="100%" border="0"><tbody><tr><td><h4>character-encoding</h4></td><td align="right">Resin 1.1</td></tr></tbody></table><div class="desc"><b>child of:</b> resin, server, host-default, host, web-app-default, web-app<br /><b>default:</b> The default value is ISO-8859-1.<br /><p>Specifies the default character encoding for the environment.</p><p></p><table class="egpad FCK__ShowTableBorders" cellspacing="0" width="90%"><tbody><tr><td class="example" bgcolor="#ffeecc"><pre>&lt;web-app id='/'&gt;
  &lt;character-encoding&gt;shift_jis&lt;/character-encoding&gt;
  ...

&lt;/web-app&gt;
</pre></td></tr></tbody></table></div></li>
		</ol>
		<p class="desc">
		</p>
		<p>     这个是resin doc里面的我是在web-app-default里面加上了encoding的配置</p>
		<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">
				<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">web-app-default</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">character-encoding</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">UTF-8</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">character-encoding</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />      <img src="http://www.blogjava.net/images/dot.gif" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">web-app-default</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>
		<p>希望对你的项目有帮助。</p>
		<p>
				<a href="http://www.creativecommons.cn/licenses/by-nc-sa/1.0/" target="_blank">
						<img height="31" alt="创造共用协议:署名,非商业,保持一致" src="http://leaf.jdk.cn/rights.gif" width="88" border="0" />
				</a>   除经特别注明外,本文章版权归<strong><a class="" href="http://jdkcn.com/"><font color="#6b6b52">莫多泡泡</font></a></strong>所有. <br /><font color="#ff0000">署名,非商业用途,保持一致.</font>   somebody(莫多)   </p><img src ="http://www.blogjava.net/rory/aggbug/59567.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rory/" target="_blank">莫多</a> 2006-07-22 18:13 <a href="http://www.blogjava.net/rory/archive/2006/07/22/59567.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于Resin虚拟目录配置的问题</title><link>http://www.blogjava.net/rory/archive/2006/07/18/58838.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Tue, 18 Jul 2006 11:41:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/07/18/58838.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/58838.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/07/18/58838.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/58838.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/58838.html</trackback:ping><description><![CDATA[项目中多个项目需要同时引用一个静态资源，所以就想到配置不同的虚拟目录指到同一个目录。于是有下面的配置:<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000"> configures the default host, matching any host name </span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">host </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">=""</span><span style="COLOR: #ff0000"> root-directory</span><span style="COLOR: #0000ff">="."</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #008000">&lt;!--</span><span style="COLOR: #008000"><br />         - configures an explicit root web-app matching the<br />         - webapp's ROOT<br />        </span><span style="COLOR: #008000">--&gt;</span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">web-app </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="/"</span><span style="COLOR: #ff0000"> document-directory</span><span style="COLOR: #0000ff">="webapps/ROOT"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">web-app </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="/community/jsvm2"</span><span style="COLOR: #ff0000"> document-directory</span><span style="COLOR: #0000ff">="D:\\projects\\FelooComponents\\jsvm2"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">web-app </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="/passport/jsvm2"</span><span style="COLOR: #ff0000"> document-directory</span><span style="COLOR: #0000ff">="D:\\projects\\FelooComponents\\jsvm2"</span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">host</span><span style="COLOR: #0000ff">&gt;</span></div><p>       但是发现这样只有后面一个管用(<a href="http://localhost:8080/passport/jsvm2">http://localhost:8080/passport/jsvm2</a>)这个是可以,可是(<a href="http://localhost:8080/community/jsvm2">http://localhost:8080/community/jsvm2</a>)就不行,很是郁闷。只要后面的document-directory不是同一个目录就成。<br />       后来在resin的doc里面看到path的配置</p><h4>path-mapping</h4><div class="desc"><b>child of:</b> web-app-default, web-app<br /><p>Maps url patterns to real paths. If using a server like IIS, you may need to match the server's path aliases.</p><p></p><table class="deftable" cellspacing="0" cellpadding="2" width="90%" border="1"><tbody><tr><th>Attribute</th><th>Meaning</th><th>default</th></tr><tr><td><span class="meta">url-pattern</span></td><td>A pattern matching the url: <span class="meta">/foo/*</span>, <span class="meta">/foo</span>, or <span class="meta">*.foo</span></td></tr><tr><td>url-regexp</td><td>A regular expression matching the url </td></tr><tr><td>real-path</td><td>The prefix of the real path. When used with <span class="meta">url-regexp</span>, allows substitution variables like <span class="meta">$1</span>. </td></tr></tbody></table><p></p><table class="egpad" cellspacing="0" width="90%"><tbody><tr><td class="example" bgcolor="#ffeecc"><pre>&lt;web-app id='/'&gt;
            &lt;path-mapping url-pattern='/resin/*'
            real-path='e:\resin'/&gt;
            &lt;path-mapping url-regexp='/~([^/]*)'
            real-path='e:\home$1'/&gt;
            &lt;/web-app&gt;
            </pre></td></tr></tbody></table></div><p>改正这样的配置就ok了。</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"><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">web-app </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="/community"</span><span style="COLOR: #ff0000"> document-directory</span><span style="COLOR: #0000ff">="D:\\projects\\FelooCommunityWeb"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />          </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">path-mapping </span><span style="COLOR: #ff0000">url-pattern</span><span style="COLOR: #0000ff">='jsvm2/*'<br />              </span><span style="COLOR: #ff0000">real-path</span><span style="COLOR: #0000ff">='D:\\projects\\FelooComponents\\jsvm2'/&gt;<br />      </span><span style="COLOR: #ff0000">&lt;/web-app</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />      <br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">web-app </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="/passport"</span><span style="COLOR: #ff0000"> document-directory</span><span style="COLOR: #0000ff">="D:\\projects\\FelooPassportWeb"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />          </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">path-mapping </span><span style="COLOR: #ff0000">url-pattern</span><span style="COLOR: #0000ff">='jsvm2/*'<br />              </span><span style="COLOR: #ff0000">real-path</span><span style="COLOR: #0000ff">='D:\\projects\\FelooComponents\\jsvm2'/&gt;<br />      </span><span style="COLOR: #ff0000">&lt;/web-app</span><span style="COLOR: #0000ff">&gt;</span></div><a href="http://www.creativecommons.cn/licenses/by-nc-sa/1.0/" target="_blank"><img height="31" alt="创造共用协议:署名,非商业,保持一致" src="http://leaf.jdk.cn/rights.gif" width="88" border="0" /></a>   除经特别注明外,本文章版权归<strong><a class="" title="" href="http://leaf.jdk.cn/" target=""><font color="#6b6b52">莫多泡泡</font></a></strong>所有. <br /><font color="#ff0000">署名,非商业用途,保持一致.</font>   somebody(莫多)<img src ="http://www.blogjava.net/rory/aggbug/58838.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rory/" target="_blank">莫多</a> 2006-07-18 19:41 <a href="http://www.blogjava.net/rory/archive/2006/07/18/58838.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于Freemarker生成静态文件的问题</title><link>http://www.blogjava.net/rory/archive/2006/06/21/54134.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Wed, 21 Jun 2006 02:46:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/06/21/54134.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/54134.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/06/21/54134.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/54134.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/54134.html</trackback:ping><description><![CDATA[首先感谢JScud提供的好文章。《<a class="" title="" href="http://www.jscud.com/srun/news/viewhtml/2_2005_4/36.htm" target="">使用FreeMarker生成Html静态文件(实例)</a>》<br />      在我们的项目中也用到了Freemarker生成静态文件。不过这里我要说的是编码的问题。我们的项目使用的都是UTF-8编码，我直接使用 飞云小侠 提供的方法生成的文件在UTF-8编码下察看是乱码，而GBK正常(后来发现因为我用的中文操作系统所以用GBK查看正常)。<br />      当然我把Freemarker的配置都改成了UTF-8，我的模版文件也是UTF-8编码的。下面是原来的代码<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> setTemplatePath(Resource templatePath) {<br />        </span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.templatePath </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> templatePath;<br />        </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">设置freemarker的参数</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">        freemarkerCfg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Configuration();<br />        </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {<br />            freemarkerCfg.setDirectoryForTemplateLoading(</span><span style="COLOR: #0000ff">this</span><span style="COLOR: #000000">.templatePath.getFile());<br />            freemarkerCfg.setObjectWrapper(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> DefaultObjectWrapper());<br />            freemarkerCfg.setDefaultEncoding(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (IOException ex) {<br />            </span><span style="COLOR: #0000ff">throw</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SystemException(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">No Directory found,please check you config.</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />        }<br />    }</span></div><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br />     * 生成静态文件<br />     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> templateFileName 模版名称eg:(biz/order.ftl)<br />     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> propMap 用于处理模板的属性Object映射 <br />     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> htmlFilePath 要生成的静态文件的路径,相对设置中的根路径,例如 "/biz/2006/5/" <br />     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> htmlFileName 要生成的文件名,例如 "123.htm" <br />     * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"><br />     </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> buildHtml(String templateFileName,Map propMap, String htmlFilePath,String htmlFileName){<br />        </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {<br />            Template template </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> freemarkerCfg.getTemplate(templateFileName);<br />            template.setEncoding(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">创建生成文件目录</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            creatDirs(buildPath.getFilename(),htmlFilePath);<br />            File htmlFile </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> File(buildPath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> htmlFilePath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> htmlFileName);<br />            Writer out </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> BufferedWriter(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> OutputStreamWriter(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileOutputStream(htmlFile)));<br />            template.process(propMap,out);<br />            out.flush();<br />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br />        } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (TemplateException ex){<br />            log.error(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Build Error</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">templateFileName,ex);<br />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br />        } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (IOException e) {<br />            log.error(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Build Error</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">templateFileName,e);<br />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br />        }<br />        <br />    }</span></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"><span style="COLOR: #000000">    </span><span style="COLOR: #008000">/**</span><span style="COLOR: #008000"><br />     * 生成静态文件<br />     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> templateFileName 模版名称eg:(biz/order.ftl)<br />     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> propMap 用于处理模板的属性Object映射 <br />     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> htmlFilePath 要生成的静态文件的路径,相对设置中的根路径,例如 "/biz/2006/5/" <br />     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> htmlFileName 要生成的文件名,例如 "123.htm" <br />     * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"><br />     </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">boolean</span><span style="COLOR: #000000"> buildHtml(String templateFileName,Map propMap, String htmlFilePath,String htmlFileName){<br />        </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {<br />            Template template </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> freemarkerCfg.getTemplate(templateFileName);<br />            template.setEncoding(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">创建生成文件目录</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            creatDirs(buildPath.getFilename(),htmlFilePath);<br />            File htmlFile </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> File(buildPath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> htmlFilePath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> htmlFileName);<br />            Writer out </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> BufferedWriter(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> OutputStreamWriter(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileOutputStream(htmlFile),</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />            template.process(propMap,out);<br />            out.flush();<br />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">true</span><span style="COLOR: #000000">;<br />        } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (TemplateException ex){<br />            log.error(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Build Error</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">templateFileName,ex);<br />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br />        } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (IOException e) {<br />            log.error(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Build Error</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">templateFileName,e);<br />            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">false</span><span style="COLOR: #000000">;<br />        }<br />        <br />    }</span></div>原因就在于OutputStreamWriter的不同构造方法<br /><br /><a href="file:///D:/Jdk5_API_zh_CN/api/java/io/OutputStreamWriter.html#OutputStreamWriter%28java.io.OutputStream%29"><strong><font face="Courier New"><em>OutputStreamWriter</em></font></strong></a><font face="Courier New"><em>(</em></font><a title="java.io 中的类" href="file:///D:/Jdk5_API_zh_CN/api/java/io/OutputStream.html"><font face="Courier New"><em>OutputStream</em></font></a><em><font face="Courier New"> out)</font><br />          创建使用默认字符编码的 OutputStreamWriter。<br /></em><a href="file:///D:/Jdk5_API_zh_CN/api/java/io/OutputStreamWriter.html#OutputStreamWriter%28java.io.OutputStream,%20java.lang.String%29"><strong><font face="Courier New"><em>OutputStreamWriter</em></font></strong></a><font face="Courier New"><em>(</em></font><a title="java.io 中的类" href="file:///D:/Jdk5_API_zh_CN/api/java/io/OutputStream.html"><font face="Courier New"><em>OutputStream</em></font></a><font face="Courier New"><em> out, </em></font><a title="java.lang 中的类" href="file:///D:/Jdk5_API_zh_CN/api/java/lang/String.html"><font face="Courier New"><em>String</em></font></a><em><font face="Courier New"> charsetName)</font><br />          创建使用指定字符集的 OutputStreamWriter。<br /><br /> </em>这个是中文JDK的文档说明，刚开始我使用默认的构造函数，所以使用了系统默认的编码，GBK，所以在生成静态文件的时候把UTF-8内容用GBK编码写入了，所以在UTF-8下浏览就有问题。<br /><br />还有关于修改模版文件同样也要注意这个问题。<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> String loadTemplate(String templateName) {<br />        StringBuffer sb </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> StringBuffer();<br />        </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {<br />            File file </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> File(templatePath</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">templateName);<br />            BufferedReader reader </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> BufferedReader(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> InputStreamReader(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileInputStream(file),</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />            String line </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> reader.readLine();<br />            </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000">(line </span><span style="COLOR: #000000">!=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">)    {<br />                sb.append(line);<br />                sb.append(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">\r\n</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">);<br />                line </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> reader.readLine();<br />            }<br />            reader.close();<br />        } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (IOException e) {<br />            </span><span style="COLOR: #0000ff">throw</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SystemException(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Loading template Error:</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,e);<br />        }<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> sb.toString();<br />    }</span></div><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> saveTemplate(String templateName, String templateContent) {<br />        </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"> {<br />            File file </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> File(templatePath </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">/</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> templateName);<br />            Writer out </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> BufferedWriter(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> OutputStreamWriter(</span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> FileOutputStream(file),</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">UTF-8</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));<br />            out.write(templateContent);<br />            out.flush();<br />            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">扔出templatesave事件</span><span style="COLOR: #008000"><br /></span><span style="COLOR: #000000">            TemplateSaveEvent evt </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> TemplateSaveEvent();<br />            evt.setTemplateName(templateName);<br />            dispatchTemplateEvent(evt);<br />        } </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (IOException e) {<br />            </span><span style="COLOR: #0000ff">throw</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> SystemException(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">Write template Error</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">,e);<br />        }<br />    }</span></div><td width="100"><br /></td><img src ="http://www.blogjava.net/rory/aggbug/54134.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rory/" target="_blank">莫多</a> 2006-06-21 10:46 <a href="http://www.blogjava.net/rory/archive/2006/06/21/54134.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用ant进行项目无忧部署</title><link>http://www.blogjava.net/rory/archive/2006/04/28/43884.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Fri, 28 Apr 2006 14:27:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/04/28/43884.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/43884.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/04/28/43884.html#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/43884.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/43884.html</trackback:ping><description><![CDATA[我们的项目比较特殊，基本上每天都要发布一次。为了不影响系统的正常使用，我们的做法是在下班之前把打包好的war放到服务器的一个目录下面(eg:d:\bak)。然后用windows的计划任务在晚上12点自动部署系统，也就是net stop tomcat,删除xx.war,删除xx，然后把d:\bak\xx.war拷贝到webapps下面。然后再net start tomcat。这样在第二天来的上班的时候就可以使用升级过的系统了。也不会影响其他人的使用，不需要中断操作。<br />    关于项目的一个配置我的前几篇文章我也提到过，那个upload的问题就不会发生了。还有就是关于项目开发中的一些问题。比如数据库的连接地址，upload directory的配置等，这些在团队中的每个人都是不一样的，那么在发布的时候都要改成服务器上的正确配置，如果一个月部署一次这到没有什么。但是像我们这样每天部署就不是那么轻松了。而且如果一时不注意很容易造成配置的不正确。所以对于很多配置文件我们都有两份。一份是用户自己开发用的，一份是部署到服务器的配置，这样在开发的时候团队中的每个人都不一样，关于服务器的配置都是一样的，在发布的时候是用的服务器的配置而不是用开发用的配置。eg：web.xml(个人的配置)web-dest.xml 而关键的配置也就是下面这段。<br />web.xml<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">context-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">contextConfigLocation</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 />        </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 />            classpath:spring/*_context.xml,<br />            classpath:spring/global.xml </span><span style="COLOR: #000000"><br />        </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 />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">context-param</span><span style="COLOR: #0000ff">&gt;</span></div>web-dest.xml<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">context-param</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">param-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">contextConfigLocation</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 />        </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 />            classpath:spring/*_context.xml,<br />            classpath:spring/global-dest.xml,<br />            classpath:spring/scheduler.xml<br />        </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 />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">context-param</span><span style="COLOR: #0000ff">&gt;</span></div>注意到其中不一样的。dest里少了scheduler.xml这个主要是定时执行的一些任务，一般在开发的时候都不需要，去掉也可以提升速度，也不会出现那么多的log。还有就是发布的web.xml用了global-dest.xml这个是关于spring的总的配置。<br />global.xml<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="dataSource"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="org.apache.commons.dbcp.BasicDataSource"</span><span style="COLOR: #ff0000"> destroy-method</span><span style="COLOR: #0000ff">="close"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="driverClassName"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">net.sourceforge.jtds.jdbc.Driver</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">jdbc:jtds:sqlserver://192.168.0.240:1433/fivefortunes;SelectMethod=cursor</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="username"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">sa</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    <br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="dataSource2"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="org.apache.commons.dbcp.BasicDataSource"</span><span style="COLOR: #ff0000"> destroy-method</span><span style="COLOR: #0000ff">="close"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="driverClassName"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">net.sourceforge.jtds.jdbc.Driver</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">jdbc:jtds:sqlserver://192.168.0.240:1433/outmail;SelectMethod=cursor</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="username"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">sa</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    <br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="customDataSource"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="org.apache.commons.dbcp.BasicDataSource"</span><span style="COLOR: #ff0000"> destroy-method</span><span style="COLOR: #0000ff">="close"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="driverClassName"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">net.sourceforge.jtds.jdbc.Driver</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">jdbc:jtds:sqlserver://192.168.0.240:1433/custom;SelectMethod=cursor</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="username"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">sa</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">&gt;</span></div>global-dest.xml<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="dataSource"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="org.apache.commons.dbcp.BasicDataSource"</span><span style="COLOR: #ff0000"> destroy-method</span><span style="COLOR: #0000ff">="close"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="driverClassName"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">net.sourceforge.jtds.jdbc.Driver</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">jdbc:jtds:sqlserver://192.168.0.5:1433/fivefortunes;SelectMethod=cursor</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="username"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">sa</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    <br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="dataSource2"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="org.apache.commons.dbcp.BasicDataSource"</span><span style="COLOR: #ff0000"> destroy-method</span><span style="COLOR: #0000ff">="close"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="driverClassName"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">net.sourceforge.jtds.jdbc.Driver</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">jdbc:jtds:sqlserver://192.168.0.5:1433/outmail;SelectMethod=cursor</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="username"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">sa</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    <br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="customDataSource"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="org.apache.commons.dbcp.BasicDataSource"</span><span style="COLOR: #ff0000"> destroy-method</span><span style="COLOR: #0000ff">="close"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="driverClassName"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">net.sourceforge.jtds.jdbc.Driver</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="url"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">jdbc:jtds:sqlserver://192.168.0.5:1433/custom;SelectMethod=cursor</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="username"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">sa</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="password"</span><span style="COLOR: #0000ff">&gt;&lt;</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;&lt;/</span><span style="COLOR: #800000">property</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">bean</span><span style="COLOR: #0000ff">&gt;</span></div>还有关于一些properties文件我们采用了用ant部署的时候改名字来达到目的。<br />build.xml<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">move </span><span style="COLOR: #ff0000">file</span><span style="COLOR: #0000ff">="${dist.dir}/mail.properties"</span><span style="COLOR: #ff0000"> tofile</span><span style="COLOR: #0000ff">="${dist.dir}/mail-dev.properties"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">copy </span><span style="COLOR: #ff0000">file</span><span style="COLOR: #0000ff">="${dist.dir}/mail-dest.properties"</span><span style="COLOR: #ff0000"> tofile</span><span style="COLOR: #0000ff">="${dist.dir}/mail.properties"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">move </span><span style="COLOR: #ff0000">file</span><span style="COLOR: #0000ff">="${dist.dir}/upload.properties"</span><span style="COLOR: #ff0000"> tofile</span><span style="COLOR: #0000ff">="${dist.dir}/upload-dev.properties"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">copy </span><span style="COLOR: #ff0000">file</span><span style="COLOR: #0000ff">="${dist.dir}/upload-dest.properties"</span><span style="COLOR: #ff0000"> tofile</span><span style="COLOR: #0000ff">="${dist.dir}/upload.properties"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span></div><br />这个是在war之前做的，大家眼看也就明白吧，就是把xx-dest.properties,改名成xx.propeties。在打完包之后<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">move </span><span style="COLOR: #ff0000">file</span><span style="COLOR: #0000ff">="${dist.dir}/mail-dev.properties"</span><span style="COLOR: #ff0000"> tofile</span><span style="COLOR: #0000ff">="${dist.dir}/mail.properties"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">move </span><span style="COLOR: #ff0000">file</span><span style="COLOR: #0000ff">="${dist.dir}/upload-dev.properties"</span><span style="COLOR: #ff0000"> tofile</span><span style="COLOR: #0000ff">="${dist.dir}/upload.properties"</span><span style="COLOR: #ff0000"> </span><span style="COLOR: #0000ff">/&gt;</span></div>这样就达到了我们无忧的目的了。只要每天部署的时候保证程序能正常运行，ant war一下就安心部署吧。<br />以上就是全部内容，如果有什么不正确欢迎砸板砖。<img src ="http://www.blogjava.net/rory/aggbug/43884.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rory/" target="_blank">莫多</a> 2006-04-28 22:27 <a href="http://www.blogjava.net/rory/archive/2006/04/28/43884.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>刚才把caucho的wiki弄坏了</title><link>http://www.blogjava.net/rory/archive/2006/03/21/36572.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Tue, 21 Mar 2006 02:48:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/03/21/36572.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/36572.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/03/21/36572.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/36572.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/36572.html</trackback:ping><description><![CDATA[<p>
				<a href="http://wiki.caucho.com/">http://wiki.caucho.com</a>
				<br />真是不好意思。我去注册了一下。可能是中文昵称的问题吧。<br />nickname我用了。中文。</p>
		<p>它是用的MediaWiki<br /><br /><a href="http://leaf.jdk.cn/index.php/archives/82">http://leaf.jdk.cn/index.php/archives/82</a></p><img src ="http://www.blogjava.net/rory/aggbug/36572.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/rory/" target="_blank">莫多</a> 2006-03-21 10:48 <a href="http://www.blogjava.net/rory/archive/2006/03/21/36572.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>