??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲成A人片在线观看WWW,亚洲视频国产精品,国产精一品亚洲二区在线播放http://m.tkk7.com/rory/Happy study,Happy work,Happy lifezh-cnMon, 12 May 2025 18:27:06 GMTMon, 12 May 2025 18:27:06 GMT60xstream对xmlnode的属?attribute)解析的问题[更新]?/title><link>http://m.tkk7.com/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://m.tkk7.com/rory/archive/2007/01/17/howto-dealwith-xstream-xmlnode-attribute.html</guid><wfw:comment>http://m.tkk7.com/rory/comments/94475.html</wfw:comment><comments>http://m.tkk7.com/rory/archive/2007/01/17/howto-dealwith-xstream-xmlnode-attribute.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://m.tkk7.com/rory/comments/commentRss/94475.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/rory/services/trackbacks/94475.html</trackback:ping><description><![CDATA[xstream是个好东ѝ对于配|文件的d很方ѝ在mybog中我qC。不q今天打用yupoo的api来做相册。发现xstream对于xmlnode的attribute解析支持不是那么的好?br />对于q种节点格式的非常的?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);"><</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">page</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">page</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">pages</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">pages</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">perpage</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">100</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">perpage</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">total</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">19</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">total</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">photos</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">photo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">ff8080810fc8ac78010fd3f158d40a52</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">id</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">owner</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">ff8080810f1a387b010f1a83d6530dfc</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">owner</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">Gmail-2</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">title</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">host</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">4</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">host</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">20061230</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">dir</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">filename</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);">231905_1463411198</span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">filename</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">photo</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">photos</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">></span></div><br />单的alias一下就可以dg<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的apiq回的xmlrpc的结果是q样?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);"><</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);">></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">photos</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);"><</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);">/></span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">photos</span><span style="color: rgb(0, 0, 255);">></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);"></</span><span style="color: rgb(128, 0, 0);">result</span><span style="color: rgb(0, 0, 255);">></span></div>q样load不到g。没法去mailist里面扄案,果然有h问?br /><pre><font color="#ff9900">Hello, I am not sure about the subject but here is what I needed help for: XML: <field name="value">I am a Field.</field> 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 />有h回答是看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);"> <a href="mailto:rory.cn@gmail.com">somebody</a><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);"><</span><span style="color: rgb(0, 0, 0);">YupooPhoto</span><span style="color: rgb(0, 0, 0);">></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);"><</span><span style="color: rgb(0, 0, 0);">YupooPhoto</span><span style="color: rgb(0, 0, 0);">></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 >http://xstream.codehaus.org/converter-tutorial.html</a></pre><br />2007q??8日更新?br />q里感谢|友 <a id="AjaxHolder_Comments_CommentList_ctl00_NameLink" target="_blank">Ivan ChenQ西滨)</a> 的提C。原来新版的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" >XStream.InitializationException</a></code> - if no <a title="class in com.thoughtworks.xstream.mapper" ><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" >XStream.InitializationException</a></code> - if no <a title="class in com.thoughtworks.xstream.mapper" ><code>AttributeMapper</code></a> is available </dd><dt><b>Since:</b></dt><dd>1.2</dd></dl></dd></dl><br />q两个方法都是从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 target="_blank"><br /><img alt="创造共用协?|名,非商?保持一? src="http://leaf.jdk.cn/rights.gif" border="0" height="31" width="88" /></a>   除经特别注明?本文章版权归<strong><a class="" ><font color="#6b6b52">莫多泡</font></a></strong>所? <br /><font color="#ff0000">|名,非商业用?保持一?</font>   <a title="莫多泡" target="_blank">somebody(莫多)</a><img src ="http://m.tkk7.com/rory/aggbug/94475.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/rory/" target="_blank">莫多</a> 2007-01-17 18:24 <a href="http://m.tkk7.com/rory/archive/2007/01/17/howto-dealwith-xstream-xmlnode-attribute.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>又是q问题-Filter 配置也很重要http://m.tkk7.com/rory/archive/2006/12/27/character_encoding_problem_filtermapping_position.html莫多莫多Wed, 27 Dec 2006 02:37:00 GMThttp://m.tkk7.com/rory/archive/2006/12/27/character_encoding_problem_filtermapping_position.htmlhttp://m.tkk7.com/rory/comments/90236.htmlhttp://m.tkk7.com/rory/archive/2006/12/27/character_encoding_problem_filtermapping_position.html#Feedback3http://m.tkk7.com/rory/comments/commentRss/90236.htmlhttp://m.tkk7.com/rory/services/trackbacks/90236.html  上周更新了一下myblog,d了一个FilterQ做l计讉K用。可是后来发现出Cؕ码问题了。找了很久都没有扑ֈ问题。debug的时候看?CharacterEncodingFilter实是执行了。不q就是没有效果。执行之前是ISO-8859-1~码的,执行之后q是Q?CharacterEncodingFilter没有vC用。后来终于找到问题的原因了。原来是Filter配置先后序的原因?br />       刚开始的配置是这L:

     < filter-mapping >
        
