﻿<?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-alancxx-文章分类-openSource</title><link>http://www.blogjava.net/alancxx/category/46451.html</link><description>------简单就是美</description><language>zh-cn</language><lastBuildDate>Mon, 30 May 2011 05:13:55 GMT</lastBuildDate><pubDate>Mon, 30 May 2011 05:13:55 GMT</pubDate><ttl>60</ttl><item><title>Hadoop介绍</title><link>http://www.blogjava.net/alancxx/articles/350080.html</link><dc:creator>蜂鸟</dc:creator><author>蜂鸟</author><pubDate>Thu, 12 May 2011 03:14:00 GMT</pubDate><guid>http://www.blogjava.net/alancxx/articles/350080.html</guid><wfw:comment>http://www.blogjava.net/alancxx/comments/350080.html</wfw:comment><comments>http://www.blogjava.net/alancxx/articles/350080.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/alancxx/comments/commentRss/350080.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/alancxx/services/trackbacks/350080.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 12px; color: rgb(0,51,51); font-family: Georgia; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px"><span style="font-size: 14pt">这里先大致介绍一下Hadoop.<br />
&nbsp;&nbsp;&nbsp; 本文大部分内容都是从官网</span><a title="Hadoop" style="color: rgb(95,158,160); text-decoration: none" href="http://lucene.apache.org/hadoop"><span style="font-size: 14pt">Hadoop</span></a><span style="font-size: 14pt">上来的。其中有一篇</span><a title="介绍HDFS的pdf文档" style="color: rgb(95,158,160); text-decoration: none" href="http://lucene.apache.org/hadoop/hdfs_design.pdf"><span style="font-size: 14pt">介绍HDFS的pdf文档</span></a><span style="font-size: 14pt">，里面对Hadoop介绍的比较全面了。我的这一个系列的Hadoop学习笔记也是从</span><a title="这里" style="color: rgb(95,158,160); text-decoration: none" href="http://wiki.apache.org/lucene-hadoop/GettingStartedWithHadoop"><span style="font-size: 14pt">这里</span></a><span style="font-size: 14pt">一步一步进行下来的，同时又参考了网上的很多文章，对学习Hadoop中遇到的问题进行了归纳总结。<br />
&nbsp;&nbsp;&nbsp; 言归正传，先说一下Hadoop的来龙去脉。谈到Hadoop就不得不提到</span><a title="Lucene" style="color: rgb(95,158,160); text-decoration: none" href="http://lucene.apache.org/"><span style="font-size: 14pt">Lucene</span></a><span style="font-size: 14pt">和</span><a title="Nutch" style="color: rgb(95,158,160); text-decoration: none" href="http://lucene.apache.org/nutch/"><span style="font-size: 14pt">Nutch</span></a><span style="font-size: 14pt">。首先，<span style="color: rgb(0,0,255)">Lucene并不是一个应用程序，而是提供了一个纯Java的高性能全文索引引擎工具包</span>，它可以方便的嵌入到各种实际应用中实现全文搜索/索引功能。<span style="color: rgb(0,0,255)">Nutch是一个应用程序，是一个以Lucene为基础实现的搜索引擎应用</span>，Lucene 为Nutch提供了文本搜索和索引的API，Nutch不光有搜索的功能，还有数据抓取的功能。在nutch0.8.0版本之前，Hadoop还属于 Nutch的一部分，而从nutch0.8.0开始，将其中实现的NDFS和MapReduce剥离出来成立一个新的开源项目，这就是Hadoop，而 nutch0.8.0版本较之以前的Nutch在架构上有了根本性的变化，那就是完全构建在Hadoop的基础之上了。在Hadoop中实现了 Google的GFS和MapReduce算法，使Hadoop成为了一个分布式的计算平台。<br />
&nbsp;&nbsp;&nbsp;其实，Hadoop并不仅仅是一个用于存储的分布式文件系统，而是设计用来在由通用计算设备组成的大型集群上执行分布式应用的框架。<br />
<br />
&nbsp;&nbsp;&nbsp;<span style="color: rgb(0,0,255)">Hadoop包含两个部分：</span><br />
<br />
&nbsp;&nbsp;&nbsp;<strong>1、HDFS<br />
</strong><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;即Hadoop Distributed File System (Hadoop分布式文件系统)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HDFS 具有高容错性，并且可以被部署在低价的硬件设备之上。HDFS很适合那些有大数据集的应用，并且提供了对数据读写的高吞吐率。HDFS是一个 master/slave的结构，就通常的部署来说，在master上只运行一个Namenode，而在每一个slave上运行一个Datanode。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HDFS 支持传统的层次文件组织结构，同现有的一些文件系统在操作上很类似，比如你可以创建和删除一个文件，把一个文件从一个目录移到另一个目录，重命名等等操 作。Namenode管理着整个分布式文件系统，对文件系统的操作（如建立、删除文件和文件夹）都是通过Namenode来控制。&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;下面是HDFS的结构：</span><br />
<div align="center">
<div align="center"><img height="645" alt="" src="http://www.cnblogs.com/images/cnblogs_com/wayne1017/HDFSArch.JPG" width="861" border="0" /></div>
</div>
<br />
<span style="font-size: 14pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;从上面的图中可以看 出，Namenode，Datanode，Client之间的通信都是建立在TCP/IP的基础之上的。当Client要执行一个写入的操作的时候，命令 不是马上就发送到Namenode，Client首先在本机上临时文件夹中缓存这些数据，当临时文件夹中的数据块达到了设定的Block的值（默认是 64M）时，Client便会通知Namenode，Namenode便响应Client的RPC请求，将文件名插入文件系统层次中并且在 Datanode中找到一块存放该数据的block，同时将该Datanode及对应的数据块信息告诉Client，Client便这些本地临时文件夹中 的数据块写入指定的数据节点。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;HDFS采取了副本策略，其目的是为了提高系统的可靠性，可用性。HDFS的副本放置策略是三个副本， 一个放在本节点上，一个放在同一机架中的另一个节点上，还有一个副本放在另一个不同的机架中的一个节点上。当前版本的hadoop0.12.0中还没有实 现，但是正在进行中，相信不久就可以出来了。<br />
<br />
&nbsp;&nbsp;&nbsp;<strong>2、MapReduce的实现<br />
</strong><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><a title="MapReduce" style="color: rgb(95,158,160); text-decoration: none" href="http://labs.google.com/papers/mapreduce.html"><span style="font-size: 14pt">MapReduce</span></a><span style="font-size: 14pt">是Google 的一项重要技术，它是一个编程模型，用以进行大数据量的计算。对于大数据量的计算，通常采用的处理手法就是并行计算。至少现阶段而言，对许多开发人员来 说，并行计算还是一个比较遥远的东西。MapReduce就是一种简化并行计算的编程模型，它让那些没有多少并行计算经验的开发人员也可以开发并行应用。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MapReduce的名字源于这个模型中的两项核心操作：Map和 Reduce。也许熟悉Functional Programming（</span><a title="函数式编程" style="color: rgb(95,158,160); text-decoration: none" href="http://chn.blogbeta.com/232.html"><span style="font-size: 14pt">函数式编程</span></a><span style="font-size: 14pt">） 的人见到这两个词会倍感亲切。简单的说来，Map是把一组数据一对一的映射为另外的一组数据，其映射的规则由一个函数来指定，比如对[1, 2, 3, 4]进行乘2的映射就变成了[2, 4, 6, 8]。Reduce是对一组数据进行归约，这个归约的规则由一个函数指定，比如对[1, 2, 3, 4]进行求和的归约得到结果是10，而对它进行求积的归约结果是24。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;关于MapReduce的内容，建议看看孟岩的这篇</span><a title="MapReduce:The free lunch is not over!" style="color: rgb(95,158,160); text-decoration: none" href="http://www.mengyan.org/blog/archives/2006/11/15/138.html"><span style="font-size: 14pt">MapReduce:The Free Lunch Is Not Over!</span></a><br />
<br />
<span style="font-size: 14pt">&nbsp;&nbsp;&nbsp;好了，作为这个系列的第一篇就写这么多了，我也是刚开始接触Hadoop，下一篇就是讲Hadoop的部署，谈谈我在部署Hadoop时遇到的问题，也给大家一个参考，少走点弯路。</span></span></span>
<img src ="http://www.blogjava.net/alancxx/aggbug/350080.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/alancxx/" target="_blank">蜂鸟</a> 2011-05-12 11:14 <a href="http://www.blogjava.net/alancxx/articles/350080.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Spring中的ServletContext使用</title><link>http://www.blogjava.net/alancxx/articles/349896.html</link><dc:creator>蜂鸟</dc:creator><author>蜂鸟</author><pubDate>Tue, 10 May 2011 02:02:00 GMT</pubDate><guid>http://www.blogjava.net/alancxx/articles/349896.html</guid><wfw:comment>http://www.blogjava.net/alancxx/comments/349896.html</wfw:comment><comments>http://www.blogjava.net/alancxx/articles/349896.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/alancxx/comments/commentRss/349896.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/alancxx/services/trackbacks/349896.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 12px; color: rgb(61,32,14); line-height: 20px; font-family: Georgia; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">
<p style="line-height: normal">Spring 不但提供了一个功能全面的应用开发框架，本身还拥有众多可以在程序编写时直接使用的工具类，您不但可以在 Spring 应用中使用这些工具类，也可以在其它的应用中使用，这些工具类中的大部分是可以在脱离 Spring 框架时使用的。了解 Spring 中有哪些好用的工具类并在程序编写时适当使用，将有助于提高开发效率、增强代码质量。</p>
<p style="line-height: normal">在这个分为两部分的文章中，我们将从众多的 Spring 工具类中遴选出那些好用的工具类介绍给大家。第 1 部分将介绍与文件资源操作和 Web 相关的工具类。在 第 2 部分 中将介绍特殊字符转义和方法入参检测工具类。</p>
<p style="line-height: normal">文件资源操作</p>
<p style="line-height: normal">文件资源的操作是应用程序中常见的功能，如当上传一个文件后将其保存在特定目录下，从指定地址加载一个配置文件等等。我们一般使用 JDK 的 I/O 处理类完成这些操作，但对于一般的应用程序来说，JDK 的这些操作类所提供的方法过于底层，直接使用它们进行文件操作不但程序编写复杂而且容易产生错误。相比于 JDK 的 File，Spring 的 Resource 接口（资源概念的描述接口）抽象层面更高且涵盖面更广，Spring 提供了许多方便易用的资源操作工具类，它们大大降低资源操作的复杂度，同时具有更强的普适性。这些工具类不依赖于 Spring 容器，这意味着您可以在程序中象一般普通类一样使用它们。</p>
<p style="line-height: normal">加载文件资源</p>
<p style="line-height: normal">Spring 定义了一个 org.springframework.core.io.Resource 接口，Resource 接口是为了统一各种类型不同的资源而定义的，Spring 提供了若干 Resource 接口的实现类，这些实现类可以轻松地加载不同类型的底层资源，并提供了获取文件名、URL 地址以及资源内容的操作方法。</p>
<p style="line-height: normal">访问文件资源</p>
<p style="line-height: normal">假设有一个文件地位于 Web 应用的类路径下，您可以通过以下方式对这个文件资源进行访问：</p>
<p style="line-height: normal">通过 FileSystemResource 以文件系统绝对路径的方式进行访问；<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
通过 ClassPathResource 以类路径的方式进行访问；<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
通过 ServletContextResource 以相对于Web应用根目录的方式进行访问。<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
相比于通过 JDK 的 File 类访问文件资源的方式，Spring 的 Resource 实现类无疑提供了更加灵活的操作方式，您可以根据情况选择适合的 Resource 实现类访问资源。下面，我们分别通过 FileSystemResource 和 ClassPathResource 访问同一个文件资源：</p>
<p style="line-height: normal"><br style="line-height: normal" />
清单 1. FileSourceExample<br style="line-height: normal" />
package com.baobaotao.io;<br style="line-height: normal" />
import java.io.IOException;<br style="line-height: normal" />
import java.io.InputStream;<br style="line-height: normal" />
import org.springframework.core.io.ClassPathResource;<br style="line-height: normal" />
import org.springframework.core.io.FileSystemResource;<br style="line-height: normal" />
import org.springframework.core.io.Resource;<br style="line-height: normal" />
public class FileSourceExample {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String filePath =<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "D:/masterSpring/chapter23/webapp/WEB-INF/classes/conf/file1.txt";<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ① 使用系统文件路径方式加载文件<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Resource res1 = new FileSystemResource(filePath);<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ② 使用类路径方式加载文件<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Resource res2 = new ClassPathResource("conf/file1.txt");<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputStream ins1 = res1.getInputStream();<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputStream ins2 = res2.getInputStream();<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("res1:"+res1.getFilename());<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("res2:"+res2.getFilename());<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } catch (IOException e) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.printStackTrace();<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
}</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
在获取资源后，您就可以通过 Resource 接口定义的多个方法访问文件的数据和其它的信息：如您可以通过 getFileName() 获取文件名，通过 getFile() 获取资源对应的 File 对象，通过 getInputStream() 直接获取文件的输入流。此外，您还可以通过 createRelative(String relativePath) 在资源相对地址上创建新的资源。</p>
<p style="line-height: normal">在 Web 应用中，您还可以通过 ServletContextResource 以相对于 Web 应用根目录的方式访问文件资源，如下所示：</p>
<p style="line-height: normal">&lt;%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%&gt;<br style="line-height: normal" />
&lt;jsp:directive.page import="<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; org.springframework.web.context.support.ServletContextResource"/&gt;<br style="line-height: normal" />
&lt;jsp:directive.page import="org.springframework.core.io.Resource"/&gt;<br style="line-height: normal" />
&lt;%<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; // ① 注意文件资源地址以相对于 Web 应用根路径的方式表示<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; Resource res3 = new ServletContextResource(application,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "/WEB-INF/classes/conf/file1.txt");<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; out.print(res3.getFilename());<br style="line-height: normal" />
%&gt;</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
对于位于远程服务器（Web 服务器或 FTP 服务器）的文件资源，您则可以方便地通过 UrlResource 进行访问。</p>
<p style="line-height: normal">为了方便访问不同类型的资源，您必须使用相应的 Resource 实现类，是否可以在不显式使用 Resource 实现类的情况下，仅根据带特殊前缀的资源地址直接加载文件资源呢？Spring 提供了一个 ResourceUtils 工具类，它支持&#8220;classpath:&#8221;和&#8220;file:&#8221;的地址前缀，它能够从指定的地址加载文件资源，请看下面的例子：</p>
<p style="line-height: normal"><br style="line-height: normal" />
清单 2. ResourceUtilsExample<br style="line-height: normal" />
package com.baobaotao.io;<br style="line-height: normal" />
import java.io.File;<br style="line-height: normal" />
import org.springframework.util.ResourceUtils;<br style="line-height: normal" />
public class ResourceUtilsExample {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) throws Throwable{<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File clsFile = ResourceUtils.getFile("classpath:conf/file1.txt");<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(clsFile.isFile());</p>
<p style="line-height: normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String httpFilePath = "file:D:/masterSpring/chapter23/src/conf/file1.txt";<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File httpFile = ResourceUtils.getFile(httpFilePath);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(httpFile.isFile());&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
}</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
ResourceUtils 的 getFile(String resourceLocation) 方法支持带特殊前缀的资源地址，这样，我们就可以在不和 Resource 实现类打交道的情况下使用 Spring 文件资源加载的功能了。</p>
<p style="line-height: normal">本地化文件资源</p>
<p style="line-height: normal">本地化文件资源是一组通过本地化标识名进行特殊命名的文件，Spring 提供的 LocalizedResourceHelper 允许通过文件资源基名和本地化实体获取匹配的本地化文件资源并以 Resource 对象返回。假设在类路径的 i18n 目录下，拥有一组基名为 message 的本地化文件资源，我们通过以下实例演示获取对应中国大陆和美国的本地化文件资源：</p>
<p style="line-height: normal"><br style="line-height: normal" />
清单 3. LocaleResourceTest<br style="line-height: normal" />
package com.baobaotao.io;<br style="line-height: normal" />
import java.util.Locale;<br style="line-height: normal" />
import org.springframework.core.io.Resource;<br style="line-height: normal" />
import org.springframework.core.io.support.LocalizedResourceHelper;<br style="line-height: normal" />
public class LocaleResourceTest {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LocalizedResourceHelper lrHalper = new LocalizedResourceHelper();<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ① 获取对应美国的本地化文件资源<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Resource msg_us = lrHalper.findLocalizedResource("i18n/message", ".properties",<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Locale.US);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ② 获取对应中国大陆的本地化文件资源<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Resource msg_cn = lrHalper.findLocalizedResource("i18n/message", ".properties",<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Locale.CHINA);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("fileName(us):"+msg_us.getFilename());<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println("fileName(cn):"+msg_cn.getFilename());<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
}</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
虽然 JDK 的 java.util.ResourceBundle 类也可以通过相似的方式获取本地化文件资源，但是其返回的是 ResourceBundle 类型的对象。如果您决定统一使用 Spring 的 Resource 接表征文件资源，那么 LocalizedResourceHelper 就是获取文件资源的非常适合的帮助类了。</p>
<p style="line-height: normal">文件操作</p>
<p style="line-height: normal">在使用各种 Resource 接口的实现类加载文件资源后，经常需要对文件资源进行读取、拷贝、转存等不同类型的操作。您可以通过 Resource 接口所提供了方法完成这些功能，不过在大多数情况下，通过 Spring 为 Resource 所配备的工具类完成文件资源的操作将更加方便。</p>
<p style="line-height: normal">文件内容拷贝</p>
<p style="line-height: normal">第一个我们要认识的是 FileCopyUtils，它提供了许多一步式的静态操作方法，能够将文件内容拷贝到一个目标 byte[]、String 甚至一个输出流或输出文件中。下面的实例展示了 FileCopyUtils 具体使用方法：</p>
<p style="line-height: normal"><br style="line-height: normal" />
清单 4. FileCopyUtilsExample<br style="line-height: normal" />
package com.baobaotao.io;<br style="line-height: normal" />
import java.io.ByteArrayOutputStream;<br style="line-height: normal" />
import java.io.File;<br style="line-height: normal" />
import java.io.FileReader;<br style="line-height: normal" />
import java.io.OutputStream;<br style="line-height: normal" />
import org.springframework.core.io.ClassPathResource;<br style="line-height: normal" />
import org.springframework.core.io.Resource;<br style="line-height: normal" />
import org.springframework.util.FileCopyUtils;<br style="line-height: normal" />
public class FileCopyUtilsExample {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) throws Throwable {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Resource res = new ClassPathResource("conf/file1.txt");<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ① 将文件内容拷贝到一个 byte[] 中<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] fileData = FileCopyUtils.copyToByteArray(res.getFile());<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ② 将文件内容拷贝到一个 String 中<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String fileStr = FileCopyUtils.copyToString(new FileReader(res.getFile()));<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ③ 将文件内容拷贝到另一个目标文件<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileCopyUtils.copy(res.getFile(),<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new File(res.getFile().getParent()+ "/file2.txt"));</p>
<p style="line-height: normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ④ 将文件内容拷贝到一个输出流中<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputStream os = new ByteArrayOutputStream();<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileCopyUtils.copy(res.getInputStream(), os);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
}</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
往往我们都通过直接操作 InputStream 读取文件的内容，但是流操作的代码是比较底层的，代码的面向对象性并不强。通过 FileCopyUtils 读取和拷贝文件内容易于操作且相当直观。如在 ① 处，我们通过 FileCopyUtils 的 copyToByteArray(File in) 方法就可以直接将文件内容读到一个 byte[] 中；另一个可用的方法是 copyToByteArray(InputStream in)，它将输入流读取到一个 byte[] 中。</p>
<p style="line-height: normal">如果是文本文件，您可能希望将文件内容读取到 String 中，此时您可以使用 copyToString(Reader in) 方法，如 ② 所示。使用 FileReader 对 File 进行封装，或使用 InputStreamReader 对 InputStream 进行封装就可以了。</p>
<p style="line-height: normal">FileCopyUtils 还提供了多个将文件内容拷贝到各种目标对象中的方法，这些方法包括：</p>
<p style="line-height: normal">方法 说明<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
static void copy(byte[] in, File out) 将 byte[] 拷贝到一个文件中<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
static void copy(byte[] in, OutputStream out) 将 byte[] 拷贝到一个输出流中<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
static int copy(File in, File out) 将文件拷贝到另一个文件中<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
static int copy(InputStream in, OutputStream out) 将输入流拷贝到输出流中<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
static int copy(Reader in, Writer out) 将 Reader 读取的内容拷贝到 Writer 指向目标输出中<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
static void copy(String in, Writer out) 将字符串拷贝到一个 Writer 指向的目标中</p>
<p style="line-height: normal">在实例中，我们虽然使用 Resource 加载文件资源，但 FileCopyUtils 本身和 Resource 没有任何关系，您完全可以在基于 JDK I/O API 的程序中使用这个工具类。</p>
<p style="line-height: normal">属性文件操作</p>
<p style="line-height: normal">我们知道可以通过 java.util.Properties的load(InputStream inStream) 方法从一个输入流中加载属性资源。Spring 提供的 PropertiesLoaderUtils 允许您直接通过基于类路径的文件地址加载属性资源，请看下面的例子：</p>
<p style="line-height: normal">package com.baobaotao.io;<br style="line-height: normal" />
import java.util.Properties;<br style="line-height: normal" />
import org.springframework.core.io.support.PropertiesLoaderUtils;<br style="line-height: normal" />
public class PropertiesLoaderUtilsExample {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; public static void main(String[] args) throws Throwable {&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ① jdbc.properties 是位于类路径下的文件<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Properties props = PropertiesLoaderUtils.loadAllProperties("jdbc.properties");<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(props.getProperty("jdbc.driverClassName"));<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
}</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
一般情况下，应用程序的属性文件都放置在类路径下，所以 PropertiesLoaderUtils 比之于 Properties#load(InputStream inStream) 方法显然具有更强的实用性。此外，PropertiesLoaderUtils 还可以直接从 Resource 对象中加载属性资源：</p>
<p style="line-height: normal">方法 说明<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
static Properties loadProperties(Resource resource) 从 Resource 中加载属性<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
static void fillProperties(Properties props, Resource resource) 将 Resource 中的属性数据添加到一个已经存在的 Properties 对象中</p>
<p style="line-height: normal">特殊编码的资源</p>
<p style="line-height: normal">当您使用 Resource 实现类加载文件资源时，它默认采用操作系统的编码格式。如果文件资源采用了特殊的编码格式（如 UTF-8），则在读取资源内容时必须事先通过 EncodedResource 指定编码格式，否则将会产生中文乱码的问题。</p>
<p style="line-height: normal"><br style="line-height: normal" />
清单 5. EncodedResourceExample<br style="line-height: normal" />
package com.baobaotao.io;<br style="line-height: normal" />
import org.springframework.core.io.ClassPathResource;<br style="line-height: normal" />
import org.springframework.core.io.Resource;<br style="line-height: normal" />
import org.springframework.core.io.support.EncodedResource;<br style="line-height: normal" />
import org.springframework.util.FileCopyUtils;<br style="line-height: normal" />
public class EncodedResourceExample {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static void main(String[] args) throws Throwable {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Resource res = new ClassPathResource("conf/file1.txt");<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ① 指定文件资源对应的编码格式（UTF-8）<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EncodedResource encRes = new EncodedResource(res,"UTF-8");<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ② 这样才能正确读取文件的内容，而不会出现乱码<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String content = FileCopyUtils.copyToString(encRes.getReader());<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(content);<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
}</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
EncodedResource 拥有一个 getResource() 方法获取 Resource，但该方法返回的是通过构造函数传入的原 Resource 对象，所以必须通过 EncodedResource#getReader() 获取应用编码后的 Reader 对象，然后再通过该 Reader 读取文件的内容。</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
回页首<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
</p>
<p style="line-height: normal"></p>
<p style="line-height: normal">Web 相关工具类</p>
<p style="line-height: normal">您几乎总是使用 Spring 框架开发 Web 的应用，Spring 为 Web 应用提供了很多有用的工具类，这些工具类可以给您的程序开发带来很多便利。在这节里，我们将逐一介绍这些工具类的使用方法。</p>
<p style="line-height: normal">操作 Servlet API 的工具类</p>
<p style="line-height: normal">当您在控制器、JSP 页面中想直接访问 Spring 容器时，您必须事先获取 WebApplicationContext 对象。Spring 容器在启动时将 WebApplicationContext 保存在 ServletContext的属性列表中，通过 WebApplicationContextUtils 工具类可以方便地获取 WebApplicationContext 对象。</p>
<p style="line-height: normal">WebApplicationContextUtils</p>
<p style="line-height: normal">当 Web 应用集成 Spring 容器后，代表 Spring 容器的 WebApplicationContext 对象将以 WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE 为键存放在 ServletContext 属性列表中。您当然可以直接通过以下语句获取 WebApplicationContext：</p>
<p style="line-height: normal">WebApplicationContext wac = (WebApplicationContext)servletContext.<br style="line-height: normal" />
getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
但通过位于 org.springframework.web.context.support 包中的 WebApplicationContextUtils 工具类获取 WebApplicationContext 更方便：</p>
<p style="line-height: normal">WebApplicationContext wac =WebApplicationContextUtils.<br style="line-height: normal" />
getWebApplicationContext(servletContext);</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
当 ServletContext 属性列表中不存在 WebApplicationContext 时，getWebApplicationContext() 方法不会抛出异常，它简单地返回 null。如果后续代码直接访问返回的结果将引发一个 NullPointerException 异常，而 WebApplicationContextUtils 另一个 getRequiredWebApplicationContext(ServletContext sc) 方法要求 ServletContext 属性列表中一定要包含一个有效的 WebApplicationContext 对象，否则马上抛出一个 IllegalStateException 异常。我们推荐使用后者，因为它能提前发现错误的时间，强制开发者搭建好必备的基础设施。</p>
<p style="line-height: normal">WebUtils</p>
<p style="line-height: normal">位于 org.springframework.web.util 包中的 WebUtils 是一个非常好用的工具类，它对很多 Servlet API 提供了易用的代理方法，降低了访问 Servlet API 的复杂度，可以将其看成是常用 Servlet API 方法的门面类。</p>
<p style="line-height: normal">下面这些方法为访问 HttpServletRequest 和 HttpSession 中的对象和属性带来了方便：</p>
<p style="line-height: normal">方法 说明<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
Cookie getCookie(HttpServletRequest request, String name) 获取 HttpServletRequest 中特定名字的 Cookie 对象。如果您需要创建 Cookie， Spring 也提供了一个方便的 CookieGenerator 工具类；<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
Object getSessionAttribute(HttpServletRequest request, String name) 获取 HttpSession 特定属性名的对象，否则您必须通过request.getHttpSession.getAttribute(name) 完成相同的操作；<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
Object getRequiredSessionAttribute(HttpServletRequest request, String name) 和上一个方法类似，只不过强制要求 HttpSession 中拥有指定的属性，否则抛出异常；<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
String getSessionId(HttpServletRequest request) 获取 Session ID 的值；<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
void exposeRequestAttributes(ServletRequest request, Map attributes) 将 Map 元素添加到 ServletRequest 的属性列表中，当请求被导向（forward）到下一个处理程序时，这些请求属性就可以被访问到了；</p>
<p style="line-height: normal">此外，WebUtils还提供了一些和ServletContext相关的方便方法：</p>
<p style="line-height: normal">方法 说明<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
String getRealPath(ServletContext servletContext, String path) 获取相对路径对应文件系统的真实文件路径；<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
File getTempDir(ServletContext servletContext) 获取 ServletContex 对应的临时文件地址，它以 File 对象的形式返回。</p>
<p style="line-height: normal">下面的片断演示了使用 WebUtils 从 HttpSession 中获取属性对象的操作：</p>
<p style="line-height: normal">protected Object formBackingObject(HttpServletRequest request) throws Exception {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; UserSession userSession = (UserSession) WebUtils.getSessionAttribute(request,<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "userSession");<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; if (userSession != null) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new AccountForm(this.petStore.getAccount(<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; userSession.getAccount().getUsername()));<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; } else {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new AccountForm();<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
}</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
Spring 所提供的过滤器和监听器</p>
<p style="line-height: normal">Spring 为 Web 应用提供了几个过滤器和监听器，在适合的时间使用它们，可以解决一些常见的 Web 应用问题。</p>
<p style="line-height: normal">延迟加载过滤器</p>
<p style="line-height: normal">Hibernate 允许对关联对象、属性进行延迟加载，但是必须保证延迟加载的操作限于同一个 Hibernate Session 范围之内进行。如果 Service 层返回一个启用了延迟加载功能的领域对象给 Web 层，当 Web 层访问到那些需要延迟加载的数据时，由于加载领域对象的 Hibernate Session 已经关闭，这些导致延迟加载数据的访问异常。</p>
<p style="line-height: normal">Spring 为此专门提供了一个 OpenSessionInViewFilter 过滤器，它的主要功能是使每个请求过程绑定一个 Hibernate Session，即使最初的事务已经完成了，也可以在 Web 层进行延迟加载的操作。</p>
<p style="line-height: normal">OpenSessionInViewFilter 过滤器将 Hibernate Session 绑定到请求线程中，它将自动被 Spring 的事务管理器探测到。所以 OpenSessionInViewFilter 适用于 Service 层使用HibernateTransactionManager 或 JtaTransactionManager 进行事务管理的环境，也可以用于非事务只读的数据操作中。</p>
<p style="line-height: normal">要启用这个过滤器，必须在 web.xml 中对此进行配置：</p>
<p style="line-height: normal">&#8230;<br style="line-height: normal" />
&lt;filter&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;filter-class&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; org.springframework.orm.hibernate3.support.OpenSessionInViewFilter<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;/filter-class&gt;<br style="line-height: normal" />
&lt;/filter&gt;<br style="line-height: normal" />
&lt;filter-mapping&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;filter-name&gt;hibernateFilter&lt;/filter-name&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;*.html&lt;/url-pattern&gt;<br style="line-height: normal" />
&lt;/filter-mapping&gt;<br style="line-height: normal" />
&#8230;</p>
<p style="line-height: normal"></p>
<p style="line-height: normal">上面的配置，我们假设使用 .html 的后缀作为 Web 框架的 URL 匹配模式，如果您使用 Struts 等 Web 框架，可以将其改为对应的&#8220;*.do&#8221;模型。<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
中文乱码过滤器</p>
<p style="line-height: normal">在您通过表单向服务器提交数据时，一个经典的问题就是中文乱码问题。虽然我们所有的 JSP 文件和页面编码格式都采用 UTF-8，但这个问题还是会出现。解决的办法很简单，我们只需要在 web.xml 中配置一个 Spring 的编码转换过滤器就可以了：</p>
<p style="line-height: normal">&lt;web-app&gt;<br style="line-height: normal" />
&lt;!---listener的配置--&gt;<br style="line-height: normal" />
&lt;filter&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;filter-class&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; org.springframework.web.filter.CharacterEncodingFilter ① Spring 编辑过滤器<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;/filter-class&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;init-param&gt; ② 编码方式<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-name&gt;encoding&lt;/param-name&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-value&gt;UTF-8&lt;/param-value&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;/init-param&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;init-param&gt; ③ 强制进行编码转换<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-name&gt;forceEncoding&lt;/param-name&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-value&gt;true&lt;/param-value&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;/init-param&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;/filter&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;filter-mapping&gt; ② 过滤器的匹配 URL<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;*.html&lt;/url-pattern&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;/filter-mapping&gt;</p>
<p style="line-height: normal">&lt;!---servlet的配置--&gt;<br style="line-height: normal" />
&lt;/web-app&gt;</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
这样所有以 .html 为后缀的 URL 请求的数据都会被转码为 UTF-8 编码格式，表单中文乱码的问题就可以解决了。</p>
<p style="line-height: normal">请求跟踪日志过滤器</p>
<p style="line-height: normal">除了以上两个常用的过滤器外，还有两个在程序调试时可能会用到的请求日志跟踪过滤器，它们会将请求的一些重要信息记录到日志中，方便程序的调试。这两个日志过滤器只有在日志级别为 DEBUG 时才会起作用：</p>
<p style="line-height: normal">方法 说明<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
org.springframework.web.filter.ServletContextRequestLoggingFilter 该过滤器将请求的 URI 记录到 Common 日志中（如通过 Log4J 指定的日志文件）；<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
org.springframework.web.filter.ServletContextRequestLoggingFilter 该过滤器将请求的 URI 记录到 ServletContext 日志中。</p>
<p style="line-height: normal">以下是日志过滤器记录的请求跟踪日志的片断：</p>
<p style="line-height: normal">(JspServlet.java:224) -&nbsp;&nbsp;&nbsp;&nbsp; JspEngine --&gt; /htmlTest.jsp<br style="line-height: normal" />
(JspServlet.java:225) - &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServletPath: /htmlTest.jsp<br style="line-height: normal" />
(JspServlet.java:226) - &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PathInfo: null<br style="line-height: normal" />
(JspServlet.java:227) - &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RealPath: D:\masterSpring\chapter23\webapp\htmlTest.jsp<br style="line-height: normal" />
(JspServlet.java:228) - &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; RequestURI: /baobaotao/htmlTest.jsp<br style="line-height: normal" />
&#8230;</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
通过这个请求跟踪日志，程度调试者可以详细地查看到有哪些请求被调用，请求的参数是什么，请求是否正确返回等信息。虽然这两个请求跟踪日志过滤器一般在程序调试时使用，但是即使程序部署不将其从 web.xml 中移除也不会有大碍，因为只要将日志级别设置为 DEBUG 以上级别，它们就不会输出请求跟踪日志信息了。</p>
<p style="line-height: normal">转存 Web 应用根目录监听器和 Log4J 监听器</p>
<p style="line-height: normal">Spring 在 org.springframework.web.util 包中提供了几个特殊用途的 Servlet 监听器，正确地使用它们可以完成一些特定需求的功能。比如某些第三方工具支持通过 ${key} 的方式引用系统参数（即可以通过 System.getProperty() 获取的属性），WebAppRootListener 可以将 Web 应用根目录添加到系统参数中，对应的属性名可以通过名为&#8220;webAppRootKey&#8221;的 Servlet 上下文参数指定，默认为&#8220;webapp.root&#8221;。下面是该监听器的具体的配置：</p>
<p style="line-height: normal"><br style="line-height: normal" />
清单 6. WebAppRootListener 监听器配置<br style="line-height: normal" />
&#8230;<br style="line-height: normal" />
&lt;context-param&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;param-name&gt;webAppRootKey&lt;/param-name&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;param-value&gt;baobaotao.root&lt;/param-value&gt; ① Web 应用根目录以该属性名添加到系统参数中<br style="line-height: normal" />
&lt;/context-param&gt;<br style="line-height: normal" />
&#8230;<br style="line-height: normal" />
② 负责将 Web 应用根目录以 webAppRootKey 上下文参数指定的属性名添加到系统参数中<br style="line-height: normal" />
&lt;listener&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;listener-class&gt;<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; org.springframework.web.util.WebAppRootListener<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;/listener-class&gt;<br style="line-height: normal" />
&lt;/listener&gt;<br style="line-height: normal" />
&#8230;</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
这样，您就可以在程序中通过 System.getProperty("baobaotao.root") 获取 Web 应用的根目录了。不过更常见的使用场景是在第三方工具的配置文件中通过${baobaotao.root} 引用 Web 应用的根目录。比如以下的 log4j.properties 配置文件就通过 ${baobaotao.root} 设置了日志文件的地址：</p>
<p style="line-height: normal">log4j.rootLogger=INFO,R<br style="line-height: normal" />
log4j.appender.R=org.apache.log4j.RollingFileAppender<br style="line-height: normal" />
log4j.appender.R.File=${baobaotao.root}/WEB-INF/logs/log4j.log ① 指定日志文件的地址<br style="line-height: normal" />
log4j.appender.R.MaxFileSize=100KB<br style="line-height: normal" />
log4j.appender.R.MaxBackupIndex=1<br style="line-height: normal" />
log4j.appender.R.layout.ConversionPattern=%d %5p [%t] (%F:%L) - %m%n</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
另一个专门用于 Log4J 的监听器是 Log4jConfigListener。一般情况下，您必须将 Log4J 日志配置文件以 log4j.properties 为文件名并保存在类路径下。Log4jConfigListener 允许您通过 log4jConfigLocation Servlet 上下文参数显式指定 Log4J 配置文件的地址，如下所示：</p>
<p style="line-height: normal">① 指定 Log4J 配置文件的地址<br style="line-height: normal" />
&lt;context-param&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;param-name&gt;log4jConfigLocation&lt;/param-name&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;param-value&gt;/WEB-INF/log4j.properties&lt;/param-value&gt;<br style="line-height: normal" />
&lt;/context-param&gt;<br style="line-height: normal" />
&#8230;<br style="line-height: normal" />
② 使用该监听器初始化 Log4J 日志引擎<br style="line-height: normal" />
&lt;listener&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;listener-class&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; org.springframework.web.util.Log4jConfigListener<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;/listener-class&gt;<br style="line-height: normal" />
&lt;/listener&gt;<br style="line-height: normal" />
&#8230;</p>
<p style="line-height: normal"></p>
<p style="line-height: normal">提示</p>
<p style="line-height: normal">一些Web应用服务器（如 Tomcat）不会为不同的Web应用使用独立的系统参数，也就是说，应用服务器上所有的 Web 应用都共享同一个系统参数对象。这时，您必须通过webAppRootKey 上下文参数为不同Web应用指定不同的属性名：如第一个 Web 应用使用 webapp1.root 而第二个 Web 应用使用 webapp2.root 等，这样才不会发生后者覆盖前者的问题。此外，WebAppRootListener 和 Log4jConfigListener 都只能应用在 Web 应用部署后 WAR 文件会解包的 Web 应用服务器上。一些 Web 应用服务器不会将Web 应用的 WAR 文件解包，整个 Web 应用以一个 WAR 包的方式存在（如 Weblogic），此时因为无法指定对应文件系统的 Web 应用根目录，使用这两个监听器将会发生问题。<br style="line-height: normal" />
<br style="line-height: normal" />
<br style="line-height: normal" />
Log4jConfigListener 监听器包括了 WebAppRootListener 的功能，也就是说，Log4jConfigListener 会自动完成将 Web 应用根目录以 webAppRootKey 上下文参数指定的属性名添加到系统参数中，所以当您使用 Log4jConfigListener 后，就没有必须再使用 WebAppRootListener了。</p>
<p style="line-height: normal">Introspector 缓存清除监听器</p>
<p style="line-height: normal">Spring 还提供了一个名为 org.springframework.web.util.IntrospectorCleanupListener 的监听器。它主要负责处理由 JavaBean Introspector 功能而引起的缓存泄露。IntrospectorCleanupListener 监听器在 Web 应用关闭的时会负责清除 JavaBean Introspector 的缓存，在 web.xml 中注册这个监听器可以保证在 Web 应用关闭的时候释放与其相关的 ClassLoader 的缓存和类引用。如果您使用了 JavaBean Introspector 分析应用中的类，Introspector 缓存会保留这些类的引用，结果在应用关闭的时候，这些类以及Web 应用相关的 ClassLoader 不能被垃圾回收。不幸的是，清除 Introspector 的唯一方式是刷新整个缓存，这是因为没法准确判断哪些是属于本 Web 应用的引用对象，哪些是属于其它 Web 应用的引用对象。所以删除被缓存的 Introspection 会导致将整个 JVM 所有应用的 Introspection 都删掉。需要注意的是，Spring 托管的 Bean 不需要使用这个监听器，因为 Spring 的 Introspection 所使用的缓存在分析完一个类之后会马上从 javaBean Introspector 缓存中清除掉，并将缓存保存在应用程序特定的 ClassLoader 中，所以它们一般不会导致内存资源泄露。但是一些类库和框架往往会产生这个问题。例如 Struts 和 Quartz 的 Introspector 的内存泄漏会导致整个的 Web 应用的 ClassLoader 不能进行垃圾回收。在 Web 应用关闭之后，您还会看到此应用的所有静态类引用，这个错误当然不是由这个类自身引起的。解决这个问题的方法很简单，您仅需在 web.xml 中配置 IntrospectorCleanupListener 监听器就可以了：</p>
<p style="line-height: normal">&lt;listener&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;listener-class&gt;<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; org.springframework.web.util.IntrospectorCleanupListener<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; &lt;/listener-class&gt;<br style="line-height: normal" />
&lt;/listener&gt;</p>
<p style="line-height: normal"></p>
<p style="line-height: normal"></p>
<p style="line-height: normal"></p>
<p style="line-height: normal"><br style="line-height: normal" />
回页首<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
</p>
<p style="line-height: normal"></p>
<p style="line-height: normal">小结</p>
<p style="line-height: normal">本文介绍了一些常用的 Spring 工具类，其中大部分 Spring 工具类不但可以在基于 Spring 的应用中使用，还可以在其它的应用中使用。使用 JDK 的文件操作类在访问类路径相关、Web 上下文相关的文件资源时，往往显得拖泥带水、拐弯抹角，Spring 的 Resource 实现类使这些工作变得轻松了许多。</p>
<p style="line-height: normal">在 Web 应用中，有时你希望直接访问 Spring 容器，获取容器中的 Bean，这时使用 WebApplicationContextUtils 工具类从 ServletContext 中获取 WebApplicationContext 是非常方便的。WebUtils 为访问 Servlet API 提供了一套便捷的代理方法，您可以通过 WebUtils 更好的访问 HttpSession 或 ServletContext 的信息。</p>
<p style="line-height: normal">Spring 提供了几个 Servlet 过滤器和监听器，其中 ServletContextRequestLoggingFilter 和 ServletContextRequestLoggingFilter 可以记录请求访问的跟踪日志，你可以在程序调试时使用它们获取请求调用的详细信息。WebAppRootListener 可以将 Web 应用的根目录以特定属性名添加到系统参数中，以便第三方工具类通过 ${key} 的方式进行访问。Log4jConfigListener 允许你指定 Log4J 日志配置文件的地址，且可以在配置文件中通过 ${key} 的方式引用 Web 应用根目录，如果你需要在 Web 应用相关的目录创建日志文件，使用 Log4jConfigListener 可以很容易地达到这一目标。</p>
<p style="line-height: normal">Web 应用的内存泄漏是最让开发者头疼的问题，虽然不正确的程序编写可能是这一问题的根源，也有可能是一些第三方框架的 JavaBean Introspector 缓存得不到清除而导致的，Spring 专门为解决这一问题配备了 IntrospectorCleanupListener 监听器，它只要简单在 web.xml 中声明该监听器就可以了。</p>
</span></span>
<img src ="http://www.blogjava.net/alancxx/aggbug/349896.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/alancxx/" target="_blank">蜂鸟</a> 2011-05-10 10:02 <a href="http://www.blogjava.net/alancxx/articles/349896.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>hibernate Restrictions用法 MatchMode.ANYWHERE</title><link>http://www.blogjava.net/alancxx/articles/349490.html</link><dc:creator>蜂鸟</dc:creator><author>蜂鸟</author><pubDate>Wed, 04 May 2011 06:09:00 GMT</pubDate><guid>http://www.blogjava.net/alancxx/articles/349490.html</guid><wfw:comment>http://www.blogjava.net/alancxx/comments/349490.html</wfw:comment><comments>http://www.blogjava.net/alancxx/articles/349490.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/alancxx/comments/commentRss/349490.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/alancxx/services/trackbacks/349490.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 14px; color: rgb(117,117,117); line-height: 21px; font-family: Arial; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">
<table class="FCK__ShowTableBorders" dir="ltr" style="table-layout: auto; line-height: normal; height: 319px" cellspacing="0" cellpadding="0" width="499" border="0">
    <tbody style="line-height: normal">
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">方法</font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">说明</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.eq</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">＝</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.allEq</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">利用Map来进行多个等于的限制</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.gt</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">＞</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.ge</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">＞＝</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.<span style="font-size: 14px! important; line-height: normal">lt</span></font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">＜</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.le</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">＜＝</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.between</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">BETWEEN</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.like</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">LIKE</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.in</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">in</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.and</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">and</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.or</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="24">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">or</font></p>
            </td>
        </tr>
        <tr style="line-height: normal">
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="220" height="47">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.sqlRestriction</font></font></p>
            </td>
            <td style="font-size: 14px! important; filter: none; visibility: visible! important; word-break: break-all; line-height: normal; zoom: 1! important; font-family: Arial; word-wrap: break-word" width="281" height="47">
            <p style="font-size: 14px! important; text-indent: 2em; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">用SQL限定查询</font></p>
            </td>
        </tr>
    </tbody>
</table>
<br style="line-height: normal" />
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4"></font></p>
<p style="font-size: 14px! important; line-height: normal"><strong style="line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><em style="color: red; line-height: normal">QBC常用限定方法</em></font></font></strong></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.eq</span><span class="Apple-converted-space">&nbsp;</span>--&gt; equal,等于.</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.allEq</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 参数为Map对象,使用key/value进行多个等于的比对,相当于多个<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.eq 的效果</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.gt</span><span class="Apple-converted-space">&nbsp;</span>--&gt; great-than &gt; 大于</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.ge</span><span class="Apple-converted-space">&nbsp;</span>--&gt; great-equal &gt;= 大于等于</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.<span style="font-size: 14px! important; line-height: normal">lt</span></span><span class="Apple-converted-space">&nbsp;</span>--&gt; less-than, &lt; 小于</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.le</span><span class="Apple-converted-space">&nbsp;</span>--&gt; less-equal &lt;= 小于等于</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.between</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 对应SQL的between子句</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.like</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 对应SQL的LIKE子句</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.in</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 对应SQL的in子句</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.and</span><span class="Apple-converted-space">&nbsp;</span>--&gt; and 关系</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.or</span><span class="Apple-converted-space">&nbsp;</span>--&gt; or 关系</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.isNull</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 判断属性是否为空,为空则返回true</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.isNotNull</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 与isNull相反</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal"><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.sqlRestriction</span><span class="Apple-converted-space">&nbsp;</span>--&gt; SQL限定的查询</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal">Order.asc</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 根据传入的字段进行升序排序</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal">Order.desc</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 根据传入的字段进行降序排序</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal">MatchMode.EXACT</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 字符串精确匹配.相当于"like 'value'"</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal">MatchMode.ANYWHERE</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 字符串在中间匹配.相当于"like '%value%'"</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal">MatchMode.START</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 字符串在最前面的位置.相当于"like 'value%'"</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312"><font style="line-height: normal" size="4"><span style="font-size: 14px! important; color: red; line-height: normal">MatchMode.END</span><span class="Apple-converted-space">&nbsp;</span>--&gt; 字符串在最后面的位置.相当于"like '%value'"</font></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">例子<br style="line-height: normal" />
查询年龄在20-30岁之间的所有学生对象<br style="line-height: normal" />
List list = session.createCriteria(Student.class)<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .add(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.between("age",new Integer(20),new Integer(30)).list();<br style="line-height: normal" />
查询学生姓名在AAA,BBB,CCC之间的学生对象<br style="line-height: normal" />
String[] names = {"AAA","BBB","CCC"};<br style="line-height: normal" />
List list = session.createCriteria(Student.class)<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .add(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.in("name",names)).list();<br style="line-height: normal" />
查询年龄为空的学生对象<br style="line-height: normal" />
List list = session.createCriteria(Student.class)<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .add(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.isNull("age")).list();<br style="line-height: normal" />
查询年龄等于20或者年龄为空的学生对象<br style="line-height: normal" />
List list = session.createCriteria(Student.class)<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .add(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.or(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.eq("age",new Integer(20)),<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.isNull("age")).list();</font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">--------------------------------------------------------------------<br style="line-height: normal" />
<span style="font-size: 14px! important; color: red; line-height: normal"><strong style="line-height: normal">使用QBC实现动态查询</strong><span class="Apple-converted-space">&nbsp;</span></span><br style="line-height: normal" />
public List findStudents(String name,int age){</font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">Criteria criteria = session.createCriteria(Student.class);<br style="line-height: normal" />
if(name != null){<br style="line-height: normal" />
&nbsp;&nbsp; criteria.add(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.liek("name",name,MatchMode.ANYWHERE));<br style="line-height: normal" />
}<br style="line-height: normal" />
if(age != 0){<br style="line-height: normal" />
&nbsp;&nbsp; criteria.add(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.eq("age",new Integer(age)));<br style="line-height: normal" />
}<br style="line-height: normal" />
criteria.addOrder(Order.asc("name"));//根据名字升序排列<br style="line-height: normal" />
return criteria.list();<br style="line-height: normal" />
}</font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4"></font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">-----------------------------------------------------------------------------------</font></p>
<p style="font-size: 14px! important; line-height: normal"><font style="line-height: normal" face="楷体_GB2312" size="4">今天用了写<span style="font-size: 14px! important; line-height: normal">hibernate</span>高级查询时用了<span style="font-size: 14px! important; line-height: normal">Restrictions</span>(当然Expr<wbr style="line-height: normal">ession也是可以以的)这个类.感觉不错.<br style="line-height: normal" />
下面的代码写的不易读.其实核心就是一句<br style="line-height: normal" />
<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.or(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.like(),<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.or(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.like,........))<br style="line-height: normal" />
里面的or可以无限加的.还是比较好用<br style="line-height: normal" />
<br style="line-height: normal" />
Session session = getHibernateTemplate().getSessionFactory()<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .openSession();<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Criteria criteria = session.createCriteria(Film.class);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; List&lt;Film&gt; list = criteria.add(<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.or(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.like("description", key,MatchMode.ANYWHERE),<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.or(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.like("name", key,MatchMode.ANYWHERE),<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.or(&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.like("direct", key,MatchMode.ANYWHERE),<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.or(<span style="font-size: 14px! important; line-height: normal">Restrictions</span>.like("mainplay",key,MatchMode.ANYWHERE),<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><span style="font-size: 14px! important; line-height: normal">Restrictions</span>.like("filearea", key,MatchMode.ANYWHERE)))))).list();<br style="line-height: normal" />
<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; session.close();<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return list;</font></p>
</span></span>
<img src ="http://www.blogjava.net/alancxx/aggbug/349490.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/alancxx/" target="_blank">蜂鸟</a> 2011-05-04 14:09 <a href="http://www.blogjava.net/alancxx/articles/349490.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用JRegex抽取网页信息</title><link>http://www.blogjava.net/alancxx/articles/348412.html</link><dc:creator>蜂鸟</dc:creator><author>蜂鸟</author><pubDate>Sat, 16 Apr 2011 12:47:00 GMT</pubDate><guid>http://www.blogjava.net/alancxx/articles/348412.html</guid><wfw:comment>http://www.blogjava.net/alancxx/comments/348412.html</wfw:comment><comments>http://www.blogjava.net/alancxx/articles/348412.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/alancxx/comments/commentRss/348412.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/alancxx/services/trackbacks/348412.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="word-spacing: 0px; font: medium Simsun; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; border-collapse: separate; orphans: 2; widows: 2; webkit-border-horizontal-spacing: 0px; webkit-border-vertical-spacing: 0px; webkit-text-decorations-in-effect: none; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px"><span class="Apple-style-span" style="font-size: 12px; color: rgb(107,107,107); line-height: 20px; font-family: Tahoma; webkit-border-horizontal-spacing: 2px; webkit-border-vertical-spacing: 2px">
<p style="line-height: normal">当网络爬虫将网页下载到磁盘上以后，需要对这些网页中的内容进行抽取，为索引做准备。一个网页中的数据大部分是HTML标签，索引肯定不会去索引这些标签。也就是说，这种信息是没有用处的信息，需要在抽取过程中过滤掉。另外，一个网页中一般会存在广告信息、锚文本信息，还有一些我们不感兴趣的信息，都被视为垃圾信息，如果不加考虑这些内容，抽取出来的信息不仅占用存储空间，而且在索引以后，为终端用户提供检索服务，用户检会索到很多无用的垃圾信息，势必影响用户的体验。</p>
<p style="line-height: normal">这里，针对论坛，采用配置模板的方式来实现信息的抽取。使用的工具可以到<a style="font-size: 12px; background-image: none; color: rgb(107,107,107); line-height: 20px; font-family: Tahoma; text-decoration: none; background-origin: initial; background-clip: initial" href="http://jregex.sourceforge.net/">http://jregex.sourceforge.net</a>上下载，JRegex是一个基于Java的正则库，可以通过在正则模板中指定待抽取信息的变量，在抽取过程中会将抽取到的信息赋给该变量，从而得到感兴趣的信息。而且，JRegex库支持多级分组匹配。</p>
<p style="line-height: normal">为了直观，假设，有一个论坛的一个网页的源代码形如：</p>
<p style="line-height: normal">&lt;a id="anchor"&gt;标题&lt;/a&gt;<br style="line-height: normal" />
&lt;cont&gt;<br style="line-height: normal" />
&lt;author&gt;a1&lt;/author&gt;<br style="line-height: normal" />
&lt;time&gt;2009&lt;/time&gt;<br style="line-height: normal" />
&lt;post&gt;p1&lt;/post&gt;</p>
<p style="line-height: normal">&lt;author&gt;a2&lt;/author&gt;<br style="line-height: normal" />
&lt;time&gt;2008&lt;/time&gt;<br style="line-height: normal" />
&lt;post&gt;p2&lt;/post&gt;</p>
<p style="line-height: normal">&lt;author&gt;a3&lt;/author&gt;<br style="line-height: normal" />
&lt;time&gt;2007&lt;/time&gt;<br style="line-height: normal" />
&lt;post&gt;p3&lt;/post&gt;</p>
<p style="line-height: normal">&lt;author&gt;a4&lt;/author&gt;<br style="line-height: normal" />
&lt;time&gt;2006&lt;/time&gt;<br style="line-height: normal" />
&lt;post&gt;p4&lt;/post&gt;</p>
<p style="line-height: normal">&lt;author&gt;2005&lt;/author&gt;<br style="line-height: normal" />
&lt;time&gt;t5&lt;/time&gt;<br style="line-height: normal" />
&lt;post&gt;p5&lt;/post&gt;<br style="line-height: normal" />
&lt;/cont&gt;</p>
<p style="line-height: normal">将该网页代码文件保存为bbsPage.txt文件，准备进行处理。</p>
<p style="line-height: normal">现在，我们的目标是抽取标题、作者、时间、内容这些内容，当然，标题完全可以从TITLE标签中获得，但是一般网站的一个网页，会在标题文本的后面加上一些目录或者网站名称的信息，例如一个标题为&#8220;品味北京奥运中心_奥运加油站_我行我摄_XXX社区_XXX社区是最活跃的社区之一&#8221;，一些垃圾信息占了标题的大部分，所以我们不从TITLE标签中抽取标题。</p>
<p style="line-height: normal">接着，针对上面的网页文件创建信息抽取的正则模板，如下所示：</p>
<p style="line-height: normal">(?s)&lt;a\sid="anchor"&gt;({title}.{1,100}?)&lt;/a&gt;\s*&lt;cont&gt;(.{1,10240}?)&lt;/cont&gt; &lt;author&gt;({name}.{1,100}?)&lt;/author&gt;\s*&lt;time&gt;({when}.{1,100}?)&lt;/time&gt;\s*&lt;post&gt;({content}.{1,100}?)&lt;/post&gt;</p>
<p style="line-height: normal">该模板包含两部分：</p>
<p style="line-height: normal">第一部分为(?s)&lt;a\sid="anchor"&gt;({title}.{1,100}?)&lt;/a&gt;\s*&lt;cont&gt;(.{1,10240}?)&lt;/cont&gt;，包含两个组，第一个组名称为title，直接能够抽取到网页的标题文本，并存储到变量title中；而第二个组没有指定组的名称，表示在后面还存在子组，在子组中继续进行抽取。</p>
<p style="line-height: normal">第二部分为&lt;author&gt;({name}.{1,100}?)&lt;/author&gt;\s*&lt;time&gt;({when}.{1,100}?)&lt;/time&gt;\s*&lt;post&gt;({content}.{1,100}?)&lt;/post&gt;，恰好是父组中未指定组名称的第二个组内中的一个循环。</p>
<p style="line-height: normal">上面两个模板之间使用一个空格字符隔开，保存到pattern.txt文件中。</p>
<p style="line-height: normal">可能，你已经观察到了，网页的标题只有一个，而对其他的信息正好能够构成一个循环组，单独从父组中分离出来继续进行抽取，结构很整齐。所以，在使用JRegex库进行编码抽取的时候，主要就是针对两个组进行的。</p>
<p style="line-height: normal">我基于上面思想和数据，实现了信息的抽取。</p>
<p style="line-height: normal">首先定义了一个键值对实体类，使用泛型，如下所示：</p>
<p style="line-height: normal">package org.shirdrn.test;</p>
<p style="line-height: normal">public class Pair&lt;K, V&gt; {<br style="line-height: normal" />
<br style="line-height: normal" />
private K key;<br style="line-height: normal" />
private V value;<br style="line-height: normal" />
<br style="line-height: normal" />
public Pair(K key, V value) {<br style="line-height: normal" />
&nbsp;&nbsp; this.key = key;<br style="line-height: normal" />
&nbsp;&nbsp; this.value = value;<br style="line-height: normal" />
}<br style="line-height: normal" />
<br style="line-height: normal" />
public K getKey() {<br style="line-height: normal" />
&nbsp;&nbsp; return key;<br style="line-height: normal" />
}<br style="line-height: normal" />
public void setKey(K key) {<br style="line-height: normal" />
&nbsp;&nbsp; this.key = key;<br style="line-height: normal" />
}<br style="line-height: normal" />
public V getValue() {<br style="line-height: normal" />
&nbsp;&nbsp; return value;<br style="line-height: normal" />
}<br style="line-height: normal" />
public void setValue(V value) {<br style="line-height: normal" />
&nbsp;&nbsp; this.value = value;<br style="line-height: normal" />
}<br style="line-height: normal" />
<br style="line-height: normal" />
}</p>
<p style="line-height: normal">进行信息抽取的核心类为InfomationExtraction，如下所示：</p>
<p style="line-height: normal">package org.shirdrn.test;</p>
<p style="line-height: normal">import java.io.BufferedReader;<br style="line-height: normal" />
import java.io.IOException;<br style="line-height: normal" />
import java.io.InputStream;<br style="line-height: normal" />
import java.io.InputStreamReader;<br style="line-height: normal" />
import java.util.ArrayList;<br style="line-height: normal" />
import java.util.List;</p>
<p style="line-height: normal">import jregex.Matcher;<br style="line-height: normal" />
import jregex.Pattern;</p>
<p style="line-height: normal">public class InfomationExtraction {<br style="line-height: normal" />
<br style="line-height: normal" />
private String htmlString;<br style="line-height: normal" />
private String patternString;<br style="line-height: normal" />
private List&lt;Pair&lt;String, String&gt;&gt; dataList = new ArrayList&lt;Pair&lt;String, String&gt;&gt;();<br style="line-height: normal" />
<br style="line-height: normal" />
public InfomationExtraction() {<br style="line-height: normal" />
&nbsp;&nbsp;<br style="line-height: normal" />
}<br style="line-height: normal" />
<br style="line-height: normal" />
public InfomationExtraction(String htmlFileName, String patternFileName) {<br style="line-height: normal" />
&nbsp;&nbsp; this.htmlString = this.readString(htmlFileName);<br style="line-height: normal" />
&nbsp;&nbsp; this.patternString = this.readString(patternFileName);<br style="line-height: normal" />
}<br style="line-height: normal" />
<br style="line-height: normal" />
public Pattern[] getPatternArray() {<br style="line-height: normal" />
&nbsp;&nbsp; Pattern[] pa = new Pattern[2];<br style="line-height: normal" />
&nbsp;&nbsp; String[] psa = this.patternString.split(" ");<br style="line-height: normal" />
&nbsp;&nbsp; for(int i=0; i&lt;psa.length; i++) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; Pattern p = new Pattern(psa[i]);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; pa[i] = p;<br style="line-height: normal" />
&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp; return pa;<br style="line-height: normal" />
}<br style="line-height: normal" />
<br style="line-height: normal" />
public void extract(Integer sgIndex) {&nbsp;&nbsp;<span class="Apple-converted-space">&nbsp;</span><font style="line-height: normal" color="#339966">// 指定父组中第sgIndex个组需要在子组中继续进行抽取<br style="line-height: normal" />
</font>&nbsp;&nbsp; Pattern[] pa = this.getPatternArray();<br style="line-height: normal" />
&nbsp;&nbsp; Pattern pBase = pa[0];<span class="Apple-converted-space">&nbsp;</span><br style="line-height: normal" />
&nbsp;&nbsp; Matcher mBase = pBase.matcher(this.htmlString);<br style="line-height: normal" />
&nbsp;&nbsp; if(mBase.find()) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; for(int i=0; i&lt;mBase.groupCount(); i++) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp; String gn = pBase.groupName(i);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp; if(gn != null) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String gv = mBase.group(i);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.dataList.add(new Pair&lt;String, String&gt;(gn, gv));<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; String subText = mBase.group(sgIndex);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; if(subText != null) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp; this.dataList.addAll(this.getSubGroupDataList(pa, subText));<span class="Apple-converted-space">&nbsp;</span><font style="line-height: normal" color="#339966">// 调用使用子组正则模板进行抽取的方法</font><br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp; }<br style="line-height: normal" />
}<br style="line-height: normal" />
<br style="line-height: normal" />
public List&lt;Pair&lt;String, String&gt;&gt; getSubGroupDataList(Pattern[] pa, String subText) {<span class="Apple-converted-space">&nbsp;</span><font style="line-height: normal" color="#339966">// 使用子组正则模板进行抽取</font><br style="line-height: normal" />
&nbsp;&nbsp; List&lt;Pair&lt;String, String&gt;&gt; list = new ArrayList&lt;Pair&lt;String, String&gt;&gt;();<br style="line-height: normal" />
&nbsp;&nbsp; for(int i=1; i&lt;pa.length; i++) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; Pattern subp =pa[i];<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; Matcher subm = subp.matcher(subText);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; while(subm.find()) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp; for(int k=0; k&lt;subm.groupCount(); k++) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String gn = subp.groupName(k);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(gn != null) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String gv = subm.group(k);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list.add(new Pair&lt;String, String&gt;(gn, gv));<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp; return list;<br style="line-height: normal" />
}</p>
<p style="line-height: normal">public String readString(String fileName) {<br style="line-height: normal" />
&nbsp;&nbsp; InputStream in = this.getClass().getResourceAsStream("/" + fileName);<br style="line-height: normal" />
&nbsp;&nbsp; BufferedReader reader = new BufferedReader(new InputStreamReader(in));<br style="line-height: normal" />
&nbsp;&nbsp; StringBuffer sb = new StringBuffer();<br style="line-height: normal" />
&nbsp;&nbsp; String line = null;<br style="line-height: normal" />
&nbsp;&nbsp; try {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; while((line=reader.readLine()) != null) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp;&nbsp; sb.append(line);<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp; } catch (IOException e) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; e.printStackTrace();<br style="line-height: normal" />
&nbsp;&nbsp; }<br style="line-height: normal" />
&nbsp;&nbsp; return sb.toString();<br style="line-height: normal" />
}<br style="line-height: normal" />
<br style="line-height: normal" />
public List&lt;Pair&lt;String, String&gt;&gt; getDataList() {<br style="line-height: normal" />
&nbsp;&nbsp; return this.dataList;<br style="line-height: normal" />
}</p>
<p style="line-height: normal">public static void main(String[] args) {&nbsp;&nbsp;<br style="line-height: normal" />
&nbsp;&nbsp; InfomationExtraction ie = new InfomationExtraction("bbsPage.txt","pattern.txt");<br style="line-height: normal" />
&nbsp;&nbsp; ie.extract(2);<br style="line-height: normal" />
&nbsp;&nbsp; for(Pair&lt;String, String&gt; p : ie.getDataList()) {<br style="line-height: normal" />
&nbsp;&nbsp;&nbsp; System.out.println("[" + p.getKey() + " " + p.getValue() + "]");<br style="line-height: normal" />
&nbsp;&nbsp; }<br style="line-height: normal" />
}</p>
<p style="line-height: normal">}</p>
<p style="line-height: normal">测试一下，如下所示：</p>
<p style="line-height: normal">[title 标题]<br style="line-height: normal" />
[name a1]<br style="line-height: normal" />
[when 2009]<br style="line-height: normal" />
[content p1]<br style="line-height: normal" />
[name a2]<br style="line-height: normal" />
[when 2008]<br style="line-height: normal" />
[content p2]<br style="line-height: normal" />
[name a3]<br style="line-height: normal" />
[when 2007]<br style="line-height: normal" />
[content p3]<br style="line-height: normal" />
[name a4]<br style="line-height: normal" />
[when 2006]<br style="line-height: normal" />
[content p4]<br style="line-height: normal" />
[name 2005]<br style="line-height: normal" />
[when t5]<br style="line-height: normal" />
[content p5]</p>
<p style="line-height: normal">至于如何组织抽取到的信息，比如你可能使用Lucene的索引，需要构造Field和Document，那么你就要设计一个实体能够包含一个Document的所有的Field，比如一个Document包括：URL、标题、作者、发表时间、发表内容这五个项，非常容易就能做到。</p>
<p style="line-height: normal">使用JRegex库，可以非常灵活地配置模板，尤其是对多个组的设计，这要根据你的需要来考虑。</p>
</span></span>
<img src ="http://www.blogjava.net/alancxx/aggbug/348412.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/alancxx/" target="_blank">蜂鸟</a> 2011-04-16 20:47 <a href="http://www.blogjava.net/alancxx/articles/348412.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>opencms创建网站过程图解</title><link>http://www.blogjava.net/alancxx/articles/342928.html</link><dc:creator>蜂鸟</dc:creator><author>蜂鸟</author><pubDate>Thu, 13 Jan 2011 07:12:00 GMT</pubDate><guid>http://www.blogjava.net/alancxx/articles/342928.html</guid><description><![CDATA[<br />
很多人都听说了OpenCms，知道了它的强大，索性的下载安装了，终于见到了久违OpenCms，看到了它简洁的界面，欣喜过后却不免一脸茫然，
这个东西怎么用，我怎么用它来建站，从哪开始，无从下手，找资料，少之双少，几经周折后，迫于时间等诸多因素，很多人无奈地选择了放弃&#8230;&#8230;<br />
希望这篇文章可以对OpenCms的追随者们有所帮助，但这也只是OpenCms的皮毛，把它的强大功能为已所用还需要我们付出更多的努力&#8230;&#8230;<br />
<br />
一、切换到&#8220;/sites/&#8221;下，创建站点文件夹&#8220;testWeb&#8221;
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_01.png" alt="" /> </p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_02.png" alt="" /> </p>
<p>　　输入文件夹的标题，这个标题就是站点的名称，一会儿你就会看到它的用处，它会显示在&#8220;站点&#8221;下&#8230;&#8230;</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_03.png" alt="" /> </p>
<p>　　创建后的结果如下：</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_04.png" alt="" /></p>
<p>　　二、配置tomcat，打开tomcat\conf\server.xml文件，增加如下蓝色选中区内容：</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_05.png" alt="" /> </p>
<p>　　三、打开tomcat\webapps\cms623\WEB-INF\config\opencms-system.xml，增加如下蓝色选中区内容：</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_06.png" alt="" /></p>
<p>　　四、重启tomat，登陆到OpenCms，这时在&#8220;站点&#8221;列表框中就会出现我们创建的网站&#8220;我的测试站点&#8221;，发，如下图：</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_07.png" alt="" /> </p>
<p>　　切换到&#8220;我的测试站点&#8221;，显示如下图，这就是我们网站的&#8220;根目录&#8221;了&#8230;&#8230;</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_08.png" alt="" /></p>
<p>&nbsp;　　五、创建网站模块：</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_09.png" alt="" /></p>
<p>　　创建模板内容如下：</p>
<div style="padding: 4px 5.4pt; background: none repeat scroll 0% 0% #e6e6e6; width: 95%; border: 0.5pt solid windowtext;">
<div><img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /><span style="color: #000000;">&lt;%</span><span style="color: #000000;">@&nbsp;taglib&nbsp;prefix</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">cms</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;uri</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">http://www.opencms.org/taglib/cms</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">%&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;</span><span style="color: #000000;">html</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;</span><span style="color: #000000;">head</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;</span><span style="color: #000000;">title</span><span style="color: #000000;">&gt;&lt;</span><span style="color: #000000;">cms:property&nbsp;name</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">Title</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">/&gt;&lt;/</span><span style="color: #000000;">title</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;</span><span style="color: #000000;">meta&nbsp;HTTP</span><span style="color: #000000;">-</span><span style="color: #000000;">EQUIV</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">CONTENT-TYPE</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;CONTENT</span><span style="color: #000000;">=</span><span style="color: #000000;">"</span><span style="color: #000000;">text/html;&nbsp;CHARSET=&lt;cms:property&nbsp;name=</span><span style="color: #000000;">"</span><span style="color: #000000;">content</span><span style="color: #000000;">-</span><span style="color: #000000;">encoding</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;default=</span><span style="color: #000000;">"</span><span style="color: #000000;">UTF</span><span style="color: #000000;">-</span><span style="color: #000000;">8</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;/&gt;</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">/&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;/</span><span style="color: #000000;">head</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;</span><span style="color: #000000;">body</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;</span><span style="color: #000000;">h2</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">测试网站的模板</span><span style="color: #000000;">&lt;/</span><span style="color: #000000;">h2</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;</span><span style="color: #000000;">cms:include&nbsp;element</span><span style="color: #000000;">=</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">body</span><span style="color: #000000;">"</span><span style="color: #000000;">/&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;/</span><span style="color: #000000;">body</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"><br />
<img src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" alt="" align="top" /></span><span style="color: #000000;">&lt;/</span><span style="color: #000000;">html</span><span style="color: #000000;">&gt;</span></div>
</div>
<p>　　六、创建项目，包含网站资源和模块资源（项目的详细介绍以后会单独的文章，在此先不多说），如下图：</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_14.png" alt="" /></p>
<p>　　七、用模板生成页面，切换到testWebProj项目，再切换到&#8220;我的测试站点&#8221;，新建&#8220;页面&#8221;，如下图：</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_010.png" alt="" /> </p>
<p>　　名称输入为&#8220;index.html&#8221;，也可输入&#8220;index&#8221;系统会自动增加&#8220;.html&#8221;的后缀，模板选择刚刚创建的&#8220;我的测试网站——模板一&#8221;</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_011.png" alt="" /> </p>
<p>　　创建页面后，编辑页面，输入内容</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_012.png" alt="" /></p>
<p>　　保存，浏览效果如下：</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_013.png" alt="" /></p>
<p>　　八、发布项目，如下图，确定当前项目为&#8220;testWebProj&#8221;，单击&#8220;发布项目&#8221;</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_17.png" alt="" />&nbsp;</p>
<p>　　发布完成后，切换到Online项目，站点选择&#8220;我的测试站点&#8221;</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_18.png" alt="" /> </p>
<p>　　&nbsp;点击浏览index.html，结果如下图：</p>
<p><img src="http://p.blog.csdn.net/images/p_blog_csdn_net/qianxuncms/291721/o_19.png" alt="" /></p>
这时浏览器的URL为：<a href="http://localhost:8081/cms623/opencms/index.html">http://localhost:8081/cms623/opencms/index.html</a>，退出OpenCms，可以通过这个URL直接访问OpenCms创建的网站了，loalhost换成局域网IP后，局域网内的其它机器也就可以同样浏览这个网站，至此就通过OpenCms创建了一个简单的网站&#8230;&#8230;<br />
<br />
<img src ="http://www.blogjava.net/alancxx/aggbug/342928.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/alancxx/" target="_blank">蜂鸟</a> 2011-01-13 15:12 <a href="http://www.blogjava.net/alancxx/articles/342928.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>