﻿<?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-linlinyu-文章分类-servlet</title><link>http://www.blogjava.net/linlinyu/category/27483.html</link><description>linlinyu</description><language>zh-cn</language><lastBuildDate>Mon, 26 Nov 2007 12:52:45 GMT</lastBuildDate><pubDate>Mon, 26 Nov 2007 12:52:45 GMT</pubDate><ttl>60</ttl><item><title>servlet CompressionFilter(yui-ext实践)</title><link>http://www.blogjava.net/linlinyu/articles/163286.html</link><dc:creator>linlin yu</dc:creator><author>linlin yu</author><pubDate>Mon, 26 Nov 2007 09:45:00 GMT</pubDate><guid>http://www.blogjava.net/linlinyu/articles/163286.html</guid><wfw:comment>http://www.blogjava.net/linlinyu/comments/163286.html</wfw:comment><comments>http://www.blogjava.net/linlinyu/articles/163286.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/linlinyu/comments/commentRss/163286.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/linlinyu/services/trackbacks/163286.html</trackback:ping><description><![CDATA[yui-ext的文件太大，采用压缩方式传输将大减小文件大小。<br />
采用过滤器方式对请求和响应进行压缩，不失为一种好的解决方案，本人采用tomcat示例代码中自带的压缩过滤器进行配置，在jboss中通过测试，达到很高的压缩比和性能<br />
步骤如下：<br />
<br />
1、&lt;TOMCAT-HOME&gt;\webapps\servlets-examples\WEB-INF\classes\compressionFilters<br />
2、CompressionFilter.java，CompressionResponseStream.java，CompressionServletResponseWrapper.java<br />
3、web.xml 
<img src ="http://www.blogjava.net/linlinyu/aggbug/163286.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/linlinyu/" target="_blank">linlin yu</a> 2007-11-26 17:45 <a href="http://www.blogjava.net/linlinyu/articles/163286.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用 Java Servlets 2.4 来执行过滤</title><link>http://www.blogjava.net/linlinyu/articles/163040.html</link><dc:creator>linlin yu</dc:creator><author>linlin yu</author><pubDate>Sun, 25 Nov 2007 14:21:00 GMT</pubDate><guid>http://www.blogjava.net/linlinyu/articles/163040.html</guid><wfw:comment>http://www.blogjava.net/linlinyu/comments/163040.html</wfw:comment><comments>http://www.blogjava.net/linlinyu/articles/163040.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/linlinyu/comments/commentRss/163040.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/linlinyu/services/trackbacks/163040.html</trackback:ping><description><![CDATA[<a href="http://www.ibm.com/developerworks/cn/java/j-pj2ee10/index.html">J2EE 探索者: 使用 Java Servlets 2.4 来执行过滤</a> 
<img src ="http://www.blogjava.net/linlinyu/aggbug/163040.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/linlinyu/" target="_blank">linlin yu</a> 2007-11-25 22:21 <a href="http://www.blogjava.net/linlinyu/articles/163040.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ServletContextListener和HttpSessionListener 应用</title><link>http://www.blogjava.net/linlinyu/articles/163022.html</link><dc:creator>linlin yu</dc:creator><author>linlin yu</author><pubDate>Sun, 25 Nov 2007 13:23:00 GMT</pubDate><guid>http://www.blogjava.net/linlinyu/articles/163022.html</guid><wfw:comment>http://www.blogjava.net/linlinyu/comments/163022.html</wfw:comment><comments>http://www.blogjava.net/linlinyu/articles/163022.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/linlinyu/comments/commentRss/163022.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/linlinyu/services/trackbacks/163022.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1，ServletContextListenerpackage&nbsp;com.soyoung.xxx.util;import&nbsp;java.util.Properties;import&nbsp;javax.servlet.ServletContext;import&nbsp;javax.servlet.ServletContextEvent;import&n...&nbsp;&nbsp;<a href='http://www.blogjava.net/linlinyu/articles/163022.html'>阅读全文</a><img src ="http://www.blogjava.net/linlinyu/aggbug/163022.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/linlinyu/" target="_blank">linlin yu</a> 2007-11-25 21:23 <a href="http://www.blogjava.net/linlinyu/articles/163022.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Servlet中的八大Listener </title><link>http://www.blogjava.net/linlinyu/articles/162534.html</link><dc:creator>linlin yu</dc:creator><author>linlin yu</author><pubDate>Fri, 23 Nov 2007 01:49:00 GMT</pubDate><guid>http://www.blogjava.net/linlinyu/articles/162534.html</guid><wfw:comment>http://www.blogjava.net/linlinyu/comments/162534.html</wfw:comment><comments>http://www.blogjava.net/linlinyu/articles/162534.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/linlinyu/comments/commentRss/162534.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/linlinyu/services/trackbacks/162534.html</trackback:ping><description><![CDATA[<p>&nbsp;</p>
<p>1. Servlet中的Listener和Event: </p>
<p>在JSP 2.0/Servlet 2.4中，共有八个Listener接口，六个Event类别。 <br />
ServletContextListener接口 <br />
[接口方法] contextInitialized()与 contextDestroyed() <br />
[接收事件] ServletContextEvent <br />
[触发场景] 在Container加载Web应用程序时（例如启动 Container之后），会呼叫contextInitialized()，而当容器移除Web应用程序时，会呼叫contextDestroyed ()方法。 </p>
<p>ServletContextAttributeListener <br />
[接口方法] attributeAdded()、 attributeReplaced()、attributeRemoved() <br />
[接收事件] ServletContextAttributeEvent <br />
[触发场景] 若有对象加入为application（ServletContext）对象的属性，则会呼叫attributeAdded()，同理在置换属性与移除属性时，会分别呼叫attributeReplaced()、attributeRemoved()。 </p>
<p>HttpSessionListener <br />
[接口方法] sessionCreated()与sessionDestroyed () <br />
[接收事件] HttpSessionEvent <br />
[触发场景] 在session （HttpSession）对象建立或被消灭时，会分别呼叫这两个方法。 </p>
<p>HttpSessionAttributeListener <br />
[接口方法] attributeAdded()、 attributeReplaced()、attributeRemoved() <br />
[接收事件] HttpSessionBindingEvent <br />
[触发场景] 若有对象加入为session（HttpSession）对象的属性，则会呼叫attributeAdded()，同理在置换属性与移除属性时，会分别呼叫attributeReplaced()、 attributeRemoved()。 </p>
<p>HttpSessionActivationListener <br />
[接口方法] sessionDidActivate()与 sessionWillPassivate() <br />
[接收事件] HttpSessionEvent <br />
[触发场景] Activate与Passivate是用于置换对象的动作，当session对象为了资源利用或负载平衡等原因而必须暂时储存至硬盘或其它储存器时（透过对象序列化），所作的动作称之为Passivate，而硬盘或储存器上的session对象重新加载JVM时所采的动作称之为Activate，所以容易理解的，sessionDidActivate()与 sessionWillPassivate()分别于Activeate后与将Passivate前呼叫。 </p>
<p>ServletRequestListener <br />
[接口方法] requestInitialized()与 requestDestroyed() <br />
[接收事件] RequestEvent <br />
[触发场景] 在request（HttpServletRequest）对象建立或被消灭时，会分别呼叫这两个方法。 </p>
<p>ServletRequestAttributeListener <br />
[接口方法] attributeAdded()、 attributeReplaced()、attributeRemoved() <br />
[接收事件] HttpSessionBindingEvent <br />
[触发场景] 若有对象加入为request（HttpServletRequest）对象的属性，则会呼叫attributeAdded()，同理在置换属性与移除属性时，会分别呼叫attributeReplaced()、 attributeRemoved()。 </p>
<p>HttpSessionBindingListener <br />
[接口方法] valueBound()与valueUnbound() <br />
[接收事件] HttpSessionBindingEvent <br />
[触发场景] 实现HttpSessionBindingListener接口的类别，其实例如果被加入至session（HttpSession）对象的属性中，则会呼叫 valueBound()，如果被从session（HttpSession）对象的属性中移除，则会呼叫valueUnbound()，实现HttpSessionBindingListener接口的类别不需在web.xml中设定。 </p>
<p>2. 如何注册Servlet中的事件 :<br />
实现上面这几个接口的类别，除了HttpSessionBindingListener外,必须在web.xml中向容器注册，容器才会在对应的事件发生时呼叫对应的类别，如： <br />
&nbsp;&lt; listener &gt;&nbsp; <br />
&nbsp;&lt; listener-class &gt; demo.servlet.listener.CustomServletContextListener&nbsp;&nbsp; </p>
<p>3. Servlet事件的应用实例 <br />
看到这里,你也许会有疑问: 了解这些 listener和event 有什么用呢?我平时开发没有用到这些,一样也能完成任务啊. </p>
<p>不错,在日常的开发中很少用到这些事件处理的方面,但是在某些情况下使用事件处理机制却可以达到事半功倍的效果,例如下面两个例子: </p>
<p>4.Java类实例<br />
==========<br />
//侦听启动和关闭<br />
import javax.servlet.ServletContextListener;<br />
import javax.servlet.*;</p>
<p>public class TigerListen implements ServletContextListener {<br />
&nbsp;public void contextInitialized(ServletContextEvent sce)<br />
&nbsp;{<br />
&nbsp; System.out.print("Init") ;<br />
&nbsp;}<br />
&nbsp;public void contextDestroyed(ServletContextEvent sce)<br />
&nbsp;{<br />
&nbsp; System.out.print("Destroved") ;<br />
&nbsp;}<br />
}</p>
<p>对应的web.xml是<br />
============<br />
&lt;!--l version="1.0" encoding="UTF-8--&gt; <br />
&nbsp;&nbsp;&nbsp; TigerListen <br />
&nbsp;&nbsp; </p>
<p><br />
============<br />
</p>
<img src ="http://www.blogjava.net/linlinyu/aggbug/162534.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/linlinyu/" target="_blank">linlin yu</a> 2007-11-23 09:49 <a href="http://www.blogjava.net/linlinyu/articles/162534.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>