< filter-name > requestCounterFilter </ filter-name >
        
< url-pattern > *.jhtml </ url-pattern >
    
</ filter-mapping >
  
    
< filter-mapping >
        
< filter-name > encodingFilter </ filter-name >
        
< url-pattern > /dwr/* </ url-pattern >
    
</ filter-mapping >
    
    
< filter-mapping >
        
< filter-name > encodingFilter </ filter-name >
        
< url-pattern > *.jhtml </ url-pattern >
    
</ filter-mapping >
    
    
< filter-mapping >
        
< filter-name > encodingFilter </ filter-name >
        
< url-pattern > *.jsp </ url-pattern >
    
</ filter-mapping >

  先经q那个统计的filter然后再经q编码的filter。这L话编码的filter׃起作用了。只要吧~码的filter攑ֈ最前面没有问题了。改成这样就好?br />

     < filter-mapping >
        
< filter-name > encodingFilter </ filter-name >
        
< url-pattern > /dwr/* </ url-pattern >
    
</ filter-mapping >
    
    
< filter-mapping >
        
< filter-name > encodingFilter </ filter-name >
        
< url-pattern > *.jhtml </ url-pattern >
    
</ filter-mapping >
    
    
< filter-mapping >
        
< filter-name > encodingFilter </ filter-name >
        
< url-pattern > *.jsp </ url-pattern >
    
</ filter-mapping >
    
    
< filter-mapping >
        
< filter-name > requestCounterFilter </ filter-name >
        
< url-pattern > *.jhtml </ url-pattern >
    
</ filter-mapping >


以后大家一定要注意啊。顺序问题也是很重要的?br />创造共用协?|名,非商?保持一? src=   除经特别注明?本文章版权归莫多泡所?
|名,非商业用?保持一?   somebody(莫多)



莫多 2006-12-27 10:37 发表评论
]]>
tuckey urlrewrite 3.x的问?/title><link>http://m.tkk7.com/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://m.tkk7.com/rory/archive/2006/12/12/tuckey-urlrewrite_3-querystring-problem.html</guid><wfw:comment>http://m.tkk7.com/rory/comments/87151.html</wfw:comment><comments>http://m.tkk7.com/rory/archive/2006/12/12/tuckey-urlrewrite_3-querystring-problem.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/rory/comments/commentRss/87151.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/rory/services/trackbacks/87151.html</trackback:ping><description><![CDATA[昨天晚上配置myblog的rewrite。发C个奇怪的问题。由于现在用的q个pjblogQؓ了让搜烦引擎收录的连接有效。我x原来的aspq接rewrite到我的新E序上面。所以有q样一条规则?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)"><</span><span style="COLOR: rgb(128,0,0)">rule</span><span style="COLOR: rgb(0,0,255)">></span><span style="COLOR: rgb(0,0,0)"><br />        </span><span style="COLOR: rgb(0,0,255)"><</span><span style="COLOR: rgb(128,0,0)">from</span><span style="COLOR: rgb(0,0,255)">></span><span style="COLOR: rgb(0,0,0)">^/article.asp\?id=(.*)$</span><span style="COLOR: rgb(0,0,255)"></</span><span style="COLOR: rgb(128,0,0)">from</span><span style="COLOR: rgb(0,0,255)">></span><span style="COLOR: rgb(0,0,0)"><br />        </span><span style="COLOR: rgb(0,0,255)"><</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)">></span><span style="COLOR: rgb(0,0,0)">/entry/$1.jhtml</span><span style="COLOR: rgb(0,0,255)"></</span><span style="COLOR: rgb(128,0,0)">to</span><span style="COLOR: rgb(0,0,255)">></span><span style="COLOR: rgb(0,0,0)"><br />    </span><span style="COLOR: rgb(0,0,255)"></</span><span style="COLOR: rgb(128,0,0)">rule</span><span style="COLOR: rgb(0,0,255)">></span></div>     但是我这Lq接L匚w不到Q只要去掉那个?可以了。这个正则表辑ּ是没有问题的?article.asp?id=64是可以匹配的到的?br />    后来?.0的manual (http://tuckey.org/urlrewrite/manual/3.0/)才发现原来是q个的问题?br /><h3><urlrewrite> 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 >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 >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是?后面的都忽略了。所以就不能匚wC。只要在<urlrewrite>里面加一个属性就可以了?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)"><</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)">></span><span style="COLOR: rgb(0,0,0)"><br />    <img alt="" src="http://m.tkk7.com/images/dot.gif" /><br /></span><span style="COLOR: rgb(0,0,255)"></</span><span style="COLOR: rgb(128,0,0)">urlrewrite</span><span style="COLOR: rgb(0,0,255)">></span></div><p><a target="_blank"><img height="31" alt="创造共用协?|名,非商?保持一? src="http://leaf.jdk.cn/rights.gif" width="88" border="0" /></a>   除经特别注明?本文章版权归<strong><a class="" ><font color="#6b6b52">莫多泡</font></a></strong>所? <br /><font color="#ff0000">|名,非商业用?保持一?</font>   <a title="莫多泡" target="_blank">somebody(莫多)</a></p><img src ="http://m.tkk7.com/rory/aggbug/87151.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/rory/" target="_blank">莫多</a> 2006-12-12 10:33 <a href="http://m.tkk7.com/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.xhttp://m.tkk7.com/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.html莫多莫多Sun, 22 Oct 2006 08:12:00 GMThttp://m.tkk7.com/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.htmlhttp://m.tkk7.com/rory/comments/76628.htmlhttp://m.tkk7.com/rory/archive/2006/10/22/spring_xmlrpc3_service_exporter.html#Feedback0http://m.tkk7.com/rory/comments/commentRss/76628.htmlhttp://m.tkk7.com/rory/services/trackbacks/76628.html      我们的项目用Cxmlrpc,不过q是用的2.x版本的。由于xmlrpc3.x地推出。提供了NULL,Serializable{的支持Q将原来的HashtableҎ了Map,VectorҎ了List。都是不错的q步。所以我们决定从xmlrpc2.x升到xmlrpc3.x.
      在spring里面有几个ServiceExporterQorg.springframework.remoting.rmi.RmiServiceExporter、org.springframework.remoting.caucho.HessianServiceExporter、org.springframework.remoting.caucho.BurlapServiceExporter。不q没有xmlrpc的serviceExporterQ原来我们是自己装的XmlRpcServer,用servlet提供服务?eg:http://localhost:8080/community/service/xmlrpc)没有和spring集成虽然用了spring?br />    考虑到spring的便利以及配|的同意我决定将xmlrpcService攑օspring中。xmlrpc3.x和xmlrpc2.x的代码基本上没有一L。改了很多东ѝ除了类型变化之外,q添加了对异常的支持。详l信息请参照xmlrpc3.x源代码?br />XmlRpcServiceExporter.java

package  com.jdkcn.xmlrpc;

import  javax.servlet.ServletException;

/**
 * 
@author  <a href="mailto:rory.cn@gmail.com">somebody</a>
 * 
@since  2006-9-27 03:59:22 pm
 * 
@version  $Id XmlRpcServiceExporter.java$
 
*/
public   class  XmlRpcServiceExporter  extends  RemoteExporter  implements
        Controller, InitializingBean {
    
    
private  XmlRpcServletServer server;
    
    
public  String serviceName;
    
    
public  Resource configFile;
    
    
public  Boolean enabledForExtensions;
    
    
public   void  setEnabledForExtensions(Boolean enabledForExtensions) {
        
this .enabledForExtensions  =  enabledForExtensions;
    }

    
public   void  setConfigFile(Resource configFile) {
        
this .configFile  =  configFile;
    }

    
public  String getServiceName() {
        
return  serviceName;
    }

    
public   void  setServiceName(String serviceName) {
        
this .serviceName  =  serviceName;
    }

    
public  XmlRpcServletServer getXmlRpcServletServer() {
        
return  server;
    }
    
    
/*  (non-Javadoc)
     * @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     
*/
    
public  ModelAndView handleRequest(HttpServletRequest request,
            HttpServletResponse response) 
throws  Exception {
        
if  ( ! WebContentGenerator.METHOD_POST.equals(request.getMethod())) {
            
throw   new  ServletException( " XmlRpcServiceExporter only supports POST requests " );
        }
        server.execute(request, response);
        
return   null ;
    }

    
/*  (non-Javadoc)
     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
     
*/
    
public   void  afterPropertiesSet()  throws  Exception {
        server 
=   new  XmlRpcServletServer();
        server.setHandlerMapping(newXmlRpcHandlerMapping());
        
if  (enabledForExtensions != null ) {
            ((XmlRpcServerConfigImpl) server.getConfig()).setEnabledForExtensions(enabledForExtensions.booleanValue());
        }
        
    }

    
/**  Creates a new handler mapping. The default implementation loads
     * a property file from the resource
     * 
     
*/
    
protected  XmlRpcHandlerMapping newXmlRpcHandlerMapping()  throws  XmlRpcException {
        
        SpringHandlerMapping mapping 
=   new  SpringHandlerMapping(getServiceInterface());
        mapping.addHandler(getServiceName(), getServiceInterface());
        mapping.setTagetObject(getProxyForService());
        
return  mapping;
    }
    
}

