﻿<?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-志成中国</title><link>http://www.blogjava.net/jiadongpo/</link><description>May there be enough clouds in your life to make a beautiful sunset!</description><language>zh-cn</language><lastBuildDate>Sun, 12 Apr 2026 17:14:20 GMT</lastBuildDate><pubDate>Sun, 12 Apr 2026 17:14:20 GMT</pubDate><ttl>60</ttl><item><title>PL/SQL Developer 9.0.6.1665 &amp; 10.0.5.1710 无限用户注...</title><link>http://www.blogjava.net/jiadongpo/archive/2013/10/15/404994.html</link><dc:creator>志成中国</dc:creator><author>志成中国</author><pubDate>Tue, 15 Oct 2013 01:02:00 GMT</pubDate><guid>http://www.blogjava.net/jiadongpo/archive/2013/10/15/404994.html</guid><wfw:comment>http://www.blogjava.net/jiadongpo/comments/404994.html</wfw:comment><comments>http://www.blogjava.net/jiadongpo/archive/2013/10/15/404994.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/jiadongpo/comments/commentRss/404994.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiadongpo/services/trackbacks/404994.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: PL/SQL Developer version 9.0.6.1665 无限用户注册码激活码 1Product Code： 46jw8l8ymfmp2twwbuur8j9gv978m2q2du2serial Number：3072543password：xs374ca4License Numbe...&nbsp;&nbsp;<a href='http://www.blogjava.net/jiadongpo/archive/2013/10/15/404994.html'>阅读全文</a><img src ="http://www.blogjava.net/jiadongpo/aggbug/404994.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiadongpo/" target="_blank">志成中国</a> 2013-10-15 09:02 <a href="http://www.blogjava.net/jiadongpo/archive/2013/10/15/404994.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ExtJS入门——开始 </title><link>http://www.blogjava.net/jiadongpo/archive/2013/01/05/393828.html</link><dc:creator>志成中国</dc:creator><author>志成中国</author><pubDate>Sat, 05 Jan 2013 09:04:00 GMT</pubDate><guid>http://www.blogjava.net/jiadongpo/archive/2013/01/05/393828.html</guid><wfw:comment>http://www.blogjava.net/jiadongpo/comments/393828.html</wfw:comment><comments>http://www.blogjava.net/jiadongpo/archive/2013/01/05/393828.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/jiadongpo/comments/commentRss/393828.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiadongpo/services/trackbacks/393828.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp;认识ExtJSextjs是使用javascript、css和html等技术实现的主要用于创建用户界面，且与后台技术无关的前端ajax框架。extjs来源于yui，开发理念来源于传统的桌面软件开发。1.下载extjs，解压，得到目录结构o&nbsp;builds：是extjs压缩后的代码，体积更小，加载更快o&nbsp;docs&nbsp;：extjs的文档o&nbsp;examples...&nbsp;&nbsp;<a href='http://www.blogjava.net/jiadongpo/archive/2013/01/05/393828.html'>阅读全文</a><img src ="http://www.blogjava.net/jiadongpo/aggbug/393828.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiadongpo/" target="_blank">志成中国</a> 2013-01-05 17:04 <a href="http://www.blogjava.net/jiadongpo/archive/2013/01/05/393828.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>抽奖</title><link>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391100.html</link><dc:creator>志成中国</dc:creator><author>志成中国</author><pubDate>Fri, 09 Nov 2012 08:03:00 GMT</pubDate><guid>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391100.html</guid><wfw:comment>http://www.blogjava.net/jiadongpo/comments/391100.html</wfw:comment><comments>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391100.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/jiadongpo/comments/commentRss/391100.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiadongpo/services/trackbacks/391100.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 不同概率的抽奖今天为大家写个小程序。工作中有遇到一些抽奖的活动，但是你懂得，抽奖物品的概率肯定不是一样，你会发现好的东西很难抽到，经常抽到一些垃圾的东西，嘿嘿，这就是本文要说的，我们要控制抽奖物品的概率。还有顺便说一句，网上这种小程序几乎没有，很多都是等概率的抽奖balabala&#8230;需求很简单，为了更加形象，这里我们列一个表格来显示我们抽奖的物品和对应的概率（没有边框，大家凑合着看看吧，...&nbsp;&nbsp;<a href='http://www.blogjava.net/jiadongpo/archive/2012/11/09/391100.html'>阅读全文</a><img src ="http://www.blogjava.net/jiadongpo/aggbug/391100.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiadongpo/" target="_blank">志成中国</a> 2012-11-09 16:03 <a href="http://www.blogjava.net/jiadongpo/archive/2012/11/09/391100.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>关键字</title><link>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391099.html</link><dc:creator>志成中国</dc:creator><author>志成中国</author><pubDate>Fri, 09 Nov 2012 08:01:00 GMT</pubDate><guid>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391099.html</guid><wfw:comment>http://www.blogjava.net/jiadongpo/comments/391099.html</wfw:comment><comments>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391099.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jiadongpo/comments/commentRss/391099.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiadongpo/services/trackbacks/391099.html</trackback:ping><description><![CDATA[<h2><a id="viewpost1_TitleUrl" href="http://www.blogjava.net/jialisoftw/archive/2012/10/17/389744.html" style="cursor: pointer; color: #0066aa; text-decoration: none; ">Java中static、this、super、final用法</a></h2><div style="text-align: -webkit-auto; font-size: 13px; line-height: 19px; font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; background-color: #ffffff; "><div>亲：本文具体讲解了Java中static的用法，具体内容有static的静态方法、静态变量、静态类。(&#8857;o&#8857;)，你们觉得如何？</div><div>一、static</div><div>请先看下面这段程序：</div><div>public class Hello{</div><div>public static void main(String[] args){ //(1)</div><div>System.out.println("Hello,world!"); //(2)</div><div>}</div><div>}</div><div>&nbsp;</div><div>看过这段程序，对于大多数学过Java 的从来说，都不陌生。即使没有学过Java，而学过其它的高级语言，例如C，那你也应该能看懂这段代码的意思。它只是简单的输出&#8220;Hello,world&#8221;，一点别的用处都没有，然而，它却展示了static关键字的主要用法。</div><div>在1处，我们定义了一个静态的方法名为main，这就意味着告诉Java编译器，我这个方法不需要创建一个此类的对象即可使用。你还得你是怎么运行这个程序吗？一般，我们都是在命令行下，打入如下的命令(加下划线为手动输入)：</div><div>&nbsp;</div><div>javac Hello.java</div><div>java Hello</div><div>Hello,world!</div><div>&nbsp;</div><div>这就是你运行的过程，第一行用来编译Hello.java这个文件，执行完后，如果你查看当前，会发现多了一个Hello.class文件，那就是第一行产生的Java二进制字节码。第二行就是执行一个Java程序的最普遍做法。执行结果如你所料。在2中，你可能会想，为什么要这样才能输出。好，我们来分解一下这条语句。（如果没有安装Java文档，请到Sun的官方网站浏览J2SE API）首先，System是位于java.lang包中的一个核心类，如果你查看它的定义，你会发现有这样一行：public static final PrintStream out;接着在进一步，点击PrintStream这个超链接，在METHOD页面，你会看到大量定义的方法，查找println，会有这样一行：</div><div>&nbsp;</div><div>public void println(String x)</div><div>&nbsp;</div><div>好了，现在你应该明白为什么我们要那样调用了，out是System的一个静态变量，所以可以直接使用，而out所属的类有一个println方法。</div><div></div><div>静态方法</div><div>通常，在一个类中定义一个方法为static，那就是说，无需本类的对象即可调用此方法。如下所示：</div><div>class Simple{</div><div>static void go(){</div><div>System.out.println("Go...");</div><div>}</div><div>}</div><div>public class Cal{</div><div>public static void main(String[] args){</div><div>Simple.go();</div><div>}</div><div>}</div><div>&nbsp;</div><div>调用一个静态方法就是&#8220;类名.方法名&#8221;,静态方法的使用很简单如上所示。一般来说，静态方法常常为应用程序中的其它类提供一些实用工具所用，在Java的类库中大量的静态方法正是出于此目的而定义的。</div><div></div><div>静态变量</div><div>静态变量与静态方法类似。所有此类实例共享此静态变量，也就是说在类装载时，只分配一块存储空间，所有此类的对象都可以操控此块存储空间，当然对于final则另当别论了。看下面这段代码：</div><div>&nbsp;</div><div>class Value{</div><div>static int c=0;</div><div>static void inc(){</div><div>c++;</div><div>}</div><div>}</div><div>class Count{</div><div>public static void prt(String s){</div><div>System.out.println(s);</div><div>}</div><div>public static void main(String[] args){</div><div>Value v1,v2;</div><div>v1=new Value();</div><div>v2=new Value();</div><div>prt("v1.c="+v1.c+" v2.c="+v2.c);</div><div>v1.inc();</div><div>prt("v1.c="+v1.c+" v2.c="+v2.c);</div><div>}</div><div>}</div><div>&nbsp;</div><div>结果如下：</div><div>&nbsp;</div><div>v1.c=0 v2.c=0</div><div>v1.c=1 v2.c=1</div><div>&nbsp;</div><div>由此可以证明它们共享一块存储区。static变量有点类似于C中的全局变量的概念。值得探讨的是静态变量的初始化问题。我们修改上面的程序：</div><div>&nbsp;</div><div>class Value{</div><div>static int c=0;</div><div>Value(){</div><div>c=15;</div><div>}</div><div>Value(int i){</div><div>c=i;</div><div>}</div><div>static void inc(){</div><div>c++;</div><div>}</div><div>}</div><div>class Count{</div><div>public static void prt(String s){</div><div>System.out.println(s);</div><div>}</div><div>Value v=new Value(10);</div><div>static Value v1,v2;</div><div>static{</div><div>prt("v1.c="+v1.c+" v2.c="+v2.c);</div><div>v1=new Value(27);</div><div>prt("v1.c="+v1.c+" v2.c="+v2.c);</div><div>v2=new Value(15);</div><div>prt("v1.c="+v1.c+" v2.c="+v2.c);</div><div>}</div><div>public static void main(String[] args){</div><div>Count ct=new Count();</div><div>prt("ct.c="+ct.v.c);</div><div>prt("v1.c="+v1.c+" v2.c="+v2.c);</div><div>v1.inc();</div><div>prt("v1.c="+v1.c+" v2.c="+v2.c);</div><div>prt("ct.c="+ct.v.c);</div><div>}</div><div>}</div><div>&nbsp;</div><div>运行结果如下：</div><div>v1.c=0 v2.c=0</div><div>v1.c=27 v2.c=27</div><div>v1.c=15 v2.c=15</div><div>ct.c=10</div><div>v1.c=10 v2.c=10</div><div>v1.c=11 v2.c=11</div><div>ct.c=11</div><div>&nbsp;</div><div>这个程序展示了静态初始化的各种特性。如果你初次接触Java，结果可能令你吃惊。可能会对static后加大括号感到困惑。首先要告诉你的是，static定义的变量会优先于任何其它非static变量，不论其出现的顺序如何。正如在程序中所表现的，虽然v出现在v1和v2的前面，但是结果却是v1和v2的初始化在v的前面。在static{后面跟着一段代码，这是用来进行显式的静态变量初始化，这段代码只会初始化一次，且在类被第一次装载时。如果你能读懂并理解这段代码，会帮助你对static关键字的认识。在涉及到继承的时候，会先初始化父类的static变量，然后是子类的，依次类推。非静态变量不是本文的主题，在此不做详细讨论，请参考Think in Java中的讲解。</div><div></div><div>静态类</div><div>通常一个普通类不允许声明为静态的，只有一个内部类才可以。这时这个声明为静态的内部类可以直接作为一个普通类来使用，而不需实例一个外部类。如下代码所示：</div><div>&nbsp;</div><div>public class StaticCls{</div><div>public static void main(String[] args){</div><div>OuterCls.InnerCls oi=new OuterCls.InnerCls();</div><div>}</div><div>}</div><div>class OuterCls{</div><div>public static class InnerCls{</div><div>InnerCls(){</div><div>System.out.println("InnerCls");</div><div>}</div><div>}</div><div>}</div><div>&nbsp;</div><div>输出结果会如你所料。</div></div><img src ="http://www.blogjava.net/jiadongpo/aggbug/391099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiadongpo/" target="_blank">志成中国</a> 2012-11-09 16:01 <a href="http://www.blogjava.net/jiadongpo/archive/2012/11/09/391099.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>异常问题</title><link>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391098.html</link><dc:creator>志成中国</dc:creator><author>志成中国</author><pubDate>Fri, 09 Nov 2012 08:00:00 GMT</pubDate><guid>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391098.html</guid><wfw:comment>http://www.blogjava.net/jiadongpo/comments/391098.html</wfw:comment><comments>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391098.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jiadongpo/comments/commentRss/391098.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiadongpo/services/trackbacks/391098.html</trackback:ping><description><![CDATA[<div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">java try catch 谁先执行问题，你能说明白吗</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">问题1&nbsp;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp;try {}里有一个return语句，那么紧跟在这个try后的finally {}里的code会不会被执行，什么时候被执行，在return前还是后?&nbsp;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>也许你的答案是在return之前，但往更细地说，我的答案是在return中间执行，请看下面程序代码的运行结果：&nbsp;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">public &nbsp;class Test {</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>public static void main(String[] args) {</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>System.out.println(new Test().test());;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>static int test()</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>int x = 1;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>try</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">			</span>return x;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>finally</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">			</span>++x;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>---------执行结果是什么 &nbsp;为什么 ---------</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">问题2</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">下面的程序代码输出的结果是多少？</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">public class &nbsp;smallT</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>public static void &nbsp;main(String args[])</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>smallT t &nbsp;= new &nbsp;smallT();</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>int &nbsp;b &nbsp;= &nbsp;t.get();</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>System.out.println(b);</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>public int &nbsp;get()</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>try</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">			</span>return 1 ;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>finally</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">			</span>return 2 ;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">		</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp;2012-6-19 16:23 满意回答 输出是1和2，</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">20705080 回答的很好了，只有几点补充下，首先代码例子用的是基本数据类型，他们进行传值就是传值，其次finally的用途是用来回收系统资源的，没有catch也是正常的使用（不catch，把异常throw回调用方法），再有finally和return是有关系的，而且经常有人提，就是finally的代码在return前运行，这就是我为什么先说你的例子是基本数据类型的原因，因为return x（1）；被放入stack中，stack是后进先出的，等待finally运行完再运行，但他已经被赋值了就是1，如果你把代码改成这样试试看</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">public Something getSome(){</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Something s = new Something("Dog");</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;try{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return s;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp; }finally{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s.name ="cat";</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">加个类</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">class Something{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp; public String name ;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp; something(String name){</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;this.name = name;}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">因为相对于基本数据类型，引用传值传的值是个地址，return s（地址）;放入stack中，又被取出时地址不变但地址那边的数据已经是cat了赞同0| 评论&nbsp;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">第1个</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">有finally的话</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">try 里的return &nbsp; &nbsp;是先保存x的结果 &nbsp; 等待finally走完 &nbsp; 虽然x变2了 &nbsp;但是return的值还是1 &nbsp;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">因为到return的时候已经把x的值取出来 &nbsp;等待finally走完 &nbsp;不管x怎么变 &nbsp;之前的1是不会变的</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">第2个</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">return &nbsp; &nbsp; 等待finally走完 &nbsp; 但是finally里return了 &nbsp; 所以返回的是2</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp; &nbsp; 赞同0| 评论 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2012-6-19 14:54 畅捷通丶稀饭 | 五级&nbsp;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">第一个是1，因为 x=1 try里面返回的是1 后面又执行了finally 后。X 是2 但是没有返回。所以 还是1</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">第二个是2，因为finally最后执行，返回的是2. 赞同0| 评论 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2012-6-19 14:56 java2000_net |&nbsp;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "></div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">finally中的语句是一定要执行的，这点是肯定的。finally中的语句执行在try之后。通常try是要和catch（不捕获异常try就没意义了）。一般的用法是：</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">try{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">1想要执行的代码</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">}catch(Exception e){</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">&nbsp;2异常处理</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">}finally{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>3最终执行的代码</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; "><span style="white-space: pre; ">	</span>}</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">1中代码没错执行的顺序就是1-&gt;3</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">1中代码有错执行的顺序是2-&gt;3</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">finally中的代码和return是没关系的，你可以把return写在任何地方。它只和try、catch有关。假如你把问题一种finally的代码写成：</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">finally{</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">return ++x;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">}那么结果就是2了。</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">finally一定会执行，且在try或catch之后执行。</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">不知道这么说能明白吗~~~</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">不明白可以问，我再回答~~~ 赞同0| 评论 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2012-6-19 15:22 黑夜也明亮 | 四级&nbsp;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">问题1：答案 1。因为return的值在执行finally之前已经确定下来了。所以即使在finally里怎么该值它始终是1，除非在finally里在return ++x重新修改返回的值。return x它不会直接返回值回去而是等程序执行完finaly后才返回。</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">你因该有听过有finaly的程序一定会执行finaly代码吧。</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">问题2：答案 2。根据一的结论二也是成立的。 赞同0| 评论 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;2012-6-19 16:41 iedgtg | 五级&nbsp;</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">第一个问题：输出的是1，因为finally总是在try-catch执行之后执行，而且，一定是在return之前执行。第一个问题里应该是在return x；之前执行，但是，此时return的值已经固定了，就是说finally再执行也改变不了return的值，当然x的值成了2，但是return的值已经固定为1了。</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">第二个问题：输出的是2，因为finally一定是在return之前执行，本来程序return的值是1，即将要return了，但是有finally，所以finally先执行，所以return的值是2。</div><div style="font-family: 微软雅黑; font-size: 18px; line-height: normal; text-align: -webkit-auto; ">但是第二种情况不建议使用，就是说finally里不建议用return，因为这样finally就没有正常的执行完毕，这是不推荐的。 赞同0| 评论 &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</div><img src ="http://www.blogjava.net/jiadongpo/aggbug/391098.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiadongpo/" target="_blank">志成中国</a> 2012-11-09 16:00 <a href="http://www.blogjava.net/jiadongpo/archive/2012/11/09/391098.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>当当网问题get_post问题</title><link>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391097.html</link><dc:creator>志成中国</dc:creator><author>志成中国</author><pubDate>Fri, 09 Nov 2012 07:49:00 GMT</pubDate><guid>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391097.html</guid><wfw:comment>http://www.blogjava.net/jiadongpo/comments/391097.html</wfw:comment><comments>http://www.blogjava.net/jiadongpo/archive/2012/11/09/391097.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jiadongpo/comments/commentRss/391097.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiadongpo/services/trackbacks/391097.html</trackback:ping><description><![CDATA[GET与Post提交问题：
----------------------------------------------
运行login.jsp点登陆时调用两次toLoginAction
<action name="toLoginAction" class="com.tarena.web.action.user.ToLoginAction">
<result name="main">
/WEB-INF/jsp/main/main.jsp
</result>
<result name="login_form">
/WEB-INF/jsp/user/login_form.jsp
</result>
</action>
所以取得结果在toLoginAction的execute里运行两次
String pass = iuserDao.findPassWordByEmail(email);
System.out.println(email);
System.out.println(pass);
也输出两次：条件不同，输出内容不同
当login_form.jsp里的表单
<form action="user/toLoginAction" id="ctl00" method="post">
     使用post方式提交时，控制台输出如下：
     root@root.com
     root
     null
     null
     当login_form.jsp里的表单
     <form action="user/toLoginAction" id="ctl00" method="post">
         使用get方式提交时，控制台输出如下：
         root@root.com
         root
         root@root.com
         root
         解决方案一：加struts的token拦截器，只让表单提交一次。
         解决方案二：转一个action，就是把他自动提交的那个请求通过action的转发取消掉。
         问题：
         为什么get和post的默认请求后取到的值会不同？
         为什么在window的电脑里没有问题？
         ----------------------------------------------
         在ｗｉｎｄｏｗ下，正常输出如下：
         root@root.com
         root
         ----------------------------------------------
         缓存问题（服务器缓存或者浏览器缓存或者浏览器bug），导致提交两次，与操作系统、程序、js提交是没关系！
         get：通过URL路传参，当页面再次提交，还会把URL中的值传递给action，所有属性再次被填充就不出现null值
         post:URL路径没有信息，当再次提交，就出现属性就出现null值
         你在学生机器上,把在tomcat中work目录删除、在把\webapps 中项目删除，把web容器缓存清空下！
         或者把学生机器重新启动下，把服务器缓存彻底清除下!
         ----------------------------------------------
         ----------------------------------------------
         图片：struts-user.xml配置如下：
         ----------------------------------------------
         ToLoginAction类如下
         ：
         ----------------------------------------------
         进入主页面的URL如：
         ----------------------------------------------
         登陆的URL如：
         ----------------------------------------------
         登陆界面：
         ----------------------------------------------
         ｗｉｎｄｗｏ系统下提交输出如图：
         ----------------------------------------------
         Linux系统下，采用ｇｅｔ提交时
         ----------------------------------------------
         Linux系统下，采用ｐｏｓｔ提交时
         ----------------------------------------------
         最后在学生电脑上又试了几次，ｇｅｔ方式提交正常和ｗｉｎｄｏｗ系统下一样了，ｐｏｓｔ方式
         提交还是没改变，不知道为什么。
         ----------------------------------------------
         邮件内容如下：
         发件人：贾东坡
         发送时间： 2012-11-08 09:37
         收件人：zhaozq
         主题： dang_get_post
         赵老师：
         您好。学生的程序有点问题，想听一下您的理解。问题描述如下：
         进入当当网的main页面，点登陆输入用户名，密码后，点登陆会请求ToLoginAction，
         进入main页面。在ToLoginAction里打印了email和pass，登陆之后输出结果在linux
         系统下与window下不同。window系统下正常输出，而在linux系统下有输出两次，并且
         login_form.jsp时表单提交方法为get时，两次都能正常输出；当提交方式为post里，第
         二次为null。例如：
         在window系统下：
         我们在输入框，输入用户名：root@qq.com 密码root，会输出如下：
         root@qq.com
         root
         在linux系统下
         当login_form.jsp的表单提交为get时，输出root@qq.comroot时，
         输出如下：
         root@qq.com
         root
         root@qq.com
         root
         当login_form.jsp的表单提交为post时，输入root@qq.comroot时，
         输出如下：
         root@qq.com
         root
         null
         null
         原因分析：首先想的是submit按钮在使用js时，有自动提交功能，可是也没使用js啊，
         还有在linux系统有自己的form机制。还有一个是程序有问题。
         解决方案：我给这个action加了个token表单拦截器就可以。说明是表单提交两次。
         问题是：1.为什么表单会提交两次，而在window下只提交一个。
         2.为什么在linux下用get和post提交方式第二次取到的值会不一样。
         3. form提交时在linux系统下与window有什么不一样。
         附件内是程序源码，谢谢您的宝贵时间。
         祝: 身体健康,工作顺利!
         贾东坡北方区 北方基地项目部 项目经理
         E-mail: jiadp@tarena.com.cn
         Address: 北京市昌平区北七家镇宏富创业园科技园综合楼3层
         Mobile: 18301442726
         Fax: 86-10-82823773
         Website: www.tarena.com.cn
         ----------------------------------------------
         发件人：zhaozq
         发送时间： 2012-11-08 11:21
         收件人：jiadp
         主题： 回复: dang_get_post
         贾老师：
         您好！
         你们班的学生机器是不是采用的是云服务器？
         zhaozq
         ----------------------------------------------
         赵老师：
         您好。我们班的机器都是普通主机，linux系统的，不是用核的，也不是云服务器。
         谢谢您的宝贵时间。
         ----------------------------------------------
         贾老师：
         您好！
         缓存问题（服务器缓存或者浏览器缓存或者浏览器bug），导致提交两次，与操作系统、程序、js提交是没关系！
         get：通过URL路传参，当页面再次提交，还会把URL中的值传递给action，所有属性再次被填充就不出现null值
         post:URL路径没有信息，当再次提交，就出现属性就出现null值
         你在学生机器上,把在tomcat中work目录删除、在把\webapps 中项目删除，把web容器缓存清空下！
         或者把学生机器重新启动下，把服务器缓存彻底清除下!
         zhaozq
         ----------------------------------------------
         赵老师：
         您好。您的分析很有道理，可是我用另外几台电脑，试了也不行，所以不该是缓存问题。
         浏览器bug，这个还没测试，因为所有学生的电脑都是同样的系统，同样的浏览器，都是这个
         情况。要是缓存问题，怎么可能用token拦截了，拦截下的是缓存的，还是我自己提交的，以及
         在哪地方缓存。还有个问题就是，在web学习的时候也有表单提交，为什么就没有这种情况，是
         不是和struts有关。
         谢谢，您的宝贵时间。
         ----------------------------------------------
         赵老师回复：
         您好。您的分析很有道理，可是我用另外几台电脑，试了也不行，所以不该是缓存问题。
         浏览器bug，这个还没测试，因为所有学生的电脑都是同样的系统，同样的浏览器，都是这个
         情况。要是缓存问题，怎么可能用token拦截了，拦截下的是缓存的，还是我自己提交的，以及
         token不是拦截了，而是令牌值相同不在提交，不是在window 系统提交没问题吗？那就与程序无关了，那就是系统
         缓存或者浏览器缓存中，正常当浏览器关闭，缓存中数据就清除，但是如果机房比较热、服务器处于长期运营等情况都会导致缓存信息无法清空，而影响程序执行
         在哪地方缓存。还有个问题就是，在web学习的时候也有表单提交，为什么就没有这种情况，是
         缓存
         不是和struts有关。
         和struts没有关系，而是与计算机硬件设备有关，这个影响具体什么时候会造成，这个都不能预计，这种情况一般比较少见。
         祝: 身体健康,工作顺利!
         ----------------------------------------------
         赵老师：
         您好。谢谢您的详细解答，真是受益匪浅，这个问题可以划上句话了。同学们都很喜欢听
         您讲课，风趣幽默、也易于接受，期待您更多的讲解。
         谢谢，您的精神讲解。您辛苦了。
         祝: 身体健康,工作顺利!
         ----------------------------------------------
         ----------------------------------------------
         Debug linux系统下截图如下：
         ----------------------------------------------
         get方式时：正常情况下：输出和win一样了。
         root@root.com
         root
         ----------------------------------------------
         post方式时：输出如下：
         root@root.com
         root
         null
         null
         -------------------------------------------------------------------------------------------
