﻿<?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</title><link>http://www.blogjava.net/rory/</link><description>Happy study,Happy work,Happy life</description><language>zh-cn</language><lastBuildDate>Sun, 03 May 2026 00:08:39 GMT</lastBuildDate><pubDate>Sun, 03 May 2026 00:08:39 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>SpringXmlrpcServiceExporter for xmlrpc3.x</title><link>http://www.blogjava.net/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Sun, 22 Oct 2006 08:12:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/76628.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/76628.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/76628.html</trackback:ping><description><![CDATA[<p>      我们的项目用到了xmlrpc,不过还是用的2.x版本的。由于xmlrpc3.x地推出。提供了NULL,Serializable等的支持，将原来的Hashtable改成了Map,Vector改成了List。都是不错的进步。所以我们决定从xmlrpc2.x升级到xmlrpc3.x.<br />      在spring里面有几个ServiceExporter，org.springframework.remoting.rmi.RmiServiceExporter、org.springframework.remoting.caucho.HessianServiceExporter、org.springframework.remoting.caucho.BurlapServiceExporter。不过没有xmlrpc的serviceExporter，原来我们是自己封装的XmlRpcServer,用servlet提供服务。(eg:http://localhost:8080/community/service/xmlrpc)没有和spring集成虽然用了spring。<br />    考虑到spring的便利以及配置的同意我决定将xmlrpcService放入spring中。xmlrpc3.x和xmlrpc2.x的代码基本上没有一样的。改了很多东西。除了类型变化之外，还添加了对异常的支持。详细信息请参照xmlrpc3.x源代码。<br />XmlRpcServiceExporter.java</p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #0000ff">package</span>
				<span style="COLOR: #000000"> com.jdkcn.xmlrpc;<br /><br /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> javax.servlet.ServletException;<br /><br /></span>
				<span style="COLOR: #008000">/**</span>
				<span style="COLOR: #008000">
						<br /> * </span>
				<span style="COLOR: #808080">@author</span>
				<span style="COLOR: #008000"> &lt;a href="mailto:rory.cn@gmail.com"&gt;somebody&lt;/a&gt;<br /> * </span>
				<span style="COLOR: #808080">@since</span>
				<span style="COLOR: #008000"> 2006-9-27 03:59:22 pm<br /> * </span>
				<span style="COLOR: #808080">@version</span>
				<span style="COLOR: #008000"> $Id XmlRpcServiceExporter.java$<br /> </span>
				<span style="COLOR: #008000">*/</span>
				<span style="COLOR: #000000">
						<br />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> XmlRpcServiceExporter </span>
				<span style="COLOR: #0000ff">extends</span>
				<span style="COLOR: #000000"> RemoteExporter </span>
				<span style="COLOR: #0000ff">implements</span>
				<span style="COLOR: #000000">
						<br />        Controller, InitializingBean {<br />    <br />    </span>
				<span style="COLOR: #0000ff">private</span>
				<span style="COLOR: #000000"> XmlRpcServletServer server;<br />    <br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> String serviceName;<br />    <br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> Resource configFile;<br />    <br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> Boolean enabledForExtensions;<br />    <br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setEnabledForExtensions(Boolean enabledForExtensions) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.enabledForExtensions </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> enabledForExtensions;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setConfigFile(Resource configFile) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.configFile </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> configFile;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> String getServiceName() {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> serviceName;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> setServiceName(String serviceName) {<br />        </span>
				<span style="COLOR: #0000ff">this</span>
				<span style="COLOR: #000000">.serviceName </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> serviceName;<br />    }<br /><br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> XmlRpcServletServer getXmlRpcServletServer() {<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> server;<br />    }<br />    <br />    </span>
				<span style="COLOR: #008000">/*</span>
				<span style="COLOR: #008000"> (non-Javadoc)<br />     * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)<br />     </span>
				<span style="COLOR: #008000">*/</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> ModelAndView handleRequest(HttpServletRequest request,<br />            HttpServletResponse response) </span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> Exception {<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (</span>
				<span style="COLOR: #000000">!</span>
				<span style="COLOR: #000000">WebContentGenerator.METHOD_POST.equals(request.getMethod())) {<br />            </span>
				<span style="COLOR: #0000ff">throw</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> ServletException(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">XmlRpcServiceExporter only supports POST requests</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">);<br />        }<br />        server.execute(request, response);<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">;<br />    }<br /><br />    </span>
				<span style="COLOR: #008000">/*</span>
				<span style="COLOR: #008000"> (non-Javadoc)<br />     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()<br />     </span>
				<span style="COLOR: #008000">*/</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">void</span>
				<span style="COLOR: #000000"> afterPropertiesSet() </span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> Exception {<br />        server </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> XmlRpcServletServer();<br />        server.setHandlerMapping(newXmlRpcHandlerMapping());<br />        </span>
				<span style="COLOR: #0000ff">if</span>
				<span style="COLOR: #000000"> (enabledForExtensions</span>
				<span style="COLOR: #000000">!=</span>
				<span style="COLOR: #0000ff">null</span>
				<span style="COLOR: #000000">) {<br />            ((XmlRpcServerConfigImpl) server.getConfig()).setEnabledForExtensions(enabledForExtensions.booleanValue());<br />        }<br />        <br />    }<br /><br />    </span>
				<span style="COLOR: #008000">/**</span>
				<span style="COLOR: #008000"> Creates a new handler mapping. The default implementation loads<br />     * a property file from the resource<br />     * <br />     </span>
				<span style="COLOR: #008000">*/</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">protected</span>
				<span style="COLOR: #000000"> XmlRpcHandlerMapping newXmlRpcHandlerMapping() </span>
				<span style="COLOR: #0000ff">throws</span>
				<span style="COLOR: #000000"> XmlRpcException {<br />        <br />        SpringHandlerMapping mapping </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">new</span>
				<span style="COLOR: #000000"> SpringHandlerMapping(getServiceInterface());<br />        mapping.addHandler(getServiceName(), getServiceInterface());<br />        mapping.setTagetObject(getProxyForService());<br />        </span>
				<span style="COLOR: #0000ff">return</span>
				<span style="COLOR: #000000"> mapping;<br />    }<br />    <br />}<br /></span>
		</div>
		<br />spring配置文件<br /><div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">bean </span><span style="COLOR: #ff0000">id</span><span style="COLOR: #0000ff">="accountService"</span><span style="COLOR: #ff0000">  class</span><span style="COLOR: #0000ff">="com.jdkcn.service.impl.AccountServiceImpl"</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">bean</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">bean </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="rpcAccountService"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="com.jdkcn.xmlrpc.XmlRpcServiceExporter"</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">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="service"</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">ref </span><span style="COLOR: #ff0000">bean</span><span style="COLOR: #0000ff">="accountService"</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">property</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">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="serviceName"</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">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">jdkcn.accountService</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</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">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="enabledForExtensions"</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">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">true</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</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">property </span><span style="COLOR: #ff0000">name</span><span style="COLOR: #0000ff">="serviceInterface"</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">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">com.jdkcn.service.AccountService</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">value</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">property</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">bean</span><span style="COLOR: #0000ff">&gt;</span></div>然后映射一个地址就可以通过xmlrpc访问服务了<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">="urlMapping"</span><span style="COLOR: #ff0000"> class</span><span style="COLOR: #0000ff">="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"</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">="mappings"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">props</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"> <br />                </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">prop </span><span style="COLOR: #ff0000">key</span><span style="COLOR: #0000ff">="/account"</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">rpcAccountService</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">prop</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">props</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">bean</span><span style="COLOR: #0000ff">&gt;</span></div>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/global.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><span style="COLOR: #000000"><br />    <br />    </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">listener</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">listener-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">org.springframework.web.context.ContextLoaderListener</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">listener-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">listener</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">service</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">org.springframework.web.servlet.DispatcherServlet</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-class</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br /><br />        </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-mapping</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">service</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-name</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />            </span><span style="COLOR: #0000ff">&lt;</span><span style="COLOR: #800000">url-pattern</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000">/service/xmlrpc3/*</span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">url-pattern</span><span style="COLOR: #0000ff">&gt;</span><span style="COLOR: #000000"><br />        </span><span style="COLOR: #0000ff">&lt;/</span><span style="COLOR: #800000">servlet-mapping</span><span style="COLOR: #0000ff">&gt;</span></div>然后我们的service地址就是这样的http://localhost:8080/service/xmlrpc3/account<br /><br />希望对大家有用，这里提供project下载。包含一个client程序。com.jdkcn.xmlrpc.Client<br /><br /><img style="MARGIN: 0px 2px -4px 0px" alt="" src="http://jdkcn.com/images/download.gif" border="0" /><a title="点击下载完整代码" href="http://jdkcn.com/download.asp" target="_blank">点击下载完整代码</a><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><img src ="http://www.blogjava.net/rory/aggbug/76628.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-10-22 16:12 <a href="http://www.blogjava.net/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于Hibernate3的escape解决方法</title><link>http://www.blogjava.net/rory/archive/2006/10/16/hibernate3_escape.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Mon, 16 Oct 2006 15:29:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/10/16/hibernate3_escape.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/75503.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/10/16/hibernate3_escape.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/75503.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/75503.html</trackback:ping><description><![CDATA[不知道大家有没有碰到，还是没有这种需求。就是用like来查询，我们没有用Lucene,Compass这种全文索引的方案,我们只是简单的添加%进行like查询。用户搜索的时候就使用*和?来代表任意和一个。所以要对"%"和"_"进行转义，我们使用的是oracle数据库。sql语句看起来可能是这样的。<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: #0000ff">SELECT</span><span style="COLOR: #000000"> </span><span style="COLOR: #808080">*</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">FROM</span><span style="COLOR: #000000"> t_user </span><span style="COLOR: #0000ff">where</span><span style="COLOR: #000000"> nickname </span><span style="COLOR: #808080">like</span><span style="COLOR: #000000"> </span><span style="COLOR: #ff0000">'</span><span style="COLOR: #ff0000">%Goo\_D</span><span style="COLOR: #ff0000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">escape</span><span style="COLOR: #000000"> </span><span style="COLOR: #ff0000">'</span><span style="COLOR: #ff0000">\</span><span style="COLOR: #ff0000">'</span></div>这里对_进行转义了。因为用户昵称包含下划线，如果不进行转义就表示一个任意字符。有时候我们可能还需要对%进行转义。同样的方法在%前加\% 但是比起普通的like语句。多了一个声明转义符的语句。所以我们会想到这样的语句<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">DetachedCriteria criteria </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> DetachedCriteria.forClass(User.</span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000">);<br />criteria.add(Restrictions.like(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">nickname</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, user.getNickname()</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">' escape'\</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">));</span></div>但是这样是不管用的。<br />接下来可能会想到使用Hibernate3的原生sql查询，其实我们不需要这样做。我们还是使用Criteria条件查询。<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">criteria.add(Restrictions.sqlRestriction(</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">{alias}.nickname like ? escape'/'</span><span style="COLOR: #000000">"</span><span style="COLOR: #000000">, StringUtil.escapeSQLLike(user.getNickname()), Hibernate.STRING));</span></div>这样Hibernate产生的语句就是我们想要的语句了。<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 />     * 转义like语句中的<br />     * &lt;code&gt;'_'&lt;/code&gt;&lt;code&gt;'%'&lt;/code&gt;<br />     * 将&lt;code&gt;'?'&lt;/code&gt;转成sql的&lt;code&gt;'/_'&lt;/code&gt;<br />     * 将&lt;code&gt;'%'&lt;/code&gt;转成sql的&lt;code&gt;'/%'&lt;/code&gt;<br />     * &lt;p&gt;<br />     *   例如搜索&lt;code&gt;?aa*bb?c_d%f&lt;/code&gt;将转化成&lt;br/&gt;<br />     *   &lt;code&gt;_aa%bb_c/_d/%f&lt;/code&gt;<br />     * &lt;/p&gt;<br />     * </span><span style="COLOR: #808080">@param</span><span style="COLOR: #008000"> likeStr<br />     * </span><span style="COLOR: #808080">@return</span><span style="COLOR: #008000"><br />     * </span><span style="COLOR: #808080">@author</span><span style="COLOR: #008000"> &lt;a href="</span><span style="COLOR: #008000; TEXT-DECORATION: underline">http://jdkcn.com</span><span style="COLOR: #008000">"&gt;somebody&lt;/a&gt;<br />     </span><span style="COLOR: #008000">*/</span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> String escapeSQLLike(String likeStr) {<br />        String str </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> StringUtils.replace(likeStr, </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">);<br />        str </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> StringUtils.replace(str, </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">);<br />        str </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> StringUtils.replace(str, </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">);<br />        str </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> StringUtils.replace(str, </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">);<br />        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> str;<br />    }</span></div><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><img src ="http://www.blogjava.net/rory/aggbug/75503.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-10-16 23:29 <a href="http://www.blogjava.net/rory/archive/2006/10/16/hibernate3_escape.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于spring启动的优化的问题</title><link>http://www.blogjava.net/rory/archive/2006/08/10/speed_up_spring_problem.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Thu, 10 Aug 2006 02:59:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/08/10/speed_up_spring_problem.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/62740.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/08/10/speed_up_spring_problem.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/62740.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/62740.html</trackback:ping><description><![CDATA[<p>  <span style="FONT-WEIGHT: bold">jspark</span> 的这篇文章《<a class="postTitle2" id="viewpost1_TitleUrl" href="/jspark/archive/2006/07/29/60712.html">开发阶段eclipse下面的spring容器的启动优化</a> 》讲到如何加快spring的启动速度。非常感谢<span style="FONT-WEIGHT: bold">jspark. </span>一下是引用的原文：<br /><br />  <span style="COLOR: rgb(51,51,153); FONT-STYLE: italic">最近在负责一个大项目，项目组成员包括项目经理大概10个人左右。项目技术用struts+spring+hibernate实现。项目的规模相对来说是比较大的，总共有10大模块，每个大模块又分为有十几个、甚至几十个小模块。开发工具用eclipse，由于在开发阶段，项目开发成员需要频繁重启服务器。在启动服务器的时候，每次启动时间总是会超过1分钟。记得以前在做另外一个项目时，启动时间不到5秒钟，相差了10倍，而且项目规模是差不多的。</span><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><span style="COLOR: rgb(51,51,153); FONT-STYLE: italic">    从初步分析来说，应该是hibernate解释hbm.xml时花费时间，或者可能是spring容器启动并解释所有的bean配置文件。诊断了一下，发现1分钟消耗的时间主要分布在hibernate解释hbm.xml花费5秒；spring容器从启动到解释bean配置文件竟然花了58秒，真是太嚣张了。当时非常怀疑spring的效率问题。企图从网上搜索相关资料，看看有什么优化措施。</span><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><span style="COLOR: rgb(51,51,153); FONT-STYLE: italic">    首先是找到了hibernate的启动优化 </span><a style="COLOR: rgb(51,51,153); FONT-STYLE: italic" href="http://www.hibernate.org/194.html">http://www.hibernate.org/194.html</a><span style="COLOR: rgb(51,51,153); FONT-STYLE: italic">  里面的主要思想是通过将xml序列花到本地的文件里，每次读取的时候根据情况，从本地文件读取并反序列化，节省了hibernate xml的解析时间。按照这个方式测试了一下，发现hibernate的启动时间从5秒降低到3秒，但是这个优化对于整个启动过程是杯水车薪的，毫无用处。</span><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><span style="COLOR: rgb(51,51,153); FONT-STYLE: italic">    没办法，又仔细查看了spring的资料，终于发现spring的容器是提供了lazy-load的，即默认的缺省设置是bean没有lazy- load，该属性处于false状态，这样导致spring在启动过程导致在启动时候，会默认加载整个对象实例图，从初始化ACTION配置、到 service配置到dao配置、乃至到数据库连接、事务等等。这么庞大的规模，难怪spring的启动时间要花将近1分钟。尝试了一下，把beans的 default-lazy-init改为true就，再次启动，速度从原来的55秒，降到8秒钟！！Great！虽然是非常小一个改动，但是影响确实非常大。一个项目组10个人，假若每个人一天平均需要在eclipse下启动测试服务器50次。那么一天项目组需要重启500次，每次节省50秒的话，就是 25000秒，将近几个小时，差不多一个工作日，多么可观的数字！</span><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><span style="COLOR: rgb(51,51,153); FONT-STYLE: italic">   不过在运行期间第一次点页面的时候，由于spring做了lazy-load，现在就需要启动一部分需要的beans，所以稍微慢2－3秒钟，但是明显比等几十秒要快很多，值得一鉴。</span><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><br style="COLOR: rgb(51,51,153); FONT-STYLE: italic" /><span style="COLOR: rgb(51,51,153); FONT-STYLE: italic">    以上是针对开发阶段的spring容器启动优化，在部署到实际环境中，倒是没必要设置为lazy-load。毕竟部署到实际环境中不是经常的事，每次启动1分钟倒不是大问题。 </span><br /><br />我这里要提醒的是不是说有的beans都能设置default-lazy-init成为true.对于scheduler的bean不能用lazy-init<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,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">beans </span>
				<span style="COLOR: rgb(255,0,0)">default-lazy-init</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 />    <br />    </span>
				<span style="COLOR: rgb(0,0,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">bean </span>
				<span style="COLOR: rgb(255,0,0)">class</span>
				<span style="COLOR: rgb(0,0,255)">="org.springframework.scheduling.quartz.SchedulerFactoryBean"</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)">property </span>
				<span style="COLOR: rgb(255,0,0)">name</span>
				<span style="COLOR: rgb(0,0,255)">="triggers"</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)">list</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="buildHtmlTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="askTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="mailSenderTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="topicDetailBuildTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="forumBuildTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="topicBuildTrigger"</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)">list</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)">property</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)">bean</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)">beans</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
		</div>
		<p>
				<br />
				<br />
				<br />这样的话。所有的scheduler就都不管用了。所以请大家要注意。<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,255)">&lt;</span>
				<span style="COLOR: rgb(128,0,0)">beans</span>
				<span style="COLOR: rgb(255,0,0)">
				</span>
				<span style="COLOR: rgb(0,0,255)">
				</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)">bean </span>
				<span style="COLOR: rgb(255,0,0)">class</span>
				<span style="COLOR: rgb(0,0,255)">="org.springframework.scheduling.quartz.SchedulerFactoryBean"</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)">property </span>
				<span style="COLOR: rgb(255,0,0)">name</span>
				<span style="COLOR: rgb(0,0,255)">="triggers"</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)">list</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="buildHtmlTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="askTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="mailSenderTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="topicDetailBuildTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="forumBuildTrigger"</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)">ref </span>
				<span style="COLOR: rgb(255,0,0)">bean</span>
				<span style="COLOR: rgb(0,0,255)">="topicBuildTrigger"</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)">list</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)">property</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)">bean</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)">beans</span>
				<span style="COLOR: rgb(0,0,255)">&gt;</span>
		</div>
		<p>
				<br /> </p><img src ="http://www.blogjava.net/rory/aggbug/62740.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-08-10 10:59 <a href="http://www.blogjava.net/rory/archive/2006/08/10/speed_up_spring_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>4</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>关于DWR2.0的配置问题</title><link>http://www.blogjava.net/rory/archive/2006/07/17/58484.html</link><dc:creator>莫多</dc:creator><author>莫多</author><pubDate>Sun, 16 Jul 2006 18:11:00 GMT</pubDate><guid>http://www.blogjava.net/rory/archive/2006/07/17/58484.html</guid><wfw:comment>http://www.blogjava.net/rory/comments/58484.html</wfw:comment><comments>http://www.blogjava.net/rory/archive/2006/07/17/58484.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/rory/comments/commentRss/58484.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/rory/services/trackbacks/58484.html</trackback:ping><description><![CDATA[<p>自从换工作之后就没有研究过DWR了。下载了最新的DWR2.0M2版本。2.0加了很多东西，也有不少变化的地方。最容易看到的变化就是包名的变化了,由 <strong>uk.ltd.getahead </strong>变成了 <strong>org.directwebremoting </strong>。<br />        换上了新的配置</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">servlet</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">servlet-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">dwr-invoker</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">servlet-class</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">org.directwebremoting.servlet.DwrServlet</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet-class</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">init-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">debug</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">true</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">init-param</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">load-on-startup</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">load-on-startup</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet</span>
				<span style="COLOR: #0000ff">&gt;</span>
		</div>
		<p>启动服务，抱错了。</p>
		<p>java.lang.IllegalArgumentExcep<wbr></wbr>tion: DefaultContainer can't find a classes<br />       at org.directwebremoting.impl<wbr></wbr>.DefaultContainer.getBean(DefaultContainer.java:216)<br />       at org.directwebremoting.annotati<wbr></wbr>ons.AnnotationsConfigurator<wbr></wbr>.configure(AnnotationsConfigurator.java:50)<br />       at org.directwebremoting.servlet<wbr></wbr>.DwrServlet.init(DwrServlet.java:121)</p>
		<p>      在DWR的Maillist里面搜索了一下，还有答案，原来DWR2.0 加入了JDK5的注释(<span class="st" id="st" name="st">annotations</span>).DwrServlet初始化的时候会去检查注释的类，找不到就抱错了。如果你不用annotations也可以忽略掉这个错误。不过看起来总是不爽。有人提出了方案。这样就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">servlet</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">servlet-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">dwr-invoker</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet-name</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">servlet-class</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">org.directwebremoting.servlet.DwrServlet</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet-class</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">init-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">debug</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">true</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">init-param</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">init-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">classes</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">java.lang.Object</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">init-param</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />        </span>
				<span style="COLOR: #0000ff">&lt;</span>
				<span style="COLOR: #800000">load-on-startup</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">100</span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">load-on-startup</span>
				<span style="COLOR: #0000ff">&gt;</span>
				<span style="COLOR: #000000">
						<br />    </span>
				<span style="COLOR: #0000ff">&lt;/</span>
				<span style="COLOR: #800000">servlet</span>
				<span style="COLOR: #0000ff">&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="" title="" href="http://leaf.jdk.cn/" target=""><font color="#6b6b52">莫多泡泡</font></a></strong>所有. <br /><font color="#ff0000">署名,非商业用途,保持一致.</font>   somebody(莫多)   </p><img src ="http://www.blogjava.net/rory/aggbug/58484.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-17 02:11 <a href="http://www.blogjava.net/rory/archive/2006/07/17/58484.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></channel></rss>