spring配置文g
    <bean id="accountService"  class="com.jdkcn.service.impl.AccountServiceImpl">
    
</bean>
        
<bean name="rpcAccountService" class="com.jdkcn.xmlrpc.XmlRpcServiceExporter">
        
<property name="service">
            
<ref bean="accountService"/>
        
</property>
        
<property name="serviceName">
            
<value>jdkcn.accountService</value>
        
</property>
        
<property name="enabledForExtensions">
            
<value>true</value>
        
</property>
        
<property name="serviceInterface">
            
<value>com.jdkcn.service.AccountService</value>
        
</property>
    
</bean>
然后映射一个地址可以通过xmlrpc讉K服务?br />
    <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        
<property name="mappings">
            
<props> 
                
<prop key="/account">rpcAccountService</prop>
            
</props>
        
</property>
    
</bean>
web.xml
    <context-param>
        
<param-name>contextConfigLocation</param-name>
        
<param-value>
            classpath:spring/global.xml
        
</param-value>
    
</context-param>
    
    
<listener>
        
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    
</listener>

        
<servlet>
            
<servlet-name>service</servlet-name>
            
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        
</servlet>

        
<servlet-mapping>
            
<servlet-name>service</servlet-name>
            
<url-pattern>/service/xmlrpc3/*</url-pattern>
        
</servlet-mapping>
然后我们的service地址是q样的http://localhost:8080/service/xmlrpc3/account

希望对大家有用,q里提供project下蝲。包含一个clientE序。com.jdkcn.xmlrpc.Client

点击下蝲完整代码

创造共用协?|名,非商?保持一? src=   除经特别注明?本文章版权归莫多泡所?
|名,非商业用?保持一?   somebody(莫多)

莫多 2006-10-22 16:12 发表评论
]]>
关于Hibernate3的escape解决Ҏhttp://m.tkk7.com/rory/archive/2006/10/16/hibernate3_escape.html莫多莫多Mon, 16 Oct 2006 15:29:00 GMThttp://m.tkk7.com/rory/archive/2006/10/16/hibernate3_escape.htmlhttp://m.tkk7.com/rory/comments/75503.htmlhttp://m.tkk7.com/rory/archive/2006/10/16/hibernate3_escape.html#Feedback1http://m.tkk7.com/rory/comments/commentRss/75503.htmlhttp://m.tkk7.com/rory/services/trackbacks/75503.html
SELECT * FROM t_user where nickname like '%Goo\_D' escape '\'
q里对_q行转义了。因为用hU包含下划线Q如果不q行转义pCZ个Q意字W。有时候我们可能还需要对%q行转义。同LҎ?前加\% 但是比v普通的like语句。多了一个声明{义符的语句。所以我们会惛_q样的语?br />
DetachedCriteria criteria = DetachedCriteria.forClass(User.class);
criteria.add(Restrictions.like(
"nickname", user.getNickname()+"' escape'\"));
但是q样是不用的?br />接下来可能会惛_使用Hibernate3的原生sql查询Q其实我们不需要这样做。我们还是用Criteria条g查询?br />
criteria.add(Restrictions.sqlRestriction("{alias}.nickname like ? escape'/'", StringUtil.escapeSQLLike(user.getNickname()), Hibernate.STRING));
q样Hibernate产生的语句就是我们想要的语句了?br />
    /**
     * 转义like语句中的
     * <code>'_'</code><code>'%'</code>
     * ?lt;code>'?'</code>转成sql?lt;code>'/_'</code>
     * ?lt;code>'%'</code>转成sql?lt;code>'/%'</code>
     * <p>
     *   例如搜烦<code>?aa*bb?c_d%f</code>{化成<br/>
     *   <code>_aa%bb_c/_d/%f</code>
     * </p>
     * 
@param likeStr
     * 
@return
     * 
@author <a href="http://jdkcn.com">somebody</a>
     
*/
    