<img src ="http://www.blogjava.net/jiadongpo/aggbug/391097.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiadongpo/" target="_blank">志成中国</a> 2012-11-09 15:49 <a href="http://www.blogjava.net/jiadongpo/archive/2012/11/09/391097.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Servlet生命周期 </title><link>http://www.blogjava.net/jiadongpo/archive/2012/10/20/389915.html</link><dc:creator>志成中国</dc:creator><author>志成中国</author><pubDate>Sat, 20 Oct 2012 05:01:00 GMT</pubDate><guid>http://www.blogjava.net/jiadongpo/archive/2012/10/20/389915.html</guid><wfw:comment>http://www.blogjava.net/jiadongpo/comments/389915.html</wfw:comment><comments>http://www.blogjava.net/jiadongpo/archive/2012/10/20/389915.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jiadongpo/comments/commentRss/389915.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiadongpo/services/trackbacks/389915.html</trackback:ping><description><![CDATA[<p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;大多数程序员都知道Servlet的生命周期，简单的概括这就分为四步：servlet类加载---&gt;实例化---&gt;服务---&gt;销 毁。对这个过程只是肤浅了解下，对于servlet何时被销毁，还是不太情楚。下面我们描述一下Tomcat与Servlet是如何工作的,首先看下面的 时序图.</p><p style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; text-align: center; "><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Application%20Data/youdao/ynote/images/E7488FB34BCC42DF8E56210D58447889/6e4a2336-7c0b-33b3-b4f7-6fc7cb51f5ea.jpeg" alt="" title="点击查看原始大小图片" height="366" width="700" data-media-type="image" data-inited="true" style="cursor: default; display: inline-block; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">1、Web Client 向Servlet容器（Tomcat）发出Http请求</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">2、Servlet容器接收Web Client的请求</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">3、Servlet容器创建一个HttpRequest对象，将Web Client请求的信息封装到这个对象中</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">4、Servlet容器创建一个HttpResponse对象</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">5、Servlet容器调用HttpServlet对象的service方法，把HttpRequest对象与HttpResponse对象作为参数</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">&nbsp;&nbsp;&nbsp;&nbsp; 传给 HttpServlet对象</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">6、HttpServlet调用HttpRequest对象的有关方法，获取Http请求信息</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">7、HttpServlet调用HttpResponse对象的有关方法，生成响应数据</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">8、Servlet容器把HttpServlet的响应结果传给Web Client</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">对于Servlet容器(Tomcat)与HttpServlet是怎样进行交互的呢，看下类图</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Application%20Data/youdao/ynote/images/FACB143F9E254007BAFB874A137547EA/45a5f265-329f-3400-ab54-935f2d59f9bb.jpeg" alt="" height="420" width="672" data-media-type="image" data-inited="true" style="cursor: default; display: inline-block; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">Servlet的框架是由两个Java包组成的：javax.servlet与javax.servlet.http。在javax.servlet包中 定义了所有的Servlet类都必须实现或者扩展的通用接口和类。在javax.servlet.http包中定义了采用Http协议通信的 HttpServlet类。Servlet的框架的核心是javax.servlet.Servlet接口，所有的Servlet都必须实现这个接口。</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">在Servlet接口中定义了5个方法，</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">其中3个方法代表了Servlet的生命周期：</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">1、init方法：负责初始化Servlet对象。</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">2、service方法：负责响应客户的请求。</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><span style="color: #ff0000; ">3、destroy方法：当Servlet对象退出生命周期时，负责释放占用的资源。</span></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><strong>一、创建Servlet对象的时机</strong></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">1、Servlet容器启动时：读取web.xml配置文件中的信息，构造指定的Servlet对象，创建ServletConfig对象，同时将ServletConfig对象作为参数来调用Servlet对象的init方法。</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">2、在Servlet容器启动后：客户首次向Servlet发出请求，Servlet容器会判断内存中是否存在指定的Servlet对象，如果没有则创建 它，然后根据客户的请求创建HttpRequest、&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpResponse对象，从而调用Servlet</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp; 对象的service方法。</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">3、Servlet的类文件被更新后，重新创建Servlet</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Servlet容器在启动时自动创建Servlet，这是由在web.xml文件中为Servlet设置的&lt;load-on-startup&gt;属性决定</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 的。从中我们也能看到同一个类型的Servlet对象在Servlet容器中以单例的形式存在。</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><strong>二、销毁Servlet对象的时机</strong></p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">1、<span style="color: #ff0000; ">Servlet容器停止或者重新启动</span>：Servlet容器调用Servlet对象的destroy方法来释放资源。以上所讲的就是Servlet对象的生命周期。那么Servlet容器如何知道创建哪一个Servlet对象？</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">Servlet对象如何配置？实际上这些信息是通过读取web.xml配置文件来实现的。</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">我们来看一下web.xml文件中的Servlet对象的配置节信息</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&lt;servlet&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;servlet-name&gt;action&lt;servlet-name&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;init-param&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-name&gt;config&lt;/param-name&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;/init-param&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;init-param&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-name&gt;detail&lt;/param-name&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-value&gt;2&lt;/param-value&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;/init-param&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;init-param&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-name&gt;debug&lt;/param-name&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;param-value&gt;2&lt;/param-value&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;/init-param&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;load-on-startup&gt;2&lt;/load-on-startup&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&lt;/servlet&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&lt;servlet-mapping&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;servlet-name&gt;action&lt;/servlet-name&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;*.do&lt;/url-pattern&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&lt;/servlet-mapping&gt;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－－</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">下面对上面的配置节信息进行解析</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">servlet-name：Servlet对象的名称</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">servlet-class：创建Servlet对象所要调用的类</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">param-name：参数名称</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">param-value：参数值</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">load-on-startup：Servlet容器启动时加载Servlet对象的顺序</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">servlet-mapping/servlet-name：要与servlet中的servlet-name配置节内容对应</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">url-pattern：客户访问的Servlet的相对URL路径</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 当Servlet容器启动的时候读取&lt;servlet&gt;配置节信息，根据&lt;servlet-class&gt;配置节信息创建 Servlet对象，同时根据&lt;init-param&gt;配置节信息创建HttpServletConfig对象，然后执行Servlet对象 的init方法，并且根据&lt;load-on-startup&gt;配置节信息来决定创建Servlet对象的顺序，如果此配置节信息为负数或者没 有配置，那么在Servlet容器启动时，将不加载此Servlet对象。当客户访问Servlet容器时，Servlet容器根据客户访问的URL地 址，通过&lt;servlet-mapping&gt;配置节中的&lt;url-pattern&gt;配置节信息找到指定的Servlet对象，并 调用此Servlet对象的service方法。</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; "><a href="http://www.diybl.com/course/3_program/java/javajs/20081123/152271.html" style="cursor: pointer; color: #7d0000; "></a>&nbsp;</p><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">为了验证下，我新建了一个web app工程，新建一个Servlet，如下:</p><div id="" style="font-size: 18px; text-align: -webkit-auto; font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; width: 679px; margin-left: 9px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; word-break: break-all; word-wrap: break-word; line-height: 25.200000762939453px; "><div><div style="padding-right: 3px; padding-bottom: 3px; padding-left: 3px; margin: 0px; font-weight: bold; ">Java代码&nbsp;&nbsp;<a href="http://blog.csdn.net/tender001/article/details/8063201" title="收藏这段代码" style="cursor: pointer; color: #7d0000; "><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Application%20Data/youdao/ynote/images/31C837B1B837443ABF6A3D8C1A2545E3/icon_star.png" alt="收藏代码" data-media-type="image" data-inited="true" style="cursor: default; display: inline-block; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; " /></a></div></div><ol start="1" style="font-size: 1em; line-height: 1.4em; margin-left: 0px; padding-top: 2px; padding-bottom: 2px; border: 1px solid #d1d7dc; color: #2b91af; "><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">package</span>&nbsp;com.tdt.servlet;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">import</span>&nbsp;java.io.IOException;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">import</span>&nbsp;java.io.PrintWriter;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">import</span>&nbsp;javax.servlet.ServletException;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">import</span>&nbsp;javax.servlet.http.HttpServlet;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">import</span>&nbsp;javax.servlet.http.HttpServletRequest;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">import</span>&nbsp;javax.servlet.http.HttpServletResponse;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; "><span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">class</span>&nbsp;TestServlet&nbsp;<span style="color: #7f0055; ">extends</span>&nbsp;HttpServlet&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">void</span>&nbsp;doGet(HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">throws</span>&nbsp;ServletException,&nbsp;IOException&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">this</span>.doPost(request,&nbsp;response);&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">void</span>&nbsp;doPost(HttpServletRequest&nbsp;request,&nbsp;HttpServletResponse&nbsp;response)&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">throws</span>&nbsp;ServletException,&nbsp;IOException&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;response.setContentType("text/html");&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PrintWriter&nbsp;out&nbsp;=&nbsp;response.getWriter();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.println("Hello,this&nbsp;is&nbsp;a&nbsp;test");&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.flush();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;out.close();&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">void</span>&nbsp;destroy()&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.err.println(getServletName()+"生命周期结束");;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #7f0055; ">public</span>&nbsp;<span style="color: #7f0055; ">void</span>&nbsp;init()&nbsp;<span style="color: #7f0055; ">throws</span>&nbsp;ServletException&nbsp;{&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(getServletName()+"执行初始化");&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="font-size: 1em; margin-left: 38px; padding-right: 0px; border-left-width: 1px; border-left-color: #d1d7dc; background-color: #fafafa; line-height: 18px; ">}&nbsp;&nbsp;</li></ol></div><p style="text-align: -webkit-auto; margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px; font-family: Helvetica, Tahoma, Arial, sans-serif; line-height: 25.200000762939453px; ">&nbsp;当servlet被销毁时会在控制台上打印提示语句，不过我发现在tomcat中，只要不停止web容器，servlet是不会被销毁的。有没有什么方 法，当service方法执行完毕就销毁这个servlet呢，我问了下老师，他说写一个监听器，不过我不知道怎么去实现它，如果有朋友知道实现的过程， 还请赐教。</p><img src ="http://www.blogjava.net/jiadongpo/aggbug/389915.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiadongpo/" target="_blank">志成中国</a> 2012-10-20 13:01 <a href="http://www.blogjava.net/jiadongpo/archive/2012/10/20/389915.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Oracle笔记-薛海露老师</title><link>http://www.blogjava.net/jiadongpo/archive/2012/10/20/389914.html</link><dc:creator>志成中国</dc:creator><author>志成中国</author><pubDate>Sat, 20 Oct 2012 04:57:00 GMT</pubDate><guid>http://www.blogjava.net/jiadongpo/archive/2012/10/20/389914.html</guid><wfw:comment>http://www.blogjava.net/jiadongpo/comments/389914.html</wfw:comment><comments>http://www.blogjava.net/jiadongpo/archive/2012/10/20/389914.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/jiadongpo/comments/commentRss/389914.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/jiadongpo/services/trackbacks/389914.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Oracle学习共享、基础加强学习&nbsp;&nbsp;<a href='http://www.blogjava.net/jiadongpo/archive/2012/10/20/389914.html'>阅读全文</a><img src ="http://www.blogjava.net/jiadongpo/aggbug/389914.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/jiadongpo/" target="_blank">志成中国</a> 2012-10-20 12:57 <a href="http://www.blogjava.net/jiadongpo/archive/2012/10/20/389914.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>