public static String escapeSQLLike(String likeStr) {
        String str 
= StringUtils.replace(likeStr, "_""/_");
        str 
= StringUtils.replace(str, "%",    "/%");
        str 
= StringUtils.replace(str, "?""_");
        str 
= StringUtils.replace(str, "*""%");
        
return str;
    }

创造共用协?|名,非商?保持一? src=   除经特别注明?本文章版权归莫多泡所?
|名,非商业用?保持一?   somebody(莫多)

莫多 2006-10-16 23:29 发表评论
]]>
关于spring启动的优化的问题http://m.tkk7.com/rory/archive/2006/08/10/speed_up_spring_problem.html莫多莫多Thu, 10 Aug 2006 02:59:00 GMThttp://m.tkk7.com/rory/archive/2006/08/10/speed_up_spring_problem.htmlhttp://m.tkk7.com/rory/comments/62740.htmlhttp://m.tkk7.com/rory/archive/2006/08/10/speed_up_spring_problem.html#Feedback2http://m.tkk7.com/rory/comments/commentRss/62740.htmlhttp://m.tkk7.com/rory/services/trackbacks/62740.html  jspark 的这文章?a class="postTitle2" id="viewpost1_TitleUrl" href="/jspark/archive/2006/07/29/60712.html">开发阶Declipse下面的spring容器的启动优?/a> 》讲到如何加快spring的启动速度。非常感?span style="FONT-WEIGHT: bold">jspark. 一下是引用的原文:

  最q在负责一个大目Q项目组成员包括目l理大概10个h左右。项目技术用struts+spring+hibernate实现。项目的规模相对来说是比较大的,d?0大模块,每个大模块又分ؓ有十几个、甚臛_十个模块。开发工LeclipseQ由于在开发阶D,目开发成员需要频J重启服务器。在启动服务器的时候,每次启动旉L会超q?分钟。记得以前在做另外一个项目时Q启动时间不?U钟Q相差了10倍,而且目规模是差不多的?/span>

    从初步分析来_应该是hibernate解释hbm.xml时花Ҏ_或者可能是spring容器启动q解释所有的bean配置文g。诊断了一下,发现1分钟消耗的旉主要分布在hibernate解释hbm.xmlp5U;spring容器从启动到解释bean配置文g竟然׃58U,真是太嚣张了。当旉常怀疑spring的效率问题。企图从|上搜烦相关资料Q看看有什么优化措施?/span>

    首先是找Chibernate的启动优?http://www.hibernate.org/194.html  里面的主要思想是通过xml序列花到本地的文仉Q每ơ读取的时候根据情况,从本地文件读取ƈ反序列化Q节省了hibernate xml的解析时间。按照这个方式测试了一下,发现hibernate的启动时间从5U降低到3U,但是q个优化对于整个启动q程是杯水R薪的Q毫无用处?/span>

    没办法,又仔l查看了spring的资料,l于发现spring的容器是提供了lazy-load的,即默认的~省讄是bean没有lazy- loadQ该属性处于false状态,q样Dspring在启动过E导致在启动时候,会默认加载整个对象实例图Q从初始化ACTION配置、到 service配置到dao配置、乃臛_数据库连接、事务等{。这么庞大的规模Q难怪spring的启动时间要花将q?分钟。尝试了一下,把beans?default-lazy-init改ؓtrue,再次启动Q速度从原来的55U,降到8U钟Q!GreatQ虽然是非常一个改动,但是影响实非常大。一个项目组10个hQ假若每个h一天^均需要在eclipse下启动测试服务器50ơ。那么一天项目组需要重?00ơ,每次节省50U的话,是 25000U,近几个时Q差不多一个工作日Q多么可观的数字Q?/span>

   不过在运行期间第一ơ点面的时候,׃spring做了lazy-loadQ现在就需要启动一部分需要的beansQ所以稍微慢2Q?U钟Q但是明显比{几十秒要快很多Q值得一鉴?/span>

    以上是针对开发阶D늚spring容器启动优化Q在部v到实际环境中Q倒是没必要设|ؓlazy-load。毕竟部|到实际环境中不是经常的事,每次启动1分钟倒不是大问题?

我这里要提醒的是不是说有的beans都能讄default-lazy-init成ؓtrue.对于scheduler的bean不能用lazy-init

< beans  default-lazy-init ="true" >
    
    
< bean  class ="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
        
< property  name ="triggers" >
            
< list >
                
< ref  bean ="buildHtmlTrigger" />
                
< ref  bean ="askTrigger" />
                
< ref  bean ="mailSenderTrigger" />
                
< ref  bean ="topicDetailBuildTrigger" />
                
< ref  bean ="forumBuildTrigger" />
                
< ref  bean ="topicBuildTrigger" />
            
</ list >
        
</ property >
    
</ bean >
</ beans >




q样的话。所有的scheduler都不管用了。所以请大家要注意?br />

< beans >
    
    
< bean  class ="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
        
< property  name ="triggers" >
            
< list >
                
< ref  bean ="buildHtmlTrigger" />
                
< ref  bean ="askTrigger" />
                
< ref  bean ="mailSenderTrigger" />
                
< ref  bean ="topicDetailBuildTrigger" />
                
< ref  bean ="forumBuildTrigger" />
                
< ref  bean ="topicBuildTrigger" />
            
</ list >
        
</ property >
    
</ bean >
</ beans >


 



莫多 2006-08-10 10:59 发表评论
]]>
q是q问题http://m.tkk7.com/rory/archive/2006/07/22/59567.html莫多莫多Sat, 22 Jul 2006 10:13:00 GMThttp://m.tkk7.com/rory/archive/2006/07/22/59567.htmlhttp://m.tkk7.com/rory/comments/59567.htmlhttp://m.tkk7.com/rory/archive/2006/07/22/59567.html#Feedback4http://m.tkk7.com/rory/comments/commentRss/59567.htmlhttp://m.tkk7.com/rory/services/trackbacks/59567.html     虽然目全部采用了UTF-8~码Q所有的源文?.java,*.jsc,*.html,*.ftl都采用了UTF-8~码。可是还是出Cq问题。很是不爽,后来扑ֈ了tomcatQ和resin的配|?/p>
  1. Tomcat的配|?conf/server.xml)
        <!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
        
    <Connector port="80" maxHttpHeaderSize="8192"
                   maxThreads
    ="150" minSpareThreads="25" maxSpareThreads="75"
                   enableLookups
    ="false" redirectPort="8443" acceptCount="100"
                   connectionTimeout
    ="20000" disableUploadTimeout="true" URIEncoding="UTF-8"/>
  2. Resin的配|?conf/resin.conf)

    character-encoding

    Resin 1.1
    child of: resin, server, host-default, host, web-app-default, web-app
    default: The default value is ISO-8859-1.

    Specifies the default character encoding for the environment.

    <web-app id='/'>
      <character-encoding>shift_jis</character-encoding>
      ...
    
    </web-app>
    

     q个是resin doc里面的我是在web-app-default里面加上了encoding的配|?/p>

     < web-app-default >
      
< character-encoding > UTF-8 </ character-encoding >
      
    
</ web-app-default >

希望对你的项目有帮助?/p>

创造共用协?|名,非商?保持一? src=    除经特别注明?本文章版权归莫多泡所?
|名,非商业用?保持一?   somebody(莫多)  



莫多 2006-07-22 18:13 发表评论
]]>
关于Resin虚拟目录配置的问?/title><link>http://m.tkk7.com/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://m.tkk7.com/rory/archive/2006/07/18/58838.html</guid><wfw:comment>http://m.tkk7.com/rory/comments/58838.html</wfw:comment><comments>http://m.tkk7.com/rory/archive/2006/07/18/58838.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/rory/comments/commentRss/58838.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/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"><!--</span><span style="COLOR: #008000"> configures the default host, matching any host name </span><span style="COLOR: #008000">--></span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff"><</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">></span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #008000"><!--</span><span style="COLOR: #008000"><br />         - configures an explicit root web-app matching the<br />         - webapp's ROOT<br />        </span><span style="COLOR: #008000">--></span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #0000ff"><</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">/></span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #0000ff"><</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">/></span><span style="COLOR: #000000"><br />      </span><span style="COLOR: #0000ff"><</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">/></span><span style="COLOR: #000000"><br />    </span><span style="COLOR: #0000ff"></</span><span style="COLOR: #800000">host</span><span style="COLOR: #0000ff">></span></div><p>       但是发现q样只有后面一个管?<a href="http://localhost:8080/passport/jsvm2">http://localhost:8080/passport/jsvm2</a>)q个是可?可是(<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 id="7b19r7t" 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 id="rdphzjv" class="meta">url-pattern</span></td><td>A pattern matching the url: <span id="nh7n99d" class="meta">/foo/*</span>, <span id="rr9xfdf" class="meta">/foo</span>, or <span id="99jhl9f" 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 id="hhxtn9l" class="meta">url-regexp</span>, allows substitution variables like <span id="rhnpbd9" 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><web-app id='/'> <path-mapping url-pattern='/resin/*' real-path='e:\resin'/> <path-mapping url-regexp='/~([^/]*)' real-path='e:\home$1'/> </web-app> </pre></td></tr></tbody></table></div><p>Ҏq样的配|就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"><</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">></span><span style="COLOR: #000000"><br />          </span><span style="COLOR: #0000ff"><</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'/><br />      </span><span style="COLOR: #ff0000"></web-app</span><span style="COLOR: #0000ff">></span><span style="COLOR: #000000"><br />      <br />            </span><span style="COLOR: #0000ff"><</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">></span><span style="COLOR: #000000"><br />          </span><span style="COLOR: #0000ff"><</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'/><br />      </span><span style="COLOR: #ff0000"></web-app</span><span style="COLOR: #0000ff">></span></div><a target="_blank"><img height="31" alt="创造共用协?|名,非商?保持一? src="http://leaf.jdk.cn/rights.gif" width="88" border="0" /></a>   除经特别注明?本文章版权归<strong><a class="" title="" target=""><font color="#6b6b52">莫多泡</font></a></strong>所? <br /><font color="#ff0000">|名,非商业用?保持一?</font>   somebody(莫多)<img src ="http://m.tkk7.com/rory/aggbug/58838.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/rory/" target="_blank">莫多</a> 2006-07-18 19:41 <a href="http://m.tkk7.com/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://m.tkk7.com/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://m.tkk7.com/rory/archive/2006/07/17/58484.html</guid><wfw:comment>http://m.tkk7.com/rory/comments/58484.html</wfw:comment><comments>http://m.tkk7.com/rory/archive/2006/07/17/58484.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/rory/comments/commentRss/58484.html</wfw:commentRss><trackback:ping>http://m.tkk7.com/rory/services/trackbacks/58484.html</trackback:ping><description><![CDATA[<p>自从换工作之后就没有研究qDWR了。下载了最新的DWR2.0M2版本?.0加了很多东西Q也有不变化的地方。最Ҏ看到的变化就是包名的变化??<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"><</span> <span style="COLOR: #800000">servlet</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">servlet-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">dwr-invoker</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">servlet-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">servlet-class</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">org.directwebremoting.servlet.DwrServlet</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">servlet-class</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">init-param</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />          </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">param-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">debug</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">param-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />          </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">param-value</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">true</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">param-value</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">init-param</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">load-on-startup</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">1</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">load-on-startup</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />    </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">servlet</span> <span style="COLOR: #0000ff">></span> </div> <p>启动服务Q抱错了?/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里面搜烦了一下,q有{案Q原来DWR2.0 加入了JDK5的注?<span id="hrt7n99" class="st" id="st" name="st">annotations</span>).DwrServlet初始化的时候会L查注释的c,找不到就抱错了。如果你不用annotations也可以忽略掉q个错误。不q看hL不爽。有人提ZҎ。这样就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"><</span> <span style="COLOR: #800000">servlet</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">servlet-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">dwr-invoker</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">servlet-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">servlet-class</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">org.directwebremoting.servlet.DwrServlet</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">servlet-class</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">init-param</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />          </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">param-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">debug</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">param-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />          </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">param-value</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">true</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">param-value</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">init-param</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">init-param</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />           </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">param-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">classes</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">param-name</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />           </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">param-value</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">java.lang.Object</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">param-value</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">init-param</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />        </span> <span style="COLOR: #0000ff"><</span> <span style="COLOR: #800000">load-on-startup</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000">100</span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">load-on-startup</span> <span style="COLOR: #0000ff">></span> <span style="COLOR: #000000"> <br />    </span> <span style="COLOR: #0000ff"></</span> <span style="COLOR: #800000">servlet</span> <span style="COLOR: #0000ff">></span> </div> <p> <a target="_blank"> <img height="31" alt="创造共用协?|名,非商?保持一? src="http://leaf.jdk.cn/rights.gif" width="88" border="0" /> </a>   除经特别注明?本文章版权归<strong><a class="" title="" target=""><font color="#6b6b52">莫多泡</font></a></strong>所? <br /><font color="#ff0000">|名,非商业用?保持一?</font>   somebody(莫多)   </p><img src ="http://m.tkk7.com/rory/aggbug/58484.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/rory/" target="_blank">莫多</a> 2006-07-17 02:11 <a href="http://m.tkk7.com/rory/archive/2006/07/17/58484.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关于Freemarker生成静态文件的问题http://m.tkk7.com/rory/archive/2006/06/21/54134.html莫多莫多Wed, 21 Jun 2006 02:46:00 GMThttp://m.tkk7.com/rory/archive/2006/06/21/54134.htmlhttp://m.tkk7.com/rory/comments/54134.htmlhttp://m.tkk7.com/rory/archive/2006/06/21/54134.html#Feedback0http://m.tkk7.com/rory/comments/commentRss/54134.htmlhttp://m.tkk7.com/rory/services/trackbacks/54134.html使用FreeMarker生成Html静态文?实例)?br />      在我们的目中也用到了Freemarker生成静态文件。不q这里我要说的是~码的问题。我们的目使用的都是UTF-8~码Q我直接使用 飞云侠 提供的方法生成的文g在UTF-8~码下察看是qQ而GBK正常(后来发现因ؓ我用的中文操作系l所以用GBK查看正常)?br />      当然我把Freemarker的配|都Ҏ了UTF-8Q我的模版文件也是UTF-8~码的。下面是原来的代?br />
    public void setTemplatePath(Resource templatePath) {
        
this.templatePath = templatePath;
        
//讄freemarker的参?/span>
        freemarkerCfg = new Configuration();
        
try {
            freemarkerCfg.setDirectoryForTemplateLoading(
this.templatePath.getFile());
            freemarkerCfg.setObjectWrapper(
new DefaultObjectWrapper());
            freemarkerCfg.setDefaultEncoding(
"UTF-8");
        } 
catch (IOException ex) {
            
throw new SystemException("No Directory found,please check you config.");
        }
    }
    /**
     * 生成静态文?br />     * 
@param templateFileName 模版名称eg:(biz/order.ftl)
     * 
@param propMap 用于处理模板的属性Object映射 
     * 
@param htmlFilePath 要生成的静态文件的路径,相对讄中的根\?例如 "/biz/2006/5/" 
     * 
@param htmlFileName 要生成的文g?例如 "123.htm" 
     * 
@return
     
*/
    
private boolean buildHtml(String templateFileName,Map propMap, String htmlFilePath,String htmlFileName){
        
try {
            Template template 
= freemarkerCfg.getTemplate(templateFileName);
            template.setEncoding(
"UTF-8");
            
//创徏生成文g目录
            creatDirs(buildPath.getFilename(),htmlFilePath);
            File htmlFile 
= new File(buildPath + htmlFilePath + htmlFileName);
            Writer out 
= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile)));
            template.process(propMap,out);
            out.flush();
            
return true;
        } 
catch (TemplateException ex){
            log.error(
"Build Error"+templateFileName,ex);
            
return false;
        } 
catch (IOException e) {
            log.error(
"Build Error"+templateFileName,e);
            
return false;
        }
        
    }
下面是修改之后的代码
    /**
     * 生成静态文?br />     * 
@param templateFileName 模版名称eg:(biz/order.ftl)
     * 
@param propMap 用于处理模板的属性Object映射 
     * 
@param htmlFilePath 要生成的静态文件的路径,相对讄中的根\?例如 "/biz/2006/5/" 
     * 
@param htmlFileName 要生成的文g?例如 "123.htm" 
     * 
@return
     
*/
    
private boolean buildHtml(String templateFileName,Map propMap, String htmlFilePath,String htmlFileName){
        
try {
            Template template 
= freemarkerCfg.getTemplate(templateFileName);
            template.setEncoding(
"UTF-8");
            
//创徏生成文g目录
            creatDirs(buildPath.getFilename(),htmlFilePath);
            File htmlFile 
= new File(buildPath + htmlFilePath + htmlFileName);
            Writer out 
= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(htmlFile),"UTF-8"));
            template.process(propMap,out);
            out.flush();
            
return true;
        } 
catch (TemplateException ex){
            log.error(
"Build Error"+templateFileName,ex);
            
return false;
        } 
catch (IOException e) {
            log.error(
"Build Error"+templateFileName,e);
            
return false;
        }
        
    }
原因在于OutputStreamWriter的不同构造方?br />
OutputStreamWriter(OutputStream out)
          创徏使用默认字符~码?OutputStreamWriter?br />
OutputStreamWriter(OutputStream out, String charsetName)
          创徏使用指定字符集的 OutputStreamWriter?br />
 
q个是中文JDK的文档说明,刚开始我使用默认的构造函敎ͼ所以用了pȝ默认的编码,GBKQ所以在生成静态文件的时候把UTF-8内容用GBK~码写入了,所以在UTF-8下浏览就有问题?br />
q有关于修改模版文g同样也要注意q个问题?br />
    public String loadTemplate(String templateName) {
        StringBuffer sb 
= new StringBuffer();
        
try {
            File file 
= new File(templatePath+"/"+templateName);
            BufferedReader reader 
= new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
            String line 
= reader.readLine();
            
while(line != null)    {
                sb.append(line);
                sb.append(
"\r\n");
                line 
= reader.readLine();
            }
            reader.close();
        } 
catch (IOException e) {
            
throw new SystemException("Loading template Error:",e);
        }
        
return sb.toString();
    }
    public void saveTemplate(String templateName, String templateContent) {
        
try {
            File file 
= new File(templatePath + "/" + templateName);
            Writer out 
= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file),"UTF-8"));
            out.write(templateContent);
            out.flush();
            
//扔出templatesave事g
            TemplateSaveEvent evt = new TemplateSaveEvent();
            evt.setTemplateName(templateName);
            dispatchTemplateEvent(evt);
        } 
catch (IOException e) {
            
throw new SystemException("Write template Error",e);
        }
    }



莫多 2006-06-21 10:46 发表评论
]]>
վ֩ģ壺 ĻAV߾Ʒѹۿ| 2022Ļ| ձŷɫƵ߲ | 18ɽƵվ| ҹ߲| ޾Ʒ߹ۿ| þۺϹ׾Ʒ | aһƬ| ˾þô߽槼| ĻѾþ99| eeuss| ҹ޾Ʒ| ŷ޹Ʒ㽶| ŮƵ77777 | ˳վþ99ȹ| ѿֻվ| ܲƵ| Ƶһ| պɬɬҹ˽ӰԺ| ŷɫƵ߹ۿ| һƵ| ձһ߲Ͷ| þ޾Ʒ| ҹƷþ| 2019Ļmvѿ| Ʒһ16| պa| ˳ɻ߹ۿ| ޳AVƬ߹ۻ| ؼƬѿ| ŮˬˬˬˬˬƵ| ŮҰbbwbbw| պëƬһƵ| ˾þô߽AV| ޾ƷŮþþþ9999| ޸岻߹ۿ| ۺ| պһƵ| Ƶ| ߹ۿƵ| jjizzȫѿƬ|