<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-28274498</id><updated>2020-02-29T20:49:38.832+11:00</updated><category term="programming"/><category term="Web marketing"/><category term="operating system"/><category term="Miscellaneous"/><category term="business"/><category term="IT"/><category term="web design"/><category term="database"/><category term="computer networking"/><category term="software engineering"/><category term="finance"/><category term="Car"/><category term="hardware"/><category term="Health"/><category term="Photography"/><category term="Sport"/><category term="cosmetics"/><category term="game"/><title type='text'>Terry Su</title><subtitle type='html'>心态决定姿态，姿态决定生态</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://suange.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default?alt=atom&amp;redirect=false'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default?alt=atom&amp;start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>325</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-28274498.post-8296569323259733420</id><published>2014-03-04T07:19:00.003+11:00</published><updated>2014-03-04T07:19:10.783+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="business"/><title type='text'>中国一线二线三线城市名单 </title><content type='html'>&lt;br /&gt;中国一线二线三线城市名单：&lt;br /&gt;　　一线城市：北京 上海 广州 深圳&lt;br /&gt;　　准一线 ：天津&lt;br /&gt;　　二线城市：&lt;br /&gt;　　二线强： 1南京 2武汉 3沈阳 4西安 5成都 6重庆 7杭州8青岛 9大连 10宁波&lt;br /&gt;　　二线中： 11济南 12哈尔滨 13长春14厦门15郑州 16长沙 17福州18乌鲁木齐 19昆明20兰州21苏州 22无锡&lt;br /&gt;　　二线弱： 23南昌 24贵阳 25南宁 26合肥 27太原 28石家庄 29呼和浩特 30佛山31东莞32唐山 33烟台34泉州35包头&lt;br /&gt;　　三线城市：&lt;br /&gt;　　三线强： 1温州2珠海3大庆 4西宁 5海口 6徐州7淄博8潍坊9洛阳 10南通 11常州12绍兴13台州14鞍山 15中山 16汕头 17吉林 18柳州&lt;br /&gt;　　三线中 ：19拉萨 20保 21邯 22银川23秦皇 24沧州 25鄂尔 26东营 27威海 28济宁 29临沂 30德州 31滨州 32泰安 33湖州 34嘉兴 35金华 36泰州 37镇江 38盐城 39扬州 40桂林 41惠州 42湛江 43江门 44茂名 45株洲 46岳阳 47衡阳 48宝鸡 49宜昌 50襄樊 51开封 52许昌 53平顶山 54赣州 55九江 56芜湖 57绵阳 58齐齐哈尔 59牡丹江 60抚顺&lt;br /&gt;　　三线弱 ：61本溪 62丹东 63辽阳 64锦州 65营口 66承德 67廊坊 68邢台 69大同 70榆林 71延安 72天水 73克拉玛 74喀什 75石河子 76南阳 77濮阳 78安阳 79焦作 80新乡 81日照82聊城 83枣庄 84蚌埠 85淮南 86马鞍山 87连云港 88淮安 89丽水 90衢州 91荆州 92安庆 93景德镇 94新余 95湘潭 96常德 97郴州 98漳州 99清远 100揭阳 101梅州 102肇庆 103玉林 104北海105德阳 106宜宾 107遵义 108大理&lt;br /&gt;　　四线城市：剩余的所有城市&lt;br /&gt;拓展业务布局的经营者们收藏吧。</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/8296569323259733420/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2014/03/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/8296569323259733420'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/8296569323259733420'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2014/03/blog-post.html' title='中国一线二线三线城市名单 '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-7397428830549030766</id><published>2013-12-19T11:42:00.001+11:00</published><updated>2013-12-19T11:42:35.274+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operating system"/><title type='text'>Error: API mismatch: the NVIDIA kernel module</title><content type='html'>&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;I was trying to get&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; color: #cc0000; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;b&gt;&lt;a href=&quot;http://store.steampowered.com/about/&quot; style=&quot;color: #274e13; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;STEAM&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&amp;nbsp;working on&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; color: #cc0000; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;b&gt;Ubuntu 12.04&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;. &amp;nbsp;I downloaded and installed the&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://media.steampowered.com/client/installer/steam.deb&quot; style=&quot;background-color: #f2ffe7; color: #274e13; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;STEAM App&lt;/a&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&amp;nbsp;and when I started it, it told me I had to upgrade my&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; color: #cc0000; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;b&gt;Nvidia Driver&lt;/b&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&amp;nbsp;from version 295.40 to version 304.43 or 310.11. &amp;nbsp;It gave me nice instructions, which I followed and it looked like it worked. &amp;nbsp;Ubuntu said it need to reboot to complete the driver update, which I did.&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;On reboot I was&amp;nbsp;greeted with a&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;Black TERMINAL SCREEN&lt;/b&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&amp;nbsp;asking for my&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;USER NAME&lt;/b&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&amp;nbsp;and&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;PASSWORD&lt;/b&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;. &amp;nbsp;Even after giving my user/password I was still stuck at the TERMINAL Screen. &amp;nbsp;Well I&amp;nbsp;remembered&amp;nbsp;the command&amp;nbsp;&lt;/span&gt;&lt;b style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;STARTX&lt;/b&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;, which I tried. &amp;nbsp;That&#39;s when I got the following ERROR MESSAGE;&lt;/span&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;span style=&quot;background-color: #f7f7f7; font-family: &#39;Ubuntu Beta&#39;, UbuntuBeta, Ubuntu, &#39;Bitstream Vera Sans&#39;, &#39;DejaVu Sans&#39;, Tahoma, sans-serif; font-size: 14px; line-height: 17px;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&quot;Error: API mismatch: the NVIDIA kernel module has version 295.49, but this NVIDIA driver component has version 310.11. Please make sure that the kernel and all NVIDIA driver components has the same version.&quot;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #333333; font-family: &#39;Ubuntu Beta&#39;, UbuntuBeta, Ubuntu, &#39;Bitstream Vera Sans&#39;, &#39;DejaVu Sans&#39;, Tahoma, sans-serif; font-size: 14px; line-height: 17px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #333333; font-family: &#39;Ubuntu Beta&#39;, UbuntuBeta, Ubuntu, &#39;Bitstream Vera Sans&#39;, &#39;DejaVu Sans&#39;, Tahoma, sans-serif; font-size: 14px; line-height: 17px;&quot;&gt;No matter what I did I could not get Ubuntu to boot into a GUI. &amp;nbsp;I knew this was a Video Drive Issue so I began my Google Searches. &amp;nbsp;Many of the things I found involved editing your &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #e0e0e0; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;/etc/X11/xorg.conf&lt;/span&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #333333; font-family: &#39;Ubuntu Beta&#39;, UbuntuBeta, Ubuntu, &#39;Bitstream Vera Sans&#39;, &#39;DejaVu Sans&#39;, Tahoma, sans-serif; font-size: 14px; line-height: 17px;&quot;&gt;&amp;nbsp;file, which I was afraid to do. &amp;nbsp;After reading several articles I pieced together how to remove and reinstall your Nvidia Video Driver from a Terminal Screen. &amp;nbsp;Here&#39;s how;&lt;/span&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #333333; font-family: &#39;Ubuntu Beta&#39;, UbuntuBeta, Ubuntu, &#39;Bitstream Vera Sans&#39;, &#39;DejaVu Sans&#39;, Tahoma, sans-serif; font-size: 14px; line-height: 17px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #333333; font-family: &#39;Ubuntu Beta&#39;, UbuntuBeta, Ubuntu, &#39;Bitstream Vera Sans&#39;, &#39;DejaVu Sans&#39;, Tahoma, sans-serif; font-size: 14px; line-height: 17px;&quot;&gt;1. &amp;nbsp;At the Terminal Screen type the following and hit ENTER;&lt;/span&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #333333; font-family: &#39;Ubuntu Beta&#39;, UbuntuBeta, Ubuntu, &#39;Bitstream Vera Sans&#39;, &#39;DejaVu Sans&#39;, Tahoma, sans-serif; font-size: 14px; line-height: 17px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #333333; font-family: &#39;Ubuntu Beta&#39;, UbuntuBeta, Ubuntu, &#39;Bitstream Vera Sans&#39;, &#39;DejaVu Sans&#39;, Tahoma, sans-serif; font-size: 14px; line-height: 17px;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #e0e0e0; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;sudo apt-get purge nvidia*&lt;/span&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;2. That removes your Nvidia Drivers, once it runs (it takes about 10 minutes and runs several lines in the Terminal)&lt;/span&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;&amp;nbsp;we reinstall the current Nvidia Driver with the following command;&lt;/span&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: #e0e0e0; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;sudo apt-get install nvidia-current-updates-dev&lt;/span&gt;&lt;span style=&quot;background-color: #f7f7f7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 14px; line-height: 17px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;span style=&quot;background-color: #f2ffe7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 15px; line-height: 21px;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 17px;&quot;&gt;3. &amp;nbsp;Once this command runs, just reboot your system and you should be good to go.&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot; /&gt;&lt;span style=&quot;background-color: #f2ffe7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 15px; line-height: 21px;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 17px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 15px; line-height: 21px;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 17px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; font-family: Georgia, Utopia, &#39;Palatino Linotype&#39;, Palatino, serif; font-size: 15px; line-height: 21px;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;background-color: #f2ffe7; color: #222222; font-family: &#39;Ubuntu Mono&#39;, &#39;Ubuntu Beta Mono A&#39;, Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace; font-size: 15px; line-height: 21px;&quot;&gt;&lt;span style=&quot;font-size: 14px; line-height: 17px;&quot;&gt;As a bonus, this Driver Removal and Reinstall lets the&amp;nbsp;&lt;a href=&quot;http://store.steampowered.com/about/&quot; style=&quot;color: #274e13; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;STEAM APP&lt;/a&gt;&amp;nbsp;start working. &amp;nbsp;I&#39;ll do a post on&amp;nbsp;&lt;a href=&quot;http://store.steampowered.com/browse/linux/&quot; style=&quot;color: #274e13; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;STEAM and it&#39;s Linux Game Selection&lt;/a&gt;&amp;nbsp;once I get a chance to play with it a little.&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/7397428830549030766/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/12/error-api-mismatch-nvidia-kernel-module.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/7397428830549030766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/7397428830549030766'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/12/error-api-mismatch-nvidia-kernel-module.html' title='Error: API mismatch: the NVIDIA kernel module'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-100971965892503830</id><published>2013-12-16T23:24:00.003+11:00</published><updated>2013-12-16T23:24:35.580+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Web marketing"/><title type='text'>你必须知道的十大网络分销渠道</title><content type='html'>徐静蕾的开啦饰品做电子商务，销售额100%来源于分销渠道，他们只做线上渠道，自己不直接销售，没有自己的官网B2C商城，自己也不在淘宝开店，每天几百个线上订单100%是外部线上渠道带来的。&lt;br /&gt;从2009年11月，开啦正式上线凡客，接着入驻卓越、当当，并成功获得卓越网免费首页及频道内推广资源，成为手表饰品频道的重要品牌商。后又进入 了时尚类的垂直B2C走秀网、逛街网、三十到五十商城等。开啦凭借徐静蕾的人脉与影响力，半年之内几乎进入了中国绝大多数排名靠前的B2C网站渠道销售， 是线上分销的成功案例。&lt;br /&gt;成功的电子商务企业，网上分销渠道销量一般不会少于自己的官网平台，线上互联网世界与线下实体世界一样，未来仍是渠道为王。有远见的B2C企业如红孩子、走秀网等都成立专门的线上渠道部来负责线上渠道建设。&lt;br /&gt;传统企业进入网上零售最好采用这样的运营节奏：第一步，建立商品供应链与运营体系；第二步，全方位地建立线上渠道；第三步，进行渠道推广。而现在90%以上的企业还未建立线上渠道，就开始大规模推广，这就是为什么很多网络推广投入产出比不理想的原因。&lt;br /&gt;其实电子商务与传统商业生意并无二致，不重视线上渠道、分销体系建立的电子商务推广效果会大打折扣。线下做销售，有了产品，知道要进入&lt;a href=&quot;http://quotes.money.163.com/usstock/hq/WMT.html&quot;&gt;沃尔玛&lt;/a&gt;、家乐福，要找地区经销商，知道要做渠道，但进入线上互联网世界，就不知道要做网络分销渠道了，仅仅漫无目的地利用网络媒体推广自己的官网，而不结合渠道来促销商品，推广效果怎不大打折扣？&lt;br /&gt;所以，推广一定要结合线上渠道来推广。有线上渠道的网络推广，会事半功倍；而无线上渠道的网络推广，就会事倍功半。&lt;br /&gt;我在中国最大的时尚B2C平台走秀网做营销副总裁期间，最主要的工作之一是带领10多人的团队，花了两年多时间在互联网上全面建立线上渠道，一共建 立了十大渠道体系，开设了上百个线上销售渠道点。最后的收益是：通过这些线上渠道不花一分钱推广费用，一年365天，每天带来几百单的销售。&lt;br /&gt;&lt;strong&gt;十大网络渠道&lt;/strong&gt;&lt;br /&gt;&lt;strong&gt;1.C2C渠道：&lt;/strong&gt;&lt;br /&gt;淘宝（C2C及淘宝商城）、拍拍（C2C及B2C渠道）、有啊商城。&lt;br /&gt;这个渠道大家都已经熟悉，就不详细介绍了。目前对很多传统企业来说，做电子商务就是在淘宝开店，销量也绝大部分来源于淘宝。但对于传统大型企业来说，从长远看，淘宝只能作为一个销售渠道，不能作为唯一的渠道，必须发展全方位渠道，争取未来的主动权。&lt;br /&gt;&lt;strong&gt;2.B2C商城渠道：&lt;/strong&gt;&lt;br /&gt;如当当网、卓越网等。&lt;br /&gt;渠道情况：他们在线上渠道的地位相当于线下的沃尔玛、家乐福。2009年，中国前十名的B2C商城大多开始转入百货商城，大多数商品品类都卖，正在建立其他品类商品供应链，这就给传统企业进入B2C渠道提供了机会。&lt;br /&gt;如何进入：如果你的商品是市场上热卖的商品，又有电子商务的客服体系等基本条件，保证这些平台一定的毛利空间，就有可能成为这些B2C平台的供应商。注意，以传统企业名义去谈比你用网站名义去谈更能被接受。&lt;br /&gt;效果预估：根据我的实操经验，如果能成为这些大的B2C平台的主推供应商，一个大的平台每天可以带来几十个订单。更何况其他小有价值的B2C平台还有成百上千，累计起来每天订单也不少。&lt;br /&gt;&lt;strong&gt;3.CPS渠道：&lt;/strong&gt;&lt;br /&gt;包括第三方CPS平台及自营CPS平台。如yiqifa、linktech、唯一、成果网。&lt;br /&gt;渠道情况：目前电子商务比较主流且固定的渠道推广就是CPS模式，通过推广产生有效的订单后进行比例分成。这是一种零风险的实效营销方式，如果网站主不能为给你的网站带来销售额，广告主不用支付任何广告费用。&lt;br /&gt;如何进入：制定超越竞争对手的联盟分成政策，增强竞争力，还需要有专人结算与维护。&lt;br /&gt;效果预估：一般B2C平台，CPS销售会占到20%，不做这个渠道意味着你损失20%的销量。当然，有实力的企业也可以建立自己的CPS联盟，一旦发展起来，和第三方CPS平台形成补充，带来的销量比例更大。&lt;br /&gt;&lt;strong&gt;4.银行商城渠道：&lt;/strong&gt;&lt;br /&gt;招行、工行、交行、建行等网上商城。&lt;br /&gt;渠道情况：中国大部分银行商城及信用卡商城都建设有B2C平台，据我的经验，银行网上商城这个渠道价值非常大，银行拥有大量网银支付的用户。&lt;br /&gt;如何进入：和银行谈判他们最在乎的是自己网上支付的流水，知道人家的需求就容易进入了。&lt;br /&gt;合作效果：我们进入了中国16家网上银行商城（每个银行的很多地区分行也开设有自己的网上商城），并进行了深度推广合作。除了订单的实际效果，银行对B2C平台的背书作用也不容忽视。如果能与这些银行深层次合作，一次合作带来上百万销售额也是可能的。&lt;br /&gt;&lt;strong&gt;5.网上支付渠道：&lt;/strong&gt;&lt;br /&gt;腾讯财付通商城渠道、支付宝商城渠道、第三方支付渠道如快钱、环迅等。&lt;br /&gt;这些第三方支付平台拥有庞大的用户量，这些已经开通网上支付手段的用户，基本都有网购经验，是精准的网购人群。这些平台也希望企业使用其支付手段做大资金流。抓住他们的需求，展示你的实力与未来注册用户的庞大，他们也愿意利用自己的资源推广你的网站平台。&lt;br /&gt;&lt;strong&gt;6.门户商城渠道：&lt;/strong&gt;&lt;br /&gt;腾讯QQ会员商城、腾讯返利商城、&lt;a href=&quot;http://quotes.money.163.com/usstock/hq/SINA.html&quot;&gt;新浪&lt;/a&gt;商城、搜狐商城、网易购物返现商城等。&lt;br /&gt;渠道情况：中国的主流门户都有自己的B2C商城，虽然它们都没有发力。门户商城的交易量也还暂时不大，但门户的影响力及庞大用户量是不可小觑的；&lt;br /&gt;如何进入：门户也欢迎直接与厂商合作，如果和这些门户有广告投放合作，结合推广进入商城，会更容易一些。&lt;br /&gt;合作效果：如果你在这些门户商城占据较好的渠道位置，并争取门户的推广资源支持，并策划一些在门户的促销活动，有专门的人维护商品与专人的客服，也可取得每天几十单的销售。&lt;br /&gt;至于其他大流量的网站如天涯、迅雷等，都已经进军电子商务，也可作为补充渠道。&lt;br /&gt;&lt;strong&gt;7.积分商城渠道：&lt;/strong&gt;&lt;br /&gt;平安万里通商城/网易邮箱积分商城/携程特约商户等。&lt;br /&gt;渠道情况：现在很多有庞大用户量的机构，建有自己的积分体系，并将这个积分和电子商务结合。在积分体系商城中，平安万里通是做得最极致的，将自己的4000万用户的积分变成一个商城，用平安万里通的入口可以直接购买其他B2C平台的商品如1号店及红孩子等商品。&lt;br /&gt;如何进入：由于这个渠道是给他们积分用户带来优惠，所以对商品价格的优惠力度要求较高，而且要求合作伙伴能和他们对接网上同步订单操作，对技术接口要求也高。&lt;br /&gt;合作效果：1号店的总销售额中60%来源于平安万里通这个渠道，超过其他渠道及官网销售额的总和，其效果可见一斑。网易邮箱及携程用户也是海量级别的，将他们的部分用户转为你的购买用户，将对商务拓展及公关工作带来极大挑战，但一旦变成你的销售渠道，其战略意义是很大的。&lt;br /&gt;&lt;strong&gt;8.运营商渠道：&lt;/strong&gt;&lt;br /&gt;&lt;a href=&quot;http://hkquotes.money.163.com/html/000941.html&quot;&gt;中国移动&lt;/a&gt;商城、&lt;a href=&quot;http://quotes.money.163.com/0600050.html&quot;&gt;中国联通&lt;/a&gt;积分商城、&lt;a href=&quot;http://hkquotes.money.163.com/html/000728.html&quot;&gt;中国电信&lt;/a&gt;商城。&lt;br /&gt;渠道价值：随着移动互联网兴起及移动支付的普及，这个渠道的战略意义会越来越大，属于提前占位的策略。我们的实际经验是：和中国移动商城的合作每天带来上10单，就是用户用手机支付来买我们的商品，等于多开了一个销售渠道与支付手段。&lt;br /&gt;&lt;strong&gt;9.购物搜索渠道：&lt;/strong&gt;&lt;br /&gt;聪明点、返利网、易购网、特价王、askyaya。&lt;br /&gt;渠道价值：由于这些购物搜索用户都是购买用户，其价值大于一般娱乐性信息网站，成为成熟网购人群的入口之一。如能让这些购物搜索全部收录一些你的网站商品，而且在首页推荐，每天都能带来一些订单。&lt;br /&gt;&lt;strong&gt;10.网站导航渠道：&lt;/strong&gt;&lt;br /&gt;hao123/265/114la购物频道。&lt;br /&gt;效果介绍：如果能进入这些导航站的首页的购物频道，每天可以带来上百订单左右，但审核较严，需要你的品牌商城关键词在百度每天有5000左右搜索量才行。如果达不到这个标准，需要以做广告付费的形式进入。&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;gg200x300&quot;&gt;&lt;br /&gt;&lt;/div&gt;由于传统企业缺乏互联网经验，更不用说建立线上渠道的经验，相信不久就会出现专业的全渠道方案解决服务商，不仅协助这些企业省人力物 力、最快时间地进入这些有价值的线上渠道。服务商还需要策划一些渠道促销，购物卡渠道促销方案、团购与节庆、渠道促销方案、永不落幕的网上特卖会（银行）  渠道促销方案等，正如线下世界进入沃尔玛卖场，要进行堆头促销，要派促销小姐现场导购。&lt;br /&gt;                                                  &lt;br /&gt;此外，企业还有将网络推广与以上渠道结合的需求，如进入了新浪商城，在新浪做广告促销，进入了迅雷商城，利用迅雷的推广资源进行渠道促销，形成整合 的推广效果，这种进入渠道再进行渠道推广方式，比现在单纯打网络广告的方式，ROI可以提高好几倍，从而达到替传统企业树线上品牌、建线上渠道、促渠道销 售全面整合的效果。</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/100971965892503830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/12/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/100971965892503830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/100971965892503830'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/12/blog-post.html' title='你必须知道的十大网络分销渠道'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-2766344622299719268</id><published>2013-12-10T12:36:00.001+11:00</published><updated>2013-12-10T12:36:24.914+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="computer networking"/><title type='text'>扫盲GFW的工作原理和封锁技术</title><content type='html'>&lt;div style=&quot;color: #222222; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px; margin-bottom: 1.5em; padding: 0px;&quot;&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;GFW是Great Fire Wall的缩写，即“长城防火墙”。这个工程由若干个部分组成，实现不同功能。长城防火墙主要指TG监控和过滤互联网内容的软硬件系统，由服务器和路由器等设备，加上相关的应用程序所构成。&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;首先，需要强调的是，由于中国网络审查广泛，中国国内含有“不合适”内容的的网站，会受到政府直接的行政干预，被要求自我审查、自我监管，乃至关闭，所以GFW的主要作用在于分析和过滤中国境内外网络的资讯互相访问。&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;GFW对网络内容的过滤和分析是双向的，GFW不仅针对国内读者访问中国境外的网站进行干扰，也干扰国外读者访问主机在中国大陆的网站。&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 56px;&quot;&gt;&lt;strong style=&quot;font-style: inherit;&quot;&gt;一 关键字过滤阻断&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&amp;nbsp;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;&amp;nbsp;关键字过滤系统。此系统能够从出口网关收集分析信息，过滤、嗅探指定的关键字。主要针对HTTP的默认端口：80端口，因为HTTP传播的内容是明文的内 容，没有经过加密，而GFW是一个IDS(Intrusion detection system)。普通的关键词如果出现在HTTP请求报文的头部(如“Host: www.youtube.com”)时，则会马上伪装成对方向连接两端的计算机发送RST包(reset)干扰两者正常的TCP连接，进而使请求的内容无 法继续查看。如果GFW在数据流中发现了特殊的内文关键词(如轮子，达赖等)时，其也会试图打断当前的连接，从而有时会出现网页开启一部分后突然停止的情 况。在任何阻断发生后，一般在随后的90秒内同一IP地址均无法浏览对应IP地址相同端口上的内容。&lt;/span&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 56px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px; margin-bottom: 1.5em; padding: 0px;&quot;&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 56px;&quot;&gt;&lt;strong style=&quot;font-style: inherit;&quot;&gt;二 IP地址封锁&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;&amp;nbsp; IP 地址封锁是GFW通过路由器来控制的，在通往国外的最后一个网关上加上一条伪造的路由规则，导致通往某些被屏蔽的网站的所有IP数据包无法到达。路由器的 正常工作方式是学习别的路由器广播的路由规则，遇到符合已知的IP转发规则的数据包，则按已经规则发送，遇到未知规则IP的数据，则转发到上一级网关。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px; margin-bottom: 1.5em; padding: 0px;&quot;&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;而 GFW对于境外(中国大陆以外)的XX网站会采取独立IP封锁技术。然而部分XX网站使用的是由虚拟主机服务提供商提供的多域名、单(同)IP的主机托管 服务，这就会造成了封禁某个IP地址，就会造成所有使用该服务提供商服务的其它使用相同IP地址服务器的网站用户一同遭殃，就算是正常的网站，也不能幸 免。其中的内容可能并无不当之处，但也不能在中国大陆正常访问。现在GFW通常会将包含XX信息的网站或网页的URL加入关键字过滤系统，并可以防止民众 透过普通海外HTTP代理服务器进行访问。&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 56px;&quot;&gt;&lt;strong style=&quot;font-style: inherit;&quot;&gt;三 特定端口封锁&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&amp;nbsp;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;&amp;nbsp;GFW会丢弃特定IP地址上特定端口的所有数据包，使该IP地址上服务器的部分功能(如SSH的22、VPN的1723或SSL的443端口等)无法在中国大陆境内正常使用。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px; margin-bottom: 1.5em; padding: 0px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot;&gt;在中国移动、中国联通等部分ISP(手机IP段)，所有的PPTP类型的VPN都被封锁。&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot;&gt;2011 年3月起，GFW开始对Google部分服务器的IP地址实施自动封锁(按时间段)某些端口，按时段对www.google.com(用户登录所有 Google服务时需此域名加密验证)和mail.google.com的几十个IP地址的443端口实施自动封锁，具体是每10或15分钟可以连通，接 着断开，10或15分钟后再连通，再断开，如此循环，令中国大陆用户和Google主机之间的连接出现间歇性中断，使其各项服务出现问题。GFW这样的封 锁手法很高明，因为Gmail并非被完全阻断，这令问题看上去好像出自Google本身。&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot;&gt;&lt;span style=&quot;line-height: 31px;&quot;&gt;&lt;strong style=&quot;font-style: inherit;&quot;&gt;这就是你们认为Google抽风的原因。&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 56px;&quot;&gt;&lt;strong style=&quot;font-style: inherit;&quot;&gt;四 SSL连接阻断&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;&amp;nbsp; GFW 会阻断特定网站的SSL加密连接，方法是通过伪装成对方向连接两端的计算机发送RST包(RESET)干扰两者间正常的TCP连接，进而打断与特定IP地 址之间的SSL(HTTPS，443端口)握手(如Gmail、Google文件、Google网上论坛等的SSL加密连接)，从而导致SSL连接失败。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px; margin-bottom: 1.5em; padding: 0px;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot;&gt;当然由于SSL本身的特点，这并不意味着与网站传输的内容可被破译。&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 56px;&quot;&gt;&lt;strong style=&quot;font-style: inherit;&quot;&gt;五 DNS劫持和污染&lt;/strong&gt;&lt;/span&gt;&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;&amp;nbsp; GFW主要采用DNS劫持和污染技术，使用Cisco提供的IDS系统来进行域名劫持，防止访问被过滤的网站，2002年Google被封锁期间其域名就被劫持到百度。中国部分ISP也会通过此技术插入广告。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;color: #222222; font-family: &#39;Helvetica Neue&#39;, Arial, Helvetica, sans-serif; font-size: 12px; line-height: 19px; margin-bottom: 1.5em; padding: 0px;&quot;&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;对于含有多个IP地址或经常变更IP地址逃避封锁的域名，GFW通常会使用此方法进行封锁。具体方法是当用户向DNS服务器提交域名请求时，DNS返回虚假(或不解析)的IP地址。&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;全球一共有13组根域名服务器(Root Server)，目前中国大陆有F、I这2个根域DNS镜像，但现在均已因为多次DNS污染外国网络，而被断开与国际互联网的连接。&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 23px;&quot;&gt;&lt;strong style=&quot;font-style: inherit;&quot;&gt;DNS劫持和污染是针对某些网站的最严重的干扰。&lt;/strong&gt;&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;干扰的方式有两种：&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;一 种是通过网络服务提供商(Internet Service Provider)提供的DNS服务器进行DNS欺骗，当人们访问某个网站时，需要要把域名转换为一个IP地址，DNS服务器负责将域名转换为IP地址， 中国大陆的ISP接受通信管理局的屏蔽网站的指令后在DNS服务器里加入某些特定域名的虚假记录，当使用此DNS服务器的网络用户访问此特定网站 时，DNS服务便给出虚假的IP地址，导致访问网站失败，甚至返回ISP运营商提供的出错页面和广告页面。&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; line-height: 26px;&quot; /&gt;&lt;br /&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: Arial, 宋体; font-size: small; line-height: 26px;&quot;&gt;另一种是GFW在DNS查询使用的UDP的53端口上根据blacklist进行过滤，遇到通往国外的使用UDP53端口进行查询的DNS请求，就返回一个虚假的IP地址。&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/2766344622299719268/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/12/gfw.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/2766344622299719268'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/2766344622299719268'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/12/gfw.html' title='扫盲GFW的工作原理和封锁技术'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-9040161112568591374</id><published>2013-09-03T17:09:00.001+10:00</published><updated>2013-09-03T17:10:25.399+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>jsonp详解</title><content type='html'>http://www.cnblogs.com/lemontea/archive/2012/12/11/2812268.html</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/9040161112568591374/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/09/jsonp.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/9040161112568591374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/9040161112568591374'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/09/jsonp.html' title='jsonp详解'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-6982632459979288720</id><published>2013-08-14T12:26:00.003+10:00</published><updated>2013-08-14T12:26:58.588+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>面向站长和网站管理员的Web缓存加速指南</title><content type='html'>&lt;div class=&quot;entry-body&quot; style=&quot;background-color: white; clear: both; color: #333333; font-family: &#39;trebuchet ms&#39;, verdana, helvetica, arial, sans-serif; font-size: 14px; line-height: 21px;&quot;&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;这是一篇知识性的文档，主要目的是为了让Web缓存相关概念更容易被开发者理解并应用于实际的应用环境中。为了简要起见，某些实现方面的细节被简化或省略了。如果你更关心细节实现则完全不必耐心看完本文，后面参考文档和更多深入阅读部分可能是你更需要的内容。&lt;/div&gt;&lt;ol style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;什么是Web缓存，为什么要使用它？&lt;/li&gt;&lt;li&gt;缓存的类型：&lt;/li&gt;&lt;ol style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;浏览器缓存；&lt;/li&gt;&lt;li&gt;代理服务器缓存；&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;Web缓存无害吗？为什么要鼓励缓存？&lt;/li&gt;&lt;li&gt;Web缓存如何工作：&lt;/li&gt;&lt;li&gt;如何控制（控制不）缓存：&lt;/li&gt;&lt;ol style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;HTML Meta标签 vs. HTTP头信息；&lt;/li&gt;&lt;li&gt;Pragma HTTP头信息（为什么不起作用）；&lt;/li&gt;&lt;li&gt;使用Expires（过期时间）HTTP头信息控制保鲜期；&lt;/li&gt;&lt;li&gt;Cache-Control（缓存控制） HTTP头信息；&lt;/li&gt;&lt;li&gt;校验参数和校验；&lt;/li&gt;&lt;/ol&gt;&lt;li&gt;创建利于缓存网站的窍门；&lt;/li&gt;&lt;li&gt;编写利于缓存的脚本；&lt;/li&gt;&lt;li&gt;常见问题解答；&lt;/li&gt;&lt;li&gt;缓存机制的实现：Web服务器端配置；&lt;/li&gt;&lt;li&gt;缓存机制的实现：服务器端脚本；&lt;/li&gt;&lt;li&gt;参考文档和深入阅读；&lt;/li&gt;&lt;li&gt;关于本文档；&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;div class=&quot;entry-more&quot; id=&quot;more&quot; style=&quot;background-color: white; clear: both; color: #333333; font-family: &#39;trebuchet ms&#39;, verdana, helvetica, arial, sans-serif; font-size: 14px; line-height: 21px;&quot;&gt;&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;什么是Web缓存，为什么要使用它？&lt;/h3&gt;Web缓存位于Web服务器之间（1个或多个，内容源服务器）和客户端之间（1个或多个）：缓存会根据进来的请求保存输出内容的副本，例如html页面， 图片，文件（统称为副本），然后，当下一个请求来到的时候：如果是相同的URL，缓存直接使用副本响应访问请求，而不是向源服务器再次发送请求。&lt;br /&gt;&lt;br /&gt;使用缓存主要有2大理由：&lt;br /&gt;&lt;ul style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;&lt;strong&gt;减少相应延迟&lt;/strong&gt;：因为请求从缓存服务器（离客户端更近）而不是源服务器被相应，这个过程耗时更少，让web服务器看上去相应更快；&lt;/li&gt;&lt;li&gt;&lt;strong&gt;减少网络带宽消耗&lt;/strong&gt;：当副本被重用时会减低客户端的带宽消耗；客户可以节省带宽费用，控制带宽的需求的增长并更易于管理。&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;缓存的类型&lt;/span&gt;&lt;/h3&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;浏览器缓存&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;对于新一代的Web浏览器来说（例如：IE，Firefox）：一般都能在设置对话框中发现关于缓存的设置，通过在你的电脑上僻处一块硬盘空间用于存储你已经看过的网站的副本。浏览器缓存根据非常简单的规则进行工作：在同一个会话过程中（在当前浏览器没有被关闭之前）会检查一次并确定缓存的副本足够新。这个缓存对于用户点击“后退”或者点击刚访问过的链接特别有用，如果你浏览过程中访问到同一个图片，这些图片可以从浏览器缓存中调出而即时显现。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;代理服务器缓存&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Web代理服务器使用同样的缓存原理，只是规模更大。代理服务器群为成百上千用户服务使用同样的机制；大公司和ISP经常在他们的防火墙上架设代理缓存或者单独的缓存设备；&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;由于带路服务器缓存并非客户端或者源服务器的一部分，而是位于原网络之外，请求必须路由到他们才能起作用。一个方法是手工设置你的浏览器：告诉浏览器使用 那个代理，另外一个是通过中间服务器：这个中间服务器处理所有的web请求，并将请求转发到后台网络，而用户不必配置代理，甚至不必知道代理的存在；&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;代理服务器缓存：是一个共享缓存，不只为一个用户服务，经常为大量用户使用，因此在减少相应时间和带宽使用方面很有效：因为同一个副本会被重用多次。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;网关缓存&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;也被称为反向代理缓存或间接代理缓存，网关缓存也是一个中间服务器，和内网管理员部署缓存用于节省带宽不同：网关缓存一般是网站管理员自己部署：让他们的网站更容易扩展并获得更好的性能；&lt;br /&gt;请求有几种方法被路由到网关缓存服务器上：其中典型的是让用一台或多台负载均衡服务器从客户端看上去是源服务器；&lt;br /&gt;&lt;br /&gt;网络内容发布商&amp;nbsp; (Content delivery networks CDNs)分布网关缓存到整个（或部分）互联网上，并出售缓存服务给需要的网站，&lt;a href=&quot;http://www.speedera.com/&quot; style=&quot;color: #0f314e;&quot;&gt;Speedera&lt;/a&gt;和&lt;a href=&quot;http://www.akamai.com/&quot; style=&quot;color: #0f314e;&quot;&gt;Akamai&lt;/a&gt;就是典型的网络内容发布商(下文简称CDN)。&lt;br /&gt;&lt;br /&gt;本问主要关注于浏览器和代理缓存，当然，有些信息对于网关缓存也同样有效；&lt;/div&gt;&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Web缓存无害吗？为什么要鼓励缓存？&lt;/h3&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Web缓存在互联网上最容易被误解的技术之一：网站管理员经常怕对网站失去控制，由于代理缓存会“隐藏”他们的用户，让他们感觉难以监控谁在使用他们的网站。&lt;br /&gt;不幸的是：就算不考虑Web缓存，互联网上也有很多网站使用非常多的参数以便管理员精确地跟踪用户如何使用他们的网站；如果这类问题也是你关心的，本文将告诉你如何获得精确的统计而不必将网站设计的非常缓存不友好。&lt;br /&gt;另外一个抱怨是缓存会给用户过期或失效的数据；无论如何：本文可以告诉你怎样配置你的服务器来控制你的内容将被如何缓存。&lt;br /&gt;&lt;br /&gt;CDN是另外一个有趣的方向，和其他代理缓存不同：CDN的网关缓存为希望被缓存的网站服务，没有以上顾虑。即使你使用了CDN，你也要考虑后续的代理服务器缓存和浏览器缓存问题。&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;另外一方面：如果良好地规划了你的网站，缓存会有助于网站服务更快，并节省服务器负载和互联网的链接请求。这个改善是显著的：一个难以缓存的网站可能需要几秒去载入页面，而对比有缓存的网站页面几乎是即时显现：用户更喜欢速度快的网站并更经常的访问；&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;这样想：很多大型互联网公司为全世界服务器群投入上百万资金，为的就是让用户访问尽可能快，客户端缓存也是这个目的，只不过更靠近用户一端，而且最好的一点是你甚至根本不用为此付费。&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;事实上，无论你是否喜欢，代理服务器和浏览器都回启用缓存。如果你没有配置网站正确的缓存，他们会按照缺省或者缓存管理员的策略进行缓存。&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;缓存如何工作&lt;/h3&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;所有的缓存都用一套规则来帮助他们决定什么时候使用缓存中的副本提供服务（假设有副本可用的情况下）；一些规则在协议中有定义（HTTP协议1.0和1.1），一些规则由缓存的管理员设置（浏览器的用户或者代理服务器的管理员）；&lt;br /&gt;一般说来：遵循以下基本的规则（不必担心，你不必知道所有的细节，细节将随后说明）&lt;/div&gt;&lt;ol style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;如果响应头信息：告诉缓存器不要保留缓存，缓存器就不会缓存相应内容；&lt;/li&gt;&lt;li&gt;如果请求信息是需要认证或者安全加密的，相应内容也不会被缓存；&lt;/li&gt;&lt;li&gt;如果在回应中不存在校验器（ETag或者Last-Modified头信息），缓存服务器会认为缺乏直接的更新度信息，内容将会被认为不可缓存。&lt;/li&gt;&lt;li&gt;一个缓存的副本如果含有以下信息：内容将会被认为是足够新的&lt;/li&gt;&lt;ul style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;含有完整的过期时间和寿命控制头信息，并且内容仍在保鲜期内；&lt;/li&gt;&lt;li&gt;浏览器已经使用过缓存副本，并且在一个会话中已经检查过内容的新鲜度；&lt;/li&gt;&lt;li&gt;缓存代理服务器近期内已经使用过缓存副本，并且内容的最后更新时间在上次使用期之前；&lt;/li&gt;&lt;li&gt;够新的副本将直接从缓存中送出，而不会向源服务器发送请求；&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;如果缓存的副本已经太旧了，缓存服务器将向源服务器发出请求校验请求，用于确定是否可以继续使用当前拷贝继续服务；&lt;/li&gt;&lt;/ol&gt;总之：&lt;strong&gt;&lt;em&gt;新鲜度&lt;/em&gt;&lt;/strong&gt;和&lt;strong&gt;校验&lt;/strong&gt;是确定内容是否可用的最重要途径：&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;如果副本足够新，从缓存中提取就立刻能用了；&lt;br /&gt;而经缓存器校验后发现副本的原件没有变化，系统也会避免将副本内容从源服务器整个重新传输一遍。&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;如何控制（控制不）缓存&lt;/h3&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;有很多工具可以帮助设计师和网站管理员调整缓存服务器对待网站的方式，这也许需要你亲自下手对服务器的配置进行一些调整，但绝对值得；了解如何使用这些工具请参考后面的实现章节；&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;HTML meta标签和HTTP 头信息&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;HTML的编写者会在文档的&lt;head&gt;区域中加入描述文档的各种属性，这些META标签常常被用于标记文档不可以被缓存或者标记多长时间后过期；&lt;br /&gt;META标签使用很简单：但是效率并不高，因为只有几种浏览器会遵循这个标记（那些真正会“读懂”HTML的浏览器），没有一种缓存代理服务器能遵循这个 规则（因为它们几乎完全不解析文档中HTML内容）；有事会在Web页面中增加：Pragma: no-cache这个META标记，如果要让页面保持刷新，这个标签其实完全没有必要。&lt;br /&gt;如果你的网站托管在ISP机房中，并且机房可能不给你权限去控制HTTP的头信息（如：Expires和Cache-Control），大声控诉：这些机制对于你的工作来说是必须的；&lt;br /&gt;另外一方面： HTTP头信息可以让你对浏览器和代理服务器如何处理你的副本进行更多的控制。他们在HTML代码中是看不见的，一般由Web服务器自动生成。但是，根据 你使用的服务，你可以在某种程度上进行控制。在下文中：你将看到一些有趣的HTTP头信息，和如何在你的站点上应用部署这些特性。&lt;br /&gt;&lt;br /&gt;HTTP头信息发送在HTML代码之前，只有被浏览器和一些中间缓存能看到，一个典型的HTTP 1.1协议返回的头信息看上去像这样：&lt;/head&gt;&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;HTTP/1.1 200 OK&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Date: Fri, 30 Oct 1998 13:19:41 GMT&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Server: Apache/1.3.3 (Unix)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Cache-Control: max-age=3600, must-revalidate&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Expires: Fri, 30 Oct 1998 14:19:41 GMT&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Last-Modified: Mon, 29 Jun 1998 02:28:12 GMT&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;ETag: &quot;3e86-410-3596fbbc&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Content-Length: 1040&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Content-Type: text/html&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;br /&gt;在头信息空一行后是HTML代码的输出，关于如何设置HTTP头信息请参考实现章节；&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Pragma HTTP头信息 (为什么它不起作用)&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;很多人认为在HTTP头信息中设置了Pragma: no-cache后会让内容无法被缓存。但事实并非如此：HTTP的规范中，响应型头信息没有任何关于Pragma属性的说明，而讨论了的是请求型头信息 Pragma属性（头信息也由浏览器发送给服务器），虽然少数集中缓存服务器会遵循这个头信息，但大部分不会。用了Pragma也不起什么作用，要用就使 用下列头信息：&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;使用Expires（过期时间）HTTP头信息来控制保鲜期&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Expires（过期时间） 属性是HTTP控制缓存的基本手段，这个属性告诉缓存器：相关副本在多长时间内是新鲜的。过了这个时间，缓存器就会向源服务器发送请求，检查文档是否被修改。几乎所有的缓存服务器都支持Expires（过期时间）属性；&lt;br /&gt;&lt;br /&gt;大部分Web服务器支持你用几种方式设置Expires属性；一般的：可以设计一个绝对时间间隔：基于客户最后查看副本的时间（最后访问时间）或者根据服务器上文档最后被修改的时间；&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Expires头信息：对于设置静态图片文件（例如导航栏和图片按钮）可缓存特别有用；因为这些图片修改很少，你可以给它们设置一个特别长的过期时间，这会使你的网站对用户变得相应非常快；他们对于控制有规律改变的网页也很有用，例如：你每天早上6点更新新闻页，你可以设置副本的过期时间也是这个时间，这样缓存 服务器就知道什么时候去取一个更新版本，而不必让用户去按浏览器的“刷新”按钮。&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;过期时间头信息属性值&lt;strong&gt;只能&lt;/strong&gt;是HTTP格式的日期时间，其他的都会被解析成当前时间“之前”，副本会过期，记住：HTTP的日期时间必须是格林威治时间（GMT），而不是本地时间。举例：&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Expires: Fri, 30 Oct 1998 14:19:41 GMT&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;所以使用过期时间属性一定要确认你的Web服务器时间设置正确，一个途径是通过网络时间同步协议（Network Time Protocol NTP），和你的系统管理员那里你可以了解更多细节。&lt;br /&gt;虽然过期时间属性非常有用，但是它还是有些局限，首先：是牵扯到了日期，这样Web服务器的时间和缓存服务器的时间必须是同步的，如果有些不同步，要么是应该缓存的内容提前过期了，要么是过期结果没及时更新。&lt;br /&gt;还有一个过期时间设置的问题也不容忽视：如果你设置的过期时间是一个固定的时间，如果你返回内容的时候又没有连带更新下次过期的时间，那么之后所有访问请求都会被发送给源Web服务器，反而增加了负载和响应时间；&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Cache-Control（缓存控制） HTTP头信息&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;HTTP 1.1介绍了另外一组头信息属性：Cache-Control响应头信息，让网站的发布者可以更全面的控制他们的内容，并定位过期时间的限制。&lt;br /&gt;有用的 Cache-Control响应头信息包括：&lt;/div&gt;&lt;ul style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;&lt;strong&gt;max-age&lt;/strong&gt;=[秒] — 执行缓存被认为是最新的最长时间。类似于过期时间，这个参数是基于请求时间的相对时间间隔，而不是绝对过期时间，[秒]是一个数字，单位是秒：从请求时间开始到过期时间之间的秒数。&lt;/li&gt;&lt;li&gt;&lt;strong&gt;s-maxage&lt;/strong&gt;=[秒] — 类似于max-age属性，除了他应用于共享（如：代理服务器）缓存&lt;/li&gt;&lt;li&gt;&lt;strong&gt;public&amp;nbsp;&lt;/strong&gt;— 标记认证内容也可以被缓存，一般来说： 经过HTTP认证才能访问的内容，输出是自动不可以缓存的；&lt;/li&gt;&lt;li&gt;&lt;strong&gt;no-cache&lt;/strong&gt;&amp;nbsp;— 强制每次请求直接发送给源服务器，而不经过本地缓存版本的校验。这对于需要确认认证应用很有用（可以和public结合使用），或者严格要求使用最新数据的应用（不惜牺牲使用缓存的所有好处）；&lt;/li&gt;&lt;li&gt;&lt;strong&gt;no-store&lt;/strong&gt;&amp;nbsp;— 强制缓存在任何情况下都不要保留任何副本&lt;/li&gt;&lt;li&gt;&lt;strong&gt;must-revalidate&lt;/strong&gt;&amp;nbsp;— 告诉缓存必须遵循所有你给予副本的新鲜度的，HTTP允许缓存在某些特定情况下返回过期数据，指定了这个属性，你高速缓存，你希望严格的遵循你的规则。&lt;/li&gt;&lt;li&gt;&lt;strong&gt;proxy-revalidate&lt;/strong&gt;&amp;nbsp;— 和 must-revalidate类似，除了他只对缓存代理服务器起作用&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;举例:&lt;/div&gt;&lt;div style=&quot;font-style: italic; margin-left: 40px;&quot;&gt;Cache-Control: max-age=3600, must-revalidate&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;如果你计划试用Cache-Control属性，你应该看一下这篇HTTP文档，详见参考和深入阅读；&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;校验参数和校验&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;在Web缓存如何工作： 我们说过：校验是当副本已经修改后，服务器和缓存之间的通讯机制；使用这个机制：缓存服务器可以避免副本实际上仍然足够新的情况下重复下载整个原件。&lt;br /&gt;校验参数非常重要，如果1个不存在，并且没有任何信息说明保鲜期（Expires或Cache-Control）的情况下，缓存将不会存储任何副本；&lt;br /&gt;最常见的校验参数是文档的最后修改时间，通过最后Last-Modified头信息可以，当一份缓存包含Last-Modified信息，他基于此信息，通过添加一个If-Modified-Since请求参数，向服务器查询：这个副本从上次查看后是否被修改了。&lt;br /&gt;HTTP 1.1介绍了另外一个校验参数： ETag，服务器是服务器生成的唯一标识符ETag，每次副本的标签都会变化。由于服务器控制了ETag如何生成，缓存服务器可以通过If-None-Match请求的返回没变则当前副本和原件完全一致。&lt;br /&gt;所有的缓存服务器都使用Last-Modified时间来确定副本是否够新，而ETag校验正变得越来越流行；&lt;br /&gt;所有新一代的Web服务器都对静态内容（如：文件）自动生成ETag和Last-Modified头信息，而你不必做任何设置。但是，服务器对于动态内容（例如：CGI,ASP或数据库生成的网站）并不知道如何生成这些信息，参考一下编写利于缓存的脚本章节；&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;创建利于缓存网站的窍门&lt;/h3&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;除了使用新鲜度信息和校验，你还有很多方法使你的网站缓存友好。&lt;/div&gt;&lt;ul style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;&lt;strong&gt;保持URL稳定&lt;/strong&gt;： 这是缓存的金科玉律，如果你给在不同的页面上，给不同用户或者从不同的站点上提供相同的内容，应该使用相同的URL，这是使你的网站缓存友好最简单，也是 最高效的方法。例如：如果你在页面上使用 &quot;/index.html&quot; 做为引用，那么就一直用这个地址；&lt;/li&gt;&lt;li&gt;&lt;strong&gt;使用一个共用的库&lt;/strong&gt;存放每页都引用的图片和其他页面元素；&lt;/li&gt;&lt;li&gt;&lt;strong&gt;对于不经常改变的图片/页面启用缓存&lt;/strong&gt;，并使用Cache-Control: max-age属性设置一个较长的过期时间；&lt;/li&gt;&lt;li&gt;&lt;strong&gt;对于定期更新的内容&lt;/strong&gt;设置一个缓存服务器可识别的max-age属性或过期时间；&lt;/li&gt;&lt;li&gt;&lt;strong&gt;如果数据源（特别是下载文件）变更，修改名称&lt;/strong&gt;，这样：你可以让其很长时间不过期，并且保证服务的是正确的版本；而链接到下载文件的页面是一个需要设置较短过期时间的页面。&lt;/li&gt;&lt;li&gt;&lt;strong&gt;万不得已不要改变文件&lt;/strong&gt;，否则你会提供一个非常新的Last-Modified日期；例如：当你更新了网站，不要复制整个网站的所有文件，只上传你修改的文件。&lt;/li&gt;&lt;li&gt;&lt;strong&gt;只在必要的时候使用Cookie&lt;/strong&gt;，cookie是非常难被缓存的，而且在大多数情况下是不必要的，如果使用cookie，控制在动态网页上；&lt;/li&gt;&lt;li&gt;&lt;strong&gt;减少试用SSL&lt;/strong&gt;，加密的页面不会被任何共享缓存服务器缓存，只在必要的时候使用，并且在SSL页面上减少图片的使用；&lt;/li&gt;&lt;li&gt;&lt;strong&gt;使用可缓存性评估引擎&lt;/strong&gt;，这对于你实践本文的很多概念都很有帮助；&lt;/li&gt;&lt;/ul&gt;&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;编写利于缓存的脚本&lt;/h3&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;脚本缺省不会返回校验参数（返回Last-Modified或ETag头信息）或其他新鲜度信息（Expires或Cache-Control），有些动态脚本的确是动态内容（每次相应内容都不一样），但是更多（搜索引擎，数据库引擎网站）网站还是能从缓存友好中获益的。&lt;br /&gt;一般说来，如果脚本生成的输出在未来一段时间（几分钟或者几天）都是可重复复制的，那么就是可缓存的。如果脚本输出内容只随URL变化而变化，也是可缓存的；但如果输出会根据cookie，认证信息或者其他外部条件变化，则还是不可缓存的。&lt;/div&gt;&lt;ul style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;最利于缓存的脚本就是将内容改变时导出成静态文件，Web服务器可以将其当作另外一个网页并生成和试用校验参数，让一些都变得更简单，只需要写入文件即可，这样最后修改时间也有了；&lt;/li&gt;&lt;li&gt;另外一个让脚本可缓存的方法是对一段时间内能保持较新的内容设置一个相对寿命的头信息，虽然通过Expires头信息也可以实现，但更容易的是用Cache-Control: max-age属性，它会让首次请求后一段时间内缓存保持新鲜；&lt;/li&gt;&lt;li&gt;如果以上做法你都做不到，你可以让脚本生成一个校验属性，并对 If-Modified-Since 和/或If-None-Match请求作出反应，这些属性可以从解析HTTP头信息得到，并对符合条件的内容返回304 Not Modified（内容未改变），可惜的是，这种做法比不上前2种高效；&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;其他窍门：&lt;/div&gt;&lt;ul style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;尽量避免使用POST，除非万不得已，POST模式的返回内容不会被大部分缓存服务器保存，如果你发送内容通过URL和查询（通过GET模式）的内容可以缓存下来供以后使用；&lt;/li&gt;&lt;li&gt;不要在URL中加入针对每个用户的识别信息：除非内容是针对每个用户不同的；&lt;/li&gt;&lt;li&gt;不要统计一个用户来自一个地址的所有请求，因为缓存常常是一起工作的；&lt;/li&gt;&lt;li&gt;生成并返回Content-Length头信息，如果方便的话，这个属性让你的脚本在可持续链接模式时：客户端可以通过一个TCP/IP链接同时请求多个副本，而不是为每次请求单独建立链接，这样你的网站相应会快很多；&lt;/li&gt;&lt;/ul&gt;具体定义请参考实现章节。&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;常见问题解答&lt;/h3&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;让网站变得可缓存的要点是什么？&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;好的策略是确定那些内容最热门，大量的复制（特别是图片）并针对这些内容先部署缓存。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;如何让页面通过缓存达到最快相应？&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;缓存最好的副本是那些可以长时间保持新鲜的内容；基于校验虽然有助于加快相应，但是它不得不和源服务器联系一次去检查内容是否够新，如果缓存服务器上就知道内容是新的，内容就可以直接相应返回了。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;我理解缓存是好的，但是我不得不统计多少人访问了我的网站！&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;如果你必须知道每次页面访问的，选择【一】个页面上的小元素，或者页面本身，通过适当的头信息让其不可缓存，例如： 可以在每个页面上部署一个1x1像素的透明图片。Referer头信息会有包含这个图片的每个页面信息；&lt;br /&gt;明确一点：这个并不会给你一个关于你用户精确度很高的统计，而且这对互联网和你的用户这都不太好，消耗了额外的带宽，强迫用户去访问无法缓存的内容。了解更多信息，参考访问统计资料。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;我如何能看到HTTP头信息的内容？&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;很多浏览器在页面属性或类似界面中可以让你看到Expires 和Last-Modified信息；如果有的话：你会找到页面信息的菜单和页面相关的文件（如图片），并且包含他们的详细信息；&lt;br /&gt;看到完整的头信息，你可以用telnet手工连接到Web服务器；&lt;br /&gt;为此：你可能需要用一个字段指定端口（缺省是80），或者链接到www.example.com:80 或者 www.example.com 80(注意是空格)，更多设置请参考一下telnet客户端的文档；&lt;br /&gt;打开网站链接：请求一个查看链接，如果你想看到http://www.example.com/foo.html 连接到www.example.com的80端口后，键入：&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;GET /foo.html HTTP/1.1 [回车]&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;GET /foo.html HTTP/1.1 [return]&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Host: www.example.com [回车][回车]&amp;nbsp;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Host: www.example.com [return][return]&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;在[回车]处按键盘的回车键；在最后，要按2次回车，然后，就会输出头信息及完整页面，如果只想看头信息，将GET换成HEAD。&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;我的页面是密码保护的，代理缓存服务器如何处理他们？&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;缺省的，网页被HTTP认证保护的都是私密内容，它们不会被任何共享缓存保留。但是，你可以通过设置Cache-Control: public让认证页面可缓存，HTTP 1.1标准兼容的缓存服务器会认出它们可缓存。&lt;br /&gt;如果你认为这些可缓存的页面，但是需要每个用户认证后才能看，可以组合使用Cache-Control: public和no-cache头信息，高速缓存必须在提供副本之前，将将新客户的认证信息提交给源服务器。设置就是这样：&lt;/div&gt;&lt;blockquote style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;em&gt;Cache-Control: public, no-cache&lt;/em&gt;&lt;/blockquote&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;无论如何：这是减少认证请求的最好方法，例如： 你的图片是不机密的，将它们部署在另外一个目录，并对此配置服务器不强制认证。这样，那些图片会缺省都缓存。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;我们是否要担心用户通过cache访问我的站点？&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;代理服务器上SSL页面不会被缓存（不推荐被缓存），所以你不必为此担心。但是，由于缓存保存了非SSL请求和从他们抓取的URL，你要意识到没有安全保护的网站，可能被不道德的管理员可能搜集用户隐私，特别是通过URL。&lt;br /&gt;实际上，位于服务器和客户端之间的管理员可以搜集这类信息。特别是通过CGI脚本在通过URL传递用户名和密码的时候会有很大问题；这对泄露用户名和密码是一个很大的漏洞；&lt;br /&gt;如果你初步懂得互联网的安全机制，你不会对缓存服务器有任何。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;我在寻找一个包含在Web发布系统解决方案，那些是比较有缓存意识的系统？&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;这很难说，一般说来系统越复杂越难缓存。最差就是全动态发布并不提供校验参数；你无发缓存任何内容。可以向系统提供商的技术人员了解一下，并参考后面的实现说明。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;我的图片设置了1个月后过期，但是我现在需要现在更新。&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;过期时间是绕不过去的，除非缓存（浏览器或者代理服务器）空间不足才会删除副本，缓存副本在过期之间会被一直使用。&lt;br /&gt;最好的办法是改变它们的链接，这样，新的副本将会从源服务器上重新下载。记住：引用它们的页面本身也会被缓存。因此，使用静态图片和类似内容是很容易缓存的，而引用他们的HTML页面则要保持非常更新；&lt;br /&gt;如果你希望对指定的缓存服务器重新载入一个副本，你可以强制使用“刷新”（在FireFox中在reload的时候按住shift键：就会有前面提到恶Pragma: no-cache头信息发出）。或者你可以让缓存的管理员从他们的界面中删除相应内容；&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;我运行一个Web托管服务，如何让我的用户发布缓存友好的网页？&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;如果你使用apahe，可以考虑允许他们使用.htaccess文件并提供相应的文档；&lt;br /&gt;另外一方面： 你也可以考虑在各种虚拟主机上建立各种缓存策略。例如： 你可以设置一个目录 /cache-1m 专门用于存放访问1个月的访问，另外一个 /no-cache目录则被用提供不可存储副本的服务。&lt;br /&gt;无论如何：对于大量用户访问还是应该用缓存。对于大网站，这方面的节约很明显（带宽和服务器负载）；&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;我标记了一些网页是可缓存的，但是浏览器仍然每次发送请求给服务。如何强制他们保存副本？&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;缓存服务器并不会总保存副本并重用副本；他们只是在特定情况下会不保存并使用副本。所有的缓存服务器都回基于文件的大小，类型（例如：图片 页面），或者服务器空间的剩余来确定如何缓存。你的页面相比更热门或者更大的文件相比，并不值得缓存。&lt;br /&gt;所以有些缓存服务器允许管理员根据文件类型确定缓存副本的优先级，允许某些副本被永久缓存并长期有效；&lt;/div&gt;&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;缓存机制的实现 - Web服务器端配置&lt;/h3&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;一般说来，应该选择最新版本的Web服务器程序来部署。不仅因为它们包含更多利于缓存的功能，新版本往往在性能和安全性方面都有很多的改善。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Apache HTTP服务器&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Apache有些可选的模块来包含这些头信息： 包括Expires和Cache-Control。 这些模块在1.2版本以上都支持；&lt;br /&gt;这些模块需要和apache一起编译；虽然他们已经包含在发布版本中，但缺省并没有启用。为了确定相应模块已经被启用：找到httpd程序并运行httpd -l 它会列出可用的模块，我们需要用的模块是mod_expires和mod_headers&lt;/div&gt;&lt;ul style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;如果这些模块不可用，你需要联系管理员，重新编译并包含这些模块。这些模块有时候通过配置文件中把注释掉的配置启用，或者在编译的时候增加-enable -module=expires和-enable-module=headers选项（在apache 1.3和以上版本）。 参考Apache发布版中的INSTALL文件；&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Apache一旦启用了相应的模块，你就可以在.htaccess文件或者在服务器的access.conf文件中通过mod_expires设置副本什 么时候过期。你可设置过期从访问时间或文件修改时间开始计算，并且应用到某种文件类型上或缺省设置，参考&lt;a href=&quot;http://httpd.apache.org/docs/1.3/mod/mod_expires.html&quot; style=&quot;color: #0f314e;&quot;&gt;模块的文档&lt;/a&gt;获得更多信息，或者遇到问题的时候向你身边的apache专家讨教。&lt;br /&gt;应用Cache-Control头信息，你需要使用mod_headers,它将允许你设置任意的HTTP头信息，参考&lt;a href=&quot;http://httpd.apache.org/docs/1.3/mod/mod_headers.html&quot; style=&quot;color: #0f314e;&quot;&gt;mod_headers的文档&lt;/a&gt;可以获得更多资料；&lt;br /&gt;这里有个例子说明如何使用头信息：&lt;/div&gt;&lt;ul style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;.htaccess文件允许web发布者使用命令只在配置文件中用到的命令。他影响到所在目录及其子目录；问一下你的服务器管理员确认这个功能是否启用了。&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;### 启用 mod_expires&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;ExpiresActive On&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;### 设置 .gif 在被访问过后1个月过期。&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;ExpiresByType image/gif A2592000&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;### 其他文件设置为最后修改时间1天后过期&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;### (用了另外的语法)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;ExpiresDefault &quot;modification plus 1 day&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;### 在index.html文件应用 Cache-Control头属性&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;files index.html=&quot;&quot;&gt;&lt;/files&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Header append Cache-Control &quot;public, must-revalidate&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&lt;ul style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;li&gt;注意： 在适当情况下mod_expires会自动计算并插入Cache-Control:max-age 头信息&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Apache 2.0的配置和1.3类似，更多信息可以参考2.0的&lt;a href=&quot;http://httpd.apache.org/docs/2.2/mod/mod_expires.html&quot; style=&quot;color: #0f314e;&quot;&gt;mod_expires&lt;/a&gt;和&lt;a href=&quot;http://httpd.apache.org/docs/2.2/mod/mod_headers.html&quot; style=&quot;color: #0f314e;&quot;&gt;mod_headers文档&lt;/a&gt;；&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Microsoft IIS服务器&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Microsoft的IIS可以非常容易的设置头信息，注意：这只针对IIS 4.0服务器，并且只能在NT服务器上运行。&lt;br /&gt;为网站的一个区域设置头信息，先要到管理员工具界面中，然后设置属性。选择HTTP Header选单，你会看到2个有趣的区域：启用内容过期和定制HTTP头信息。头一个设置会自动配置，第二个可以用于设置Cache-Control头信息；&lt;br /&gt;设置asp页面的头信息可以参考后面的ASP章节，也可以通过ISAPI模块设置头信息，细节请参考MSDN。&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Netscape/iPlanet企业服务器&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;3.6版本以后，Netscape/iPlanet已经不能设置Expires头信息了，他从3.0版本开始支持HTTP 1.1的功能。这意味着HTTP 1.1的缓存（代理服务器/浏览器）优势都可以通过你对Cache-Control设置来获得。&lt;br /&gt;使用Cache-Control头信息，在管理服务器上选择内容管理|缓存设置目录。然后：使用资源选择器，选择你希望设置头信息的目录。设置完头信息后，点击“OK”。更多信息请参考&lt;a href=&quot;http://developer.netscape.com/docs/manuals/enterprise/admnunix/content.htm#1006282&quot; style=&quot;color: #0f314e;&quot;&gt;Netscape/iPlanet企业服务器的手册&lt;/a&gt;。&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;缓存机制的实现：服务器端脚本&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;需要注意的一点是：也许服务器设置HTTP头信息比脚本语言更容易，但是两者你都应该使用。&lt;br /&gt;因为服务器端的脚本主要是为了动态内容，他本身不产生可缓存的文件页面，即使内容实际是可以缓存的。如果你的内容经常改变，但是不是每次页面请求都改变， 考虑设置一个Cache-Control: max-age头信息；大部分用户会在短时间内多次访问同一页面。例如： 用户点击“后退”按钮，即使没有新内容，他们仍然要再次从服务器下载内容查看。&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;CGI程序&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;CGI脚本是生成内容最流行的方式之一，你可以很容易在发送内容之前的扩展HTTP头信息；大部分CGI实现都需要你写 Content-Type头信息，例如这个Perl脚本：&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;#!/usr/bin/perl&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;print &quot;Content-type: text/html\n&quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;print &quot;Expires: Thu, 29 Oct 1998 17:04:19 GMT\n&quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;print &quot;\n&quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;### 后面是内容体...&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;由于都是文本，你可以很容易通过内置函数生成Expires和其他日期相关的头信息。如果你使用Cache-Control: max-age;会更简单；&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;print &quot;Cache-Control: max-age=600\n&quot;;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;这样脚本可以在被请求后缓存10分钟；这样用户如果按“后退”按钮，他们不会重新提交请求；&lt;br /&gt;CGI的规范同时也允许客户端发送头信息，每个头信息都有一个‘HTTP_’的前缀；这样如果一个客户端发送一个If-Modified-Since请求，就是这样的：&lt;/div&gt;&lt;div style=&quot;font-style: italic; margin-left: 40px;&quot;&gt;HTTP_IF_MODIFIED_SINCE = Fri, 30 Oct 1998 14:19:41 GMT&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;br /&gt;参考一下&lt;a href=&quot;http://www.mnot.net/cgi_buffer/&quot; style=&quot;color: #0f314e;&quot;&gt;cgi_buffer&lt;/a&gt;库，一个自动处理ETag的生成和校验的库，生成Content-Length属性和对内容进行gzip压缩。在Python脚本中也只需加入一行；&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;服务器端包含 Server Side Includes&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;SSI（经常使用.shtml扩展名）是网站发布者最早可以生成动态内容的方案。通过在页面中设置特别的标记，也成为一种嵌入HTML的脚本；&lt;br /&gt;大部分SSI的实现无法设置校验器，于是无法缓存。但是Apache可以通过对特定文件的组执行权限设置实现允许用户设置那种SSI可以被缓存；结合XbitHack调整整个目录。更多文档请参考&lt;a href=&quot;http://httpd.apache.org/docs/1.3/mod/mod_include.html&quot; style=&quot;color: #0f314e;&quot;&gt;mod_include文档&lt;/a&gt;。&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;PHP&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;PHP是一个内建在web服务器中的服务器端脚本语言，当做为HTML嵌入式脚本，很像SSI，但是有更多的选项，PHP可以在各种Web服务器上设置为CGI模式运行，或者做为Apache的模块；&lt;br /&gt;缺省PHP生成副本没有设置校验器，于是也无法缓存，但是开发者可以通过Header()函数来生成HTTP的头信息；&lt;br /&gt;例如：以下代码会生成一个Cache-Control头信息，并设置为3天以后过期的Expires头信息；&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;Header(&quot;Cache-Control: must-revalidate&quot;);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;$offset = 60 * 60 * 24 * 3;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;$ExpStr = &quot;Expires: &quot; . gmdate(&quot;D, d M Y H:i:s&quot;, time() + $offset) . &quot; GMT&quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;nbsp;Header($ExpStr);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;?&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;记住： Header()的输出必须先于所有其他HTML的输出；&lt;br /&gt;正如你看到的：你可以手工创建HTTP日期；PHP没有为你提供专门的函数（新版本已经让这个越来越容易了，请参考PHP的&lt;a href=&quot;http://php.net/date&quot; style=&quot;color: #0f314e;&quot;&gt;日期相关函数文档&lt;/a&gt;），当然，最简单的还是设置Cache-Control: max-age头信息，而且对于大部分情况都比较适用；&lt;br /&gt;更多信息，请参考&lt;a href=&quot;http://www.php.net/manual/function.header.php3&quot; style=&quot;color: #0f314e;&quot;&gt;header相关的文档&lt;/a&gt;；&lt;br /&gt;也请参考一下&lt;a href=&quot;http://www.mnot.net/cgi_buffer/&quot; style=&quot;color: #0f314e;&quot;&gt;cgi_buffer&lt;/a&gt;库，自动处理ETag的生成和校验，Content-Length生成和内容的gzip压缩，PHP脚本只需包含1行代码；&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;Cold Fusion&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;a href=&quot;http://www.adobe.com/products/coldfusion/&quot; style=&quot;color: #0f314e;&quot;&gt;Cold Fusion&lt;/a&gt;是Macromedia的商业服务器端脚本引擎，并且支持多种Windows平台，Linux平台和多种Unix平台。Cold Fusion通过CFHEADER标记设置HTTP头信息相对容易。可惜的是：以下的Expires头信息的设置有些容易误导；&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;cfheader name=&quot;Expires&quot; value=&quot;#Now()#&quot;&gt;&lt;/cfheader&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;它并不像你想像的那样工作，因为时间（本例中为请求发起的时间）并不会被转换成一个符合HTTP时间，而且打印出副本的Cold fusion的日期/时间对象，大部分客户端会忽略或者将其转换成1970年1月1日。&lt;br /&gt;但是：Cold Fusion另外提供了一套日期格式化函数， GetHttpTimeSTring. 结合DateAdd函数，就很容易设置过期时间了，这里我们设置一个Header声明副本在1个月以后过期；&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&lt;cfheader name=&quot;Expires&quot; value=&quot;#GetHttpTimeString(DateAdd(&#39;m&#39;, 1, Now()))#&quot;&gt;&lt;/cfheader&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;你也可以使用CFHEADER标签来设置Cache-Control: max-age等其他头信息；&lt;br /&gt;记住：Web服务器也会将头信息设置转给Cold Fusion(做为CGI运行的时候)，检查你的服务器设置并确定你是否可以利用服务器设置代替Cold Fusion。&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;ASP和ASP.NET&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;在asp中设置HTTP头信息是：确认Response方法先于HTML内容输出前被调用，或者使用 Response.Buffer暂存输出；同样的：注意某些版本的IIS缺省设置会输出Cache-Control: private 头信息，必须声明成public才能被共享缓存服务器缓存。&lt;br /&gt;IIS的ASP和其他web服务器都允许你设置HTTP头信息，例如： 设置过期时间，你可以设置Response对象的属性；&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;lt;% Response.Expires=1440 %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;设置请求的副本在输出的指定分钟后过期，类似的：也可以设置绝对的过期时间（确认你的HTTP日期格式正确）&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;&amp;lt;% Response.ExpiresAbsolute=#May 31,1996 13:30:15 GMT# %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Cache-Control头信息可以这样设置：&lt;/div&gt;&lt;div style=&quot;font-style: italic; margin-left: 40px;&quot;&gt;&amp;lt;% Response.CacheControl=&quot;public&quot; %&amp;gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;在ASP.NET中，Response.Expires 已经不推荐使用了，正确的方法是通过Response.Cache设置Cache相关的头信息；&lt;/div&gt;&lt;div style=&quot;margin-left: 40px;&quot;&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Response.Cache.SetExpires ( DateTime.Now.AddMinutes ( 60 ) ) ;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Response.Cache.SetCacheability ( HttpCacheability.Public ) ;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;参考&lt;a href=&quot;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconaspoutputcache.asp&quot; style=&quot;color: #0f314e;&quot;&gt;MSDN文档&lt;/a&gt;可以找到更多相关新年系；&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;参考文档和深入阅读&lt;/h3&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;a href=&quot;http://www.ietf.org/rfc/rfc2616.txt&quot; style=&quot;color: #0f314e;&quot; target=&quot;_blank&quot;&gt;HTTP 1.1 规范定义&lt;/a&gt;&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;HTTP 1.1的规范有大量的扩展用于页面缓存，以及权威的接口实现指南，参考章节：13, 14.9, 14.21, 以及 14.25.&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;a href=&quot;http://www.web-caching.com/&quot; style=&quot;color: #0f314e;&quot; target=&quot;_blank&quot;&gt;Web-Caching.com&lt;/a&gt;&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;非常精彩的介绍缓存相关概念，并介绍其他在线资源。&lt;br /&gt;&lt;a href=&quot;http://www.goldmark.org/netrants/webstats/&quot; style=&quot;color: #0f314e;&quot; target=&quot;_blank&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;a href=&quot;http://www.goldmark.org/netrants/webstats/&quot; style=&quot;color: #0f314e;&quot; target=&quot;_blank&quot;&gt;关于非连续性访问统计&lt;/a&gt;&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;Jeff Goldberg内容丰富的演说告诉你为什么不应该过度依赖访问统计和计数器；&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;a href=&quot;http://www.mnot.net/cacheability/&quot; style=&quot;color: #0f314e;&quot;&gt;可缓存性检测引擎&lt;/a&gt;&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;可缓存的引擎设计，检测网页并确定其如何与Web缓存服务器交互， 这个引擎配合这篇指南是一个很好的调试工具，&lt;br /&gt;&lt;/div&gt;&lt;h4 style=&quot;font-weight: normal; margin-bottom: 10px; margin-top: 10px;&quot;&gt;&lt;a href=&quot;http://www.mnot.net/cgi_buffer/&quot; style=&quot;color: #0f314e;&quot;&gt;cgi_buffer库&lt;/a&gt;&lt;/h4&gt;&lt;div style=&quot;margin-bottom: 10px; margin-top: 10px;&quot;&gt;包含库：用于CGI模式运行的Perl/Python/PHP脚本，自动处理ETag生成/校验，Content-Length生成和内容压缩。正确地。 Python版本也被用作其他大量的CGI脚本。&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/6982632459979288720/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/08/web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/6982632459979288720'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/6982632459979288720'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/08/web.html' title='面向站长和网站管理员的Web缓存加速指南'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-3919416116806496698</id><published>2013-07-04T13:18:00.000+10:00</published><updated>2013-07-04T13:18:22.901+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="business"/><title type='text'>成功创业家的法则：学好再做还是边做边学？</title><content type='html'>今日忙碌，再以以前作品《别学北极熊》其中一篇章摘录一段给各位分享：&lt;br /&gt;  成功创业家都不约而同的告诉我，他们创业的时候，&lt;strong&gt;根本不知道自己在做什么&lt;/strong&gt;。假如他们当初真的想得很清楚，再三的确认无误才宣布创业，可能就永远不会创业了，不可能以成功创业家悠闲姿态坐在我面前。&lt;br /&gt;  成功创业家一点也不讳言，他们在创业初期，是从跌跌撞撞中闯出一番头绪。&lt;strong&gt;第一次创业，一群二十几岁的人，能懂得什么东西&lt;/strong&gt;？年纪三十出头就把公司卖掉的杨孟佑回忆当时年纪小：都是靠自己的感觉，&lt;strong&gt;随后再调整&lt;/strong&gt;。&lt;br /&gt;  你可以看到，成功创业家虽然是这世代最年轻就累积财富的一群，他们的学、经历却不一定是同年纪中最好的。为什么？这是因为，那些总是从最好的学校出来、录取最好的公司的高层人士，从小到大都在做正确的事，养成了做什么事都要求&lt;strong&gt;正确&lt;/strong&gt;的习惯，在创业方面反而就缚手缚脚。&lt;strong&gt;他们都是&lt;/strong&gt;&lt;strong&gt;先学好再做好&lt;/strong&gt;，&lt;strong&gt;成功创业家则是&lt;/strong&gt;&lt;strong&gt;一边做一边学&lt;/strong&gt;。科技创业，本来就是需要一些傻劲；那些习惯做正确的事的守本份的人，傻劲就缺了一些。&lt;br /&gt;  大部份的人都缺乏傻劲，也因此无法认同创业家的傻劲。他们看到别人创业，第一句话就是：你，真的可以创业吗？听了对方的点子，还没听完就说：真的有这么简 单吗？等到他也开始羡慕成功创业家，打算自己出来创业时，他会先做了非常详尽的市场调查，各项细节都考虑了非常详尽，还很害怕别人将他的点子偷走，这样的 人，速度太慢，要考虑的事情太多，便无法支持到最后一刻，创业也无法成功。&lt;br /&gt;  成功创业家想都不想就跳下去，如此莽撞的行为为什么反而容易创业成功？大概是因为科技创业成功的人，一定是靠创新，在产业里应该是第一位。这就好像田径 赛。跑第二名的，可以跟着第一名跑，第三名则可以跟着第一和第二名跑，但，身为第一名的，若还东张西望、研究自己跑的跑道是否正确，就会愈跑愈慢，跑得摇 摇晃晃，跑得不够坚决，很快就会被第二名赶上去，要不也自己先精疲力竭了。&lt;br /&gt;  林百里当初创立广达电脑，就是一口气就砸了三千万资金、聘了二十余人的团队，不到半年就做出了产品。也就是林百里迅速的动作，公司马上取得先机，获欧美大厂订单，也因而进步迅速，让广达先一步的成为全球最大的笔记型电脑工厂。&lt;br /&gt;  看着各方创业家成长长达二十年的成功创业家沙正治，也对于这件事有很深刻的感觉。他说，成功创业家当然也不是随便创业，但他们作初期的创业分析时，都是盲 目的自信。到最后，产品完成的期限一定是一延再延，比计画中的还长几倍。等到把东西好不容易都做出来了，人家就是不买；有时候，别人又突然买了，你也摸不 透他为什么买了！&lt;br /&gt;  既然再厉害的创业家都很难计划得周全，所以周全就不是这么重要了。创业，要有一种&lt;strong&gt;永不妥协的个性和宗教式的狂热&lt;/strong&gt;。沙正治说：太注重理性、完美的人，并不适合创业。&lt;br /&gt;  科技本身本来就是充满风险，已经成功五次的人，下次不见得会成功；已经失败五次的人，下次也不见得会失败。就是因为这样，成功创业家这样的做下去精神，让他们至少比别人更有机会。创业家一定要有勇气大声说：没关系，做下去，这次或许失败了，但一定会有成功的一天！&lt;br /&gt;  而&lt;strong&gt;做中学&lt;/strong&gt;，&lt;strong&gt;就是最好的学习方法&lt;/strong&gt;。若创业家没有先起个头，他也没机会调整方向，也就没机会将他个人和公司透过学习而提升到下一步的程度，成为成功创业家。&lt;br /&gt; 在印度被称作教父级的创业元老雷奇（Kanwal Rekhi），虽然很聪明，从来学不会做人处事的圆融技巧，七零年代，在美国各大公司工作了林林总总十一年，却从来没担任过比系统工程师更高的职位。老板 告诉他，因为他太聪明，是个不可多得的技术天才，所以不忍埋没他的才能，不能让他当经理。雷奇愤而和他的印度朋友一起创立Excelan公司，虽然技术很 强，但在当时白人气氛下，雷奇又不擅做人，资金找得非常辛苦，最后好不容易从一个白人创投拿到钱。&lt;br /&gt;  拿到钱后，没人放心让雷自己做，一开始执行长给别人做。后来他做不下去，雷奇才重新接掌，但随后又因为公司要上市被换下来，之后又因为执行长管不住才被换 回来。没想到，雷奇做了以后，管理公司的能力大增，因为他喜欢当老板的感觉做得好。后来，原本看起来和人无法相处的雷奇，做到Novell公司的技术长， 并在故乡印度做了一连串有远见的东西，他被印度人称为爸爸，登上了富比士（ Forbes）的封面。成为一个最受尊敬的人。但，有谁去想过，为何他能从一个怪异孤僻的人，变成人人爱戴的人，这些都是从他创业的过程中做中学出来的。&lt;br /&gt;  注意，并不是所有事都可以随便做下去试试。成功创业家做下去之前，还是对财务要有一定的规画。张敦凯在这方面就很有经验了。当时他靠着从前工作所积得的一 些现金和股票，算一算，没收入仍可撑二到三年，在创业之前，在财务上已经有了最坏的准备。除了个人以外，在公司的财务也要注意，方向错了没关系，但公司财 务的观念一定要有。不知道这产品能不能用无所谓，但一定要知道这钱能烧多久。&lt;br /&gt;  把财务都算清楚以后，张敦凯就和其他的创业家一样，捏起鼻孔噗通跳进水里。当时他才三十三岁，并未真的懂得从市场的角度来看东西，只大概看了一下市场，觉 得市场大概蛮大的。然后就钻了进去，中间方向有点错，但都还可以改，一边改，一边就看得到市场中有大大小小的缝隙，就能找到自己的特殊点（niche）。 张敦凯最后终于突破了一重又一重的难关，他的公司也在台湾上市了。回想当年当他还是青涩的创业家一路学来的过程，他不禁一笑：假如当时想得太清楚，就不会 出来创业啦！&lt;br /&gt;  而成功创业家勇于做下去，也是在为自己增加成功的机会。多尝试者，铁定让成功机率增加。一次又一次的试，从每次尝试中去作微调，就会愈来愈容易成功。&lt;br /&gt;  把公司卖掉赚进亿万财富的陈劲初，回想当年创业的时候，一心只想设计一个全世界唯一做这东西的积体电路，就找了一个朋友，两人很高兴的做起来了。等到做完 积体电路才发现没有电路板可装这个积体电路，只好自己再继续做电路板。等到做完电路板，又发现市场上没软体可用这样的电路板，于是就连软体也自己做。等到 所有东西都做完了，发现没人帮他们卖产品，只好跑来自己卖。这些都不见得是当初刚创业的人所想得到的，但，若没有做出积体电路，怎么知道电路板需要呢？若 没做到下一步，要怎么知道其它东西有需要呢？&lt;br /&gt;  这些成功创业家一致认为，尤其是东方人，更需要训练不怕失败的饪性。科技大老史钦泰认为，东方的教育系统在培养学龄儿童不怕输精神方面，做得相当少，因此 东方人创业家相对就比较少。史钦泰忧心国内成者为王，败者为寇的竞争环境，虽然刺激很多人进步再进步，但同时也让很多人由于怕失败了被嘲笑、被以异样眼光 对待，于是对于冒险一途望之却步，许多创意十足的构想也从来没人敢拿出来发表。&lt;br /&gt; 成功创业家根本不知道要向谁学。所以他们只能一边做一边学。&lt;br /&gt;  也就是说，创业成功的技巧无它，只要你&lt;strong&gt;肯踏出第一步&lt;/strong&gt;，&lt;strong&gt;一边做一边学&lt;/strong&gt;！</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/3919416116806496698/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/07/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/3919416116806496698'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/3919416116806496698'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/07/blog-post.html' title='成功创业家的法则：学好再做还是边做边学？'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-4943516213687920352</id><published>2013-06-29T15:38:00.002+10:00</published><updated>2013-06-29T15:38:32.703+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>Eclipse Java EE jQuery Validation Error Workaround</title><content type='html'>&lt;br /&gt;&lt;div style=&quot;background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #444444; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;During my recent Java EE project I came across an annoying bug which always showed an Error Symbol on my root project folder. At first I thought it was a Java error but then I saw it was caused by the minified version of jQuery (jquery-1.7.2.min.js) in my case. This is an&amp;nbsp;&lt;a href=&quot;https://bugs.eclipse.org/bugs/show_bug.cgi?id=349020&quot; style=&quot;-webkit-tap-highlight-color: rgb(255, 94, 153); background-color: transparent; color: #3777af; font-weight: bold; margin: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot; target=&quot;_blank&quot;&gt;Eclipse bug&lt;/a&gt;&amp;nbsp;already reported in summer 2011. I guess this can also happen with other minified JavaScript files.&lt;/div&gt;&lt;div style=&quot;background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #444444; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; margin-bottom: 1.5em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span id=&quot;more-219&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 style=&quot;background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 2em; letter-spacing: -0.05em; line-height: 1.125em; margin: 0.75em 0px 0.375em; outline: 0px; padding: 0px; text-rendering: optimizelegibility; text-shadow: rgba(255, 255, 255, 0.952941) 0px 1px 0px; vertical-align: baseline;&quot;&gt;Workaround – How to fix&lt;/h2&gt;&lt;div style=&quot;background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #444444; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;To get rid of the annoying Error symbol do the following:&lt;/div&gt;&lt;ol style=&quot;background-color: rgba(255, 255, 255, 0.952941); border: 0px; color: #444444; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 16px; line-height: 24px; list-style-image: initial; list-style-position: outside; margin: 0px 0px 2em 2em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;Right click your&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Project root folder&lt;/strong&gt;&amp;nbsp;in your&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Eclipse Project Explorer View&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Go to&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Properties -&amp;gt; JavaScript -&amp;gt; Include Path -&amp;gt; Source Tab&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Select&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Excluded&lt;/strong&gt;&amp;nbsp;and&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Edit…&amp;nbsp;&lt;/strong&gt;and then&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;Add..&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Now you can either&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;browse for JavaScript&lt;/strong&gt;&amp;nbsp;file which has errors or just enter a&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;wildcard pattern&lt;/strong&gt;which will exclude anything matched by your pattern. In my case in entered&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;**/jquery*.js&lt;/strong&gt;&amp;nbsp;to exclude all jQuery library files.&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Then you can hit&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;OK, Finish&amp;nbsp;&lt;/strong&gt;and&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;OK&lt;/strong&gt;&amp;nbsp;again&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Your&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Eclipse Progress View&lt;/strong&gt;&amp;nbsp;should now show a&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Building Workspace&lt;/strong&gt;&amp;nbsp;message&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Tada! The Error Symbol is gone!&lt;/li&gt;&lt;/ol&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/4943516213687920352/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/06/eclipse-java-ee-jquery-validation-error.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/4943516213687920352'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/4943516213687920352'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/06/eclipse-java-ee-jquery-validation-error.html' title='Eclipse Java EE jQuery Validation Error Workaround'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-3608120677346495703</id><published>2013-06-22T14:16:00.000+10:00</published><updated>2013-06-22T14:16:41.927+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="software engineering"/><title type='text'>What do “branch”, “tag” and “trunk” mean in Subversion repositories?</title><content type='html'>&lt;br /&gt;&lt;ul style=&quot;background-color: white; border: 0px; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; list-style-image: initial; list-style-position: initial; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;background-color: transparent; border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;a href=&quot;http://svnbook.red-bean.com/en/1.7/svn.tour.importing.html#svn.tour.importing.layout&quot; style=&quot;background-color: transparent; border: 0px; color: #4a6b82; cursor: pointer; margin: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Trunk&lt;/strong&gt;&lt;/a&gt;&amp;nbsp;would be the main body of development, originating from the start of the project until the present.&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;background-color: transparent; border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;a href=&quot;http://svnbook.red-bean.com/en/1.7/svn.branchmerge.whatis.html&quot; style=&quot;background-color: transparent; border: 0px; color: #4a6b82; cursor: pointer; margin: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Branch&lt;/strong&gt;&lt;/a&gt;&amp;nbsp;will be a copy of code derived from a certain point in the trunk that is used for applying major changes to the code while preserving the integrity of the code in the trunk. If the major changes work according to plan, they are usually merged back into the trunk.&lt;/div&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;div style=&quot;background-color: transparent; border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;a href=&quot;http://svnbook.red-bean.com/en/1.7/svn.branchmerge.tags.html&quot; style=&quot;background-color: transparent; border: 0px; color: #4a6b82; cursor: pointer; margin: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Tag&lt;/strong&gt;&lt;/a&gt;&amp;nbsp;will be a point in time on the trunk or a branch that you wish to preserve. The two main reasons for preservation would be that either this is a major release of the software, whether alpha, beta, RC or RTM, or this is the most stable point of the software before major revisions on the trunk were applied.&lt;/div&gt;&lt;div style=&quot;background-color: transparent; border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;For example, let&#39;s say you start a new project. You start working in &quot;trunk&quot;, on what will eventually be released as version 1.0.&lt;/div&gt;&lt;ul style=&quot;border: 0px; list-style: disc; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;trunk/ - development version, soon to be 1.0&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;branches/ - empty&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;Once 1.0.0 is finished, you branch trunk into a new &quot;1.0&quot; branch, and create a &quot;1.0.0&quot; tag. Now work on what will eventually be 1.1 continues in trunk.&lt;/div&gt;&lt;ul style=&quot;border: 0px; list-style: disc; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;trunk/ - development version,&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;soon to be 1.1&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;branches/1.0 - 1.0.0 release version&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;tags/1.0.0 - 1.0.0 release version&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;You come across some bugs in the code, and fix them in trunk, and then merge the fixes over to the 1.0 branch. You can also do the opposite, and fix the bugs in the 1.0 branch and then merge them back to trunk, but commonly projects stick with merging one-way only to lessen the chance of missing something. Sometimes a bug can only be fixed in 1.0 because it is obsolete in 1.1. It doesn&#39;t really matter: you only want to make sure that you don&#39;t release 1.1 with the same bugs that have been fixed in 1.0.&lt;/div&gt;&lt;ul style=&quot;border: 0px; list-style: disc; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;trunk/ - development version, soon to be 1.1&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;branches/1.0 -&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;upcoming 1.0.1 release&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;tags/1.0.0 - 1.0.0 release version&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;Once you find enough bugs (or maybe one critical bug), you decide to do a 1.0.1 release. So you make a tag &quot;1.0.1&quot; from the 1.0 branch, and release the code. At this point, trunk will contain what will be 1.1, and the &quot;1.0&quot; branch contains 1.0.1 code. The next time you release an update to 1.0, it would be 1.0.2.&lt;/div&gt;&lt;ul style=&quot;border: 0px; list-style: disc; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;trunk/ - development version, soon to be 1.1&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;branches/1.0 -&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;upcoming 1.0.2 release&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;tags/1.0.0 - 1.0.0 release version&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;tags/1.0.1 - 1.0.1 release version&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;Eventually you are almost ready to release 1.1, but you want to do a beta first. In this case, you likely do a &quot;1.1&quot; branch, and a &quot;1.1beta1&quot; tag. Now, work on what will be 1.2 (or 2.0 maybe) continues in trunk, but work on 1.1 continues in the &quot;1.1&quot; branch.&lt;/div&gt;&lt;ul style=&quot;border: 0px; list-style: disc; margin: 0px 0px 1em 30px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;trunk/ - development version,&amp;nbsp;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;soon to be 1.2&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;branches/1.0 - upcoming 1.0.2 release&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;branches/1.1 - upcoming 1.1.0 release&lt;/strong&gt;&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;tags/1.0.0 - 1.0.0 release version&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;tags/1.0.1 - 1.0.1 release version&lt;/li&gt;&lt;li style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;&lt;strong style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;tags/1.1beta1 - 1.1 beta 1 release version&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;Once you release 1.1 final, you do a &quot;1.1&quot; tag from the &quot;1.1&quot; branch.&lt;/div&gt;&lt;div style=&quot;border: 0px; clear: both; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;You can also continue to maintain 1.0 if you&#39;d like, porting bug fixes between all three branches (1.0, 1.1, and trunk). The important takeaway is that for every main version of the software you are maintaining, you have a branch that contains the latest version of code for that version.&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/3608120677346495703/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/06/what-do-branch-tag-and-trunk-mean-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/3608120677346495703'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/3608120677346495703'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/06/what-do-branch-tag-and-trunk-mean-in.html' title='What do “branch”, “tag” and “trunk” mean in Subversion repositories?'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-8324251700462171667</id><published>2013-06-05T19:37:00.002+10:00</published><updated>2013-06-05T19:37:11.261+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>浏览器缓存机制</title><content type='html'>&lt;b style=&quot;background-color: white; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px;&quot;&gt;Cache-Control&lt;/b&gt;&lt;br /&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;Cache-Control 是最重要的规则。这个字段用于指定所有缓存机制在整个请求/响应链中必须服从的指令。这些指令指定用于阻止缓存对请求或响应造成不利干扰的行为。这些指令通常覆盖默认缓存算法。缓存指令是单向的，即请求中存在一个指令并不意味着响应中将存在同一个指令。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;cache-control 定义是：Cache-Control = “Cache-Control” “:” cache-directive。表 1 展示了适用的值。&lt;/div&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 1. 常用 cache-directive 值&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Cache-directive&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;说明&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;public&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;所有内容都将被缓存&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;private&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容只缓存到私有缓存中&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;no-cache&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;所有内容都不会被缓存&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;no-store&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;所有内容都不会被缓存到缓存或 Internet 临时文件中&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;must-revalidation/proxy-revalidation&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;如果缓存的内容失效，请求必须发送到服务器/代理以进行重新验证&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;max-age=xxx (xxx is numeric)&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;缓存的内容将在 xxx 秒后失效, 这个选项只在HTTP 1.1可用, 并如果和Last-Modified一起使用时, 优先级较高&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;表 2 表明在不同的情形下，浏览器是将请求重新发送到服务器还是使用缓存的内容。&lt;/div&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 2. 对 cache-directive 值的浏览器响应&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Cache-directive&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;打开一个新的浏览器窗口&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;在原窗口中单击 Enter 按钮&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;刷新&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;单击 Back 按钮&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;public&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;private&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;第一次，浏览器重新发送请求到服务器；此后，浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;no-cache/no-store&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;must-revalidation/proxy-revalidation&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;第一次，浏览器重新发送请求到服务器；此后，浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;max-age=xxx (xxx is numeric)&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;在 xxx 秒后，浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;在 xxx 秒后，浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;在 xxx 秒后，浏览器重新发送请求到服务器&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;Cache-Control是关于浏览器缓存的最重要的设置，因为它覆盖其他设置，比如 Expires 和 Last-Modified。另外，由于浏览器的行为基本相同，这个属性是处理跨浏览器缓存问题的最有效的方法。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;&lt;b&gt;失效&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;Expires 头部字段提供一个日期和时间，响应在该日期和时间后被认为失效。失效的缓存条目通常不会被缓存（无论是代理缓存还是用户代理缓存）返回，除非首先通过原始服务器（或者拥有该实体的最新副本的中介缓存）验证。（注意：cache-control max-age 和 s-maxage 将覆盖 Expires 头部。）&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;Expires 字段接收以下格式的值：“Expires: Sun, 08 Nov 2009 03:37:26 GMT”。如果查看内容时的日期在给定的日期之前，则认为该内容没有失效并从缓存中提取出来。反之，则认为该内容失效，缓存将采取一些措施。表 3-6 表明针对不同用户操作的不同浏览器的行为。&lt;/div&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 3. 当用户打开一个新的浏览器窗口时的失效操作&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Firefox 3.5&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;IE 8&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Chrome 3&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容没有失效&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容失效&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 4. 当用户在原始浏览器窗口中单击 Enter 按钮时的失效操作&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Firefox 3.5&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;IE 8&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Chrome 3&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容没有失效&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容失效&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 5. 当用户按 F5 键刷新页面时的失效操作&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Firefox 3.5&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;IE 8&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Chrome 3&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容没有失效&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容失效&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 6. 当用户单击 Back 或 Forward 按钮时的失效操作&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Firefox 3.5&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;IE 8&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Chrome 3&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容没有失效&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容失效&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;注意：所有浏览器都假定为使用默认设置运行。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;&lt;b&gt;Last-Modified/E-Tag&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;Last-Modified 实体头部字段值通常用作一个缓存验证器。简单来说，如果实体值在 Last-Modified 值之后没有被更改，则认为该缓存条目有效。ETag 响应头部字段值是一个实体标记，它提供一个 “不透明” 的缓存验证器。这可能在以下几种情况下提供更可靠的验证：不方便存储修改日期；HTTP 日期值的 one-second 解决方案不够用；或者原始服务器希望避免由于使用修改日期而导致的某些冲突。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;不同的浏览器有不同的配置行为。表 7-10 表明针对不同用户操作的不同浏览器的行为。&lt;/div&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 7. 当用户打开一个新的浏览器窗口时的 Last-Modified E-Tag 操作&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Firefox 3.5&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;IE 8&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Chrome 3&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容自上次访问以来没有被修改&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容自上次访问以来已经被修改&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 8. 当用户在原始浏览器窗口中单击 Enter 按钮时的 Last-Modified E-Tag 操作&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Firefox 3.5&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;IE 8&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Chrome 3&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容自上次访问以来没有被修改&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容自上次访问以来已经被修改&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 9. 当用户按 F5 键刷新页面时的 Last-Modified E-Tag 操作&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Firefox 3.5&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;IE 8&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Chrome 3&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容自上次访问以来没有被修改&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 304&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容自上次访问以来已经被修改&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 10. 没有缓存设置且用户单击 Back 或 Forward 按钮&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Firefox 3.5&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;IE 8&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Chrome 3&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容自上次访问以来没有被修改&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;内容自上次访问以来已经被修改&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;注意：所有浏览器都假定使用默认设置运行。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;不进行任何缓存相关设置&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;如果您不定义任何缓存相关设置，则不同的浏览器有不同的行为。有时，同一个浏览器在相同的情形下每次运行时的行为都是不同的。情况可能很复杂。另外，有些不该缓存的内容如果被缓存，将会导致安全问题。&lt;br /&gt;不同的浏览器有不同的行为。表 11 展示了不同的浏览器行为。&lt;/div&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;表 11. 没有缓存设置且用户打开一个新的浏览器窗口&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Firefox 3.5&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;IE 8&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Chrome 3&lt;/th&gt;&lt;th style=&quot;background-image: none; border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 4px 10px 4px 5px; text-align: center; vertical-align: middle;&quot;&gt;Safari 4&lt;/th&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;打开一个新页面&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;在原始窗口中单击 Enter 按钮&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面。&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;按 F5 键刷新&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;单击 Back 或 Forward 按钮&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面。&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器呈现来自缓存的页面。&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;浏览器重新发送请求到服务器。返回代码是 200&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;注意：所有浏览器都假定使用默认设置运行。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin-bottom: 1.5em; padding: 0px; text-indent: 1em; vertical-align: baseline;&quot;&gt;最后, 概括下关键的结论:&lt;/div&gt;&lt;table style=&quot;background-color: white; border-collapse: collapse; border-spacing: 0px; border: 1px solid rgb(85, 85, 85); color: #222222; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 12px; line-height: 18px; margin: 10px 0px 1.4em; padding: 0px; vertical-align: middle; width: 629px;&quot;&gt;&lt;caption style=&quot;background-color: #eeeeee; border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; text-align: left; vertical-align: baseline;&quot;&gt;关键结论&lt;/caption&gt;&lt;tbody style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot; width=&quot;12%&quot;&gt;打开新窗口&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;如果指定cache-control的值为private、no-cache、must-revalidate,那么打开新窗口访问时都会重新访问服务器。而如果指定了max-age值,那么在此值内的时间里就不会重新访问服务器,例如：Cache-control: max-age=5 表示当访问此网页后的5秒内再次访问不会去服务器.&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;在地址栏回车&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;如果值为private或must-revalidate,则只有第一次访问时会访问服务器,以后就不再访问。如果值为no-cache,那么每次都会访问。如果值为max-age,则在过期之前不会重复访问。&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;按后退按扭&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;如果值为private、must-revalidate、max-age,则不会重访问,而如果为no-cache,则每次都重复访问.&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;border: 0px; font-family: inherit; font-style: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;按刷新按扭&lt;/td&gt;&lt;td style=&quot;border: 1px solid rgb(85, 85, 85); font-family: inherit; font-style: inherit; margin: 0px; padding: 1px; vertical-align: middle;&quot;&gt;无论为何值,都会重复访问.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/8324251700462171667/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/06/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/8324251700462171667'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/8324251700462171667'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/06/blog-post.html' title='浏览器缓存机制'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-2823527090319791091</id><published>2013-06-04T14:30:00.001+10:00</published><updated>2013-06-04T14:32:16.406+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>HTTP Performance</title><content type='html'>&lt;h2&gt;HTTP Performance: An Overview&lt;/h2&gt;It&#39;s no secret—users love fast Web sites. Users are notoriously impatient,     and unless your Web site has no competitive substitute, users are unlikely to     stick around if your site&#39;s performance doesn&#39;t measure up. If your site has     visitors from around the world, ensuring your site operates efficiently is even     more critical, as international network connections generally suffer from the     twin banes of snappy sites: high latency and low bandwidth.&lt;br /&gt;There are many options for improving your site&#39;s performance: compression,     caching, geographic load balancing, adding hardware, and so forth. Optimizing     the use of compression and caching is often the best place to start, as     configuration changes are generally free and can return dramatic benefits.   &lt;br /&gt;In this article, we&#39;ll use the Fiddler HTTP Debugger to explore HTTP     performance, caching, and compression.    &lt;br /&gt;&lt;h2&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; id=&quot;ie_introfiddler2_topic2&quot;&gt;&lt;/a&gt;Tweaking &quot;First Visit&quot; Performance&lt;/h2&gt;On their crucial first visit to your site, visitors must download every piece of     content used to generate the page, including JScript, CSS, images, and HTML. If     your page is too slow to load, visitors may leave your page before it&#39;s even     done downloading!&lt;br /&gt;By exposing all HTTP traffic, Fiddler readily shows which files are used to     generate a given page. Shift+click multiple entries in the HTTP Sessions list     to calculate the &quot;total page weight&quot;—the number of requests and the bytes     transferred.&lt;br /&gt;&lt;div class=&quot;fig&quot;&gt;&lt;img alt=&quot;Bb250442.ie_fiddlerhttp_fig01(en-us,VS.85).gif&quot; src=&quot;http://i.msdn.microsoft.com/dynimg/IC71347.gif&quot; id=&quot;ie_fiddlerhttp_fig01&quot; title=&quot;Bb250442.ie_fiddlerhttp_fig01(en-us,VS.85).gif&quot; xmlns=&quot;&quot; /&gt;&lt;/div&gt;&lt;div class=&quot;label&quot;&gt;&lt;strong&gt;Figure 1. Fiddler&#39;s Performance Statistics View&lt;/strong&gt;&lt;/div&gt;The best way to ensure a &quot;Wow, this is fast&quot; first impression is to deliver     fewer and smaller files.&lt;br /&gt;Tips for fast first-visits:   &lt;br /&gt;&lt;ul&gt;&lt;li&gt;    Use fewer graphics.&lt;/li&gt;&lt;li&gt;    Extract styles into a single CSS file.&lt;/li&gt;&lt;li&gt;    Extract script blocks into a single JS file.&lt;/li&gt;&lt;li&gt;    Simplify your page layout.&lt;/li&gt;&lt;li&gt;    Use HTTP Compression.&lt;/li&gt;&lt;/ul&gt;Once you&#39;ve tuned your site for a fast first visit, you can make it even faster     for return visitors by taking advantage of HTTP caching.&lt;br /&gt;&lt;h2&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; id=&quot;ie_introfiddler2_topic3&quot;&gt;&lt;/a&gt;Introduction to HTTP Caching&lt;/h2&gt;Two key factors in improving the speed of your Web applications are:   &lt;br /&gt;&lt;ul&gt;&lt;li&gt;    Reducing the number of request/response roundtrips.&lt;/li&gt;&lt;li&gt;    Reducing the number of bytes transferred between the server and the client.&lt;/li&gt;&lt;/ul&gt;HTTP caching is of the best ways to reduce roundtrips and bytes transferred.     Caching provides a mechanism for a client or proxy to store HTTP responses for     later use, so that requests need not cross the network.   &lt;br /&gt;Other than performance, another benefit of maximizing use of HTTP caching comes     from the fact that bandwidth isn&#39;t free. By tuning caching for a major     Microsoft site, we were able to reduce our outbound bandwidth costs by over     $10,000 &lt;em&gt;per month&lt;/em&gt;.&lt;br /&gt;&lt;h3&gt;Cache-Related Request Headers&lt;/h3&gt;To enhance performance, Microsoft Internet Explorer and other Web clients     maintain a local cache of resources downloaded from remote Web servers.   &lt;br /&gt;When a resource is needed by the client, there are three possible actions:   &lt;br /&gt;&lt;ul&gt;&lt;li&gt;    Send a plain HTTP request to the remote Web server asking for a resource&lt;/li&gt;&lt;li&gt;    Send a &lt;em&gt;conditional&lt;/em&gt;&lt;strong&gt; &lt;/strong&gt;HTTP request to the origin server asking for      the resource &lt;em&gt;only if it differs&lt;/em&gt; from the locally cached version&lt;/li&gt;&lt;li&gt;    Use a locally cached version of the resource, if a cached copy is available&lt;/li&gt;&lt;/ul&gt;When sending a request, the client may use one of the following headers:&lt;br /&gt;&lt;strong&gt;Table 1. Client Cache Headers&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;table id=&quot;Table3&quot;&gt;    &lt;tbody&gt;&lt;tr&gt;&lt;td&gt;&lt;code&gt;Pragma:&lt;/code&gt; &lt;em&gt;no-cache&lt;/em&gt;&lt;/td&gt;&lt;td&gt;The client is unwilling to accept any cached responses from caches        along the route and the origin server must be contacted for a fresh copy of the        resource.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code&gt;If-Modified-Since:&lt;/code&gt; &lt;em&gt;datetime&lt;/em&gt;&lt;/td&gt;&lt;td&gt;The server should return the requested resource only if the        resource has been modified since the date-time provided by the client.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;code&gt;If-None-Match:&lt;/code&gt; &lt;em&gt;etagvalue&lt;/em&gt;&lt;/td&gt;&lt;td&gt;The server should return the requested resource if the ETAG of the        resource is different than the value provided by the client. An &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19&quot;&gt;       ETAG&lt;/a&gt; is a unique identifier representing a particular version of a        file.      &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;A client indicates that it has a cached response available for use by sending a     &quot;Conditional request&quot; containing the headers &lt;strong&gt;If-Modified-Since&lt;/strong&gt; or &lt;strong&gt;If-None-Match&lt;/strong&gt;.     If the server replies to a conditional request with &lt;strong&gt;HTTP/304 Not Modified&lt;/strong&gt;,     the client is directed to reuse its cached response. Otherwise, the server     should return a new response and the client should discard its outdated cache     item.&lt;br /&gt;Observe two consecutive requests for an image file in the following code     sessions. In the first session, no locally cached version of the file is     present, so the server returns the file along with an &lt;strong&gt;ETAG&lt;/strong&gt; value and the     date-time of the last modification of the file. In the subsequent session, a     locally cached version of the file is now available, so a conditional request     is made, passing up the &lt;strong&gt;ETAG&lt;/strong&gt; of the cached response as well as the &lt;strong&gt;Last-Modified&lt;/strong&gt;   time of the original request. Since the image has not changed since the cached     version (either because the &lt;strong&gt;ETAG&lt;/strong&gt; matches or the &lt;strong&gt;If-Modified-Since&lt;/strong&gt;     value matches the &lt;strong&gt;Last-Modified&lt;/strong&gt; value) the server returns a 304 to the     client to direct it to use the cached response.&lt;br /&gt;&lt;strong&gt;Session #1&lt;/strong&gt;&lt;br /&gt;&lt;pre&gt;GET /images/banner.jpg HTTP/1.1&lt;br /&gt;Host: www.bayden.com&lt;br /&gt;&lt;br /&gt;HTTP/1.1 200 OK&lt;br /&gt;Date: Tue, 08 Mar 2006 00:32:46 GMT&lt;br /&gt;Content-Length: 6171&lt;br /&gt;Content-Type: image/jpeg&lt;br /&gt;&lt;strong&gt;ETag: &quot;40c7f76e8d30c31:2fe20&quot;&lt;br /&gt;Last-Modified: Thu, 12 Jun 2003 02:50:50 GMT&lt;/strong&gt;&lt;br /&gt;&lt;/pre&gt;&lt;strong&gt;Session #2&lt;/strong&gt;&lt;br /&gt;&lt;pre&gt;GET /images/banner.jpg HTTP/1.1&lt;br /&gt;If-Modified-Since: Thu, 12 Jun 2003 02:50:50 GMT&lt;br /&gt;If-None-Match: &quot;40c7f76e8d30c31:2fe20&quot;&lt;br /&gt;Host: www.bayden.com&lt;br /&gt;&lt;br /&gt;HTTP/1.1 304 Not Modified&lt;br /&gt;&lt;/pre&gt;Because an &lt;strong&gt;HTTP/304&lt;/strong&gt; response contains only headers and no body, it     crosses the network much more quickly than if the full resource had been     re-downloaded. However, even an &lt;strong&gt;HTTP/304&lt;/strong&gt; requires a full roundtrip to     the remote Web server; by carefully setting response headers, a Web application     developer can eliminate the need to issue even conditional requests.   &lt;br /&gt;&lt;h3&gt;Cache-Related Response Headers&lt;/h3&gt;Generally, the cacheability of an HTTP response is controlled by headers sent in     the response. The &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html&quot;&gt;HTTP      specification&lt;/a&gt; describes the headers that control caching. The optional &lt;strong&gt;Cache-Control&lt;/strong&gt;   and &lt;strong&gt;Expires&lt;/strong&gt; headers are the primary mechanisms for a Web server to     indicate to a proxy or a client how content may be cached.   &lt;br /&gt;The &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.21&quot;&gt;Expires&lt;/a&gt;   header contains an absolute date-time after which a cached copy of a response     should no longer be considered &lt;em&gt;fresh&lt;/em&gt;. If the &lt;strong&gt;Expires&lt;/strong&gt; header     contains something other than a date (&lt;strong&gt;0&lt;/strong&gt; or &lt;strong&gt;-1&lt;/strong&gt; are common values),     the response should immediately be treated as &lt;em&gt;stale&lt;/em&gt;. A &lt;em&gt;fresh&lt;/em&gt; cache     entry may be reused without contacting the server again; a &lt;em&gt;stale &lt;/em&gt;cache     entry should not be reused without first contacting the Web server to ensure     that it is still up-to-date.&lt;br /&gt;For example, let&#39;s look at the previous example, except we&#39;ll add an &lt;strong&gt;Expires&lt;/strong&gt;   header to the first response:&lt;br /&gt;&lt;strong&gt;Session #1&lt;/strong&gt;&lt;br /&gt;&lt;pre&gt;GET /images/banner.jpg HTTP/1.1&lt;br /&gt;Host: www.bayden.com&lt;br /&gt;&lt;br /&gt;HTTP/1.1 200 OK&lt;br /&gt;Date: Tue, 08 Mar 2006 00:32:46 GMT&lt;br /&gt;Content-Length: 6171&lt;br /&gt;Content-Type: image/jpeg&lt;br /&gt;Expires: Tue, 12 Jun 2007 02:50:50 GMT&lt;br /&gt;Last-Modified: Thu, 12 Jun 2003 02:50:50 GMT&lt;br /&gt;&lt;/pre&gt;&lt;strong&gt;Session #2&lt;/strong&gt;&lt;br /&gt;&lt;pre&gt;&lt;no automatically=&quot;&quot; cached=&quot;&quot; http=&quot;&quot; is=&quot;&quot; made=&quot;&quot; request=&quot;&quot; used=&quot;&quot; version=&quot;&quot;&gt;&lt;br /&gt;&lt;/no&gt;&lt;/pre&gt;As you can see, we&#39;ve improved performance by adding an &lt;strong&gt;Expires&lt;/strong&gt; header,     since no conditional HTTP request is made during Session #2.&lt;br /&gt;Similarly, the &lt;strong&gt;Cache-Control&lt;/strong&gt; header contains a list of tokens that     control caching. Any &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9&quot;&gt;    Cache-Control&lt;/a&gt; directives supersede the &lt;strong&gt;Expires&lt;/strong&gt; header.&lt;br /&gt;Commonly used &lt;strong&gt;Cache-Control&lt;/strong&gt; tokens include those found in table 2.&lt;br /&gt;&lt;strong&gt;Table 2. Common Cache-Control Headers&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;table id=&quot;Table4&quot;&gt;    &lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Value&lt;/th&gt;&lt;th&gt;Meaning&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;public&lt;/td&gt;&lt;td&gt;The response may be stored in any cache, including caches shared        among many users.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;private&lt;/td&gt;&lt;td&gt;The response may only be stored in a private cache used by a single        user.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;no-cache&lt;/td&gt;&lt;td&gt;The response should not be reused to satisfy future requests.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;no-store&lt;/td&gt;&lt;td&gt;The response should not be reused to satisfy future requests, and        should not be written to disk. This is primarily used as a security measure for        sensitive responses.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;max-age=&lt;em&gt;#seconds&lt;/em&gt;&lt;/td&gt;&lt;td&gt;The response may be reused to satisfy future requests within a        certain number of seconds.&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;must-revalidate&lt;/td&gt;&lt;td&gt;The response may be reused to satisfy future requests, but the        origin server should first be contacted to verify that the response is still        fresh.&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;strong&gt;Notes&lt;/strong&gt;  &lt;br /&gt;&lt;ul&gt;&lt;li&gt;    You can learn more about how to configure caching for IIS from the Microsoft      Knowledge Base article &lt;a href=&quot;http://support.microsoft.com/default.aspx?scid=kb;en-us;247404&quot;&gt;     How to Modify the Cache-Control HTTP Header When You Use IIS&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;    You can learn more about how to configure caching for ASP.NET pages the      Microsoft Knowledge Base article &lt;a href=&quot;http://support.microsoft.com/default.aspx?scid=kb;en-us;323290&quot;&gt;     How To Cache in ASP.NET by Using Visual C# .NET&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;    If you find that you often update files on your Web site without changing the      filenames, take care to set appropriate cache lifetimes. For instance, if you      want &lt;strong&gt;thisyear.gif&lt;/strong&gt; to show the current year on your site, you need to      make sure the caching directives don&#39;t call for an expiration longer than 1      day, or else a user visiting on December 31&lt;span class=&quot;sup&quot;&gt;st&lt;/span&gt; won&#39;t see the right      image when they go back on January 1&lt;span class=&quot;sup&quot;&gt;st&lt;/span&gt;!&lt;/li&gt;&lt;li&gt;    For legacy reasons, servers may send a &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.32&quot;&gt;     Pragma: no-cache&lt;/a&gt; header. This is treated as &lt;strong&gt;Cache-Control: no-cache&lt;/strong&gt;.    &lt;/li&gt;&lt;li&gt;    The &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.44&quot;&gt;Vary&lt;/a&gt;    header signals to a cache that a response is valid for reuse only under certain      circumstances. For example, use&lt;code&gt; &lt;/code&gt;&lt;strong&gt;Vary: User-Agent&lt;/strong&gt; to direct      that the current response may only be reused for future requests sending the      same &lt;strong&gt;User-Agent&lt;/strong&gt; header. The directive &lt;strong&gt;Vary: *&lt;/strong&gt; is equivalent to &lt;strong&gt;Cache-Control:       no-cache&lt;/strong&gt;.&lt;/li&gt;&lt;/ul&gt;Using the HTTP Sessions list, Fiddler users can see whether pages contain HTTP     Caching headers.   &lt;br /&gt;&lt;img alt=&quot;Bb250442.ie_fiddlerhttp_fig02(en-us,VS.85).gif&quot; src=&quot;http://i.msdn.microsoft.com/dynimg/IC143220.gif&quot; id=&quot;ie_fiddlerhttp_fig02&quot; title=&quot;Bb250442.ie_fiddlerhttp_fig02(en-us,VS.85).gif&quot; xmlns=&quot;&quot; /&gt;&lt;br /&gt;&lt;strong&gt;Figure 2. Fiddler Sessions List&lt;/strong&gt;&lt;br /&gt;If a response does not contain &lt;strong&gt;Expires&lt;/strong&gt; or &lt;strong&gt;Cache-Control&lt;/strong&gt; headers,     the client may be forced to issue a conditional request to ensure that the     resource is still fresh.&lt;br /&gt;&lt;h2&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; id=&quot;ie_introfiddler2_topic4&quot;&gt;&lt;/a&gt;Conditional Requests and the WinInet     Cache&lt;/h2&gt;Internet Explorer takes advantage of the caching services provided by Microsoft     Windows Internet Services (WinInet).   &lt;br /&gt;WinInet allows the user to configure the size and behavior of the cache. To     access the cache settings:   &lt;br /&gt;&lt;ol&gt;&lt;li&gt;    Open Internet Explorer.&lt;/li&gt;&lt;li&gt;    On the &lt;strong&gt;Tools&lt;/strong&gt; menu, choose &lt;strong&gt;Internet Options&lt;/strong&gt;.&lt;/li&gt;&lt;li&gt;    On the &lt;strong&gt;General&lt;/strong&gt; tab, in the &lt;strong&gt;Temporary Internet Files box&lt;/strong&gt;, click &lt;strong&gt;Settings&lt;/strong&gt;.&lt;/li&gt;&lt;/ol&gt;At the top of the &lt;strong&gt;Settings&lt;/strong&gt; dialog box, there are four choices.&lt;br /&gt;&lt;img alt=&quot;Bb250442.ie_fiddlerhttp_fig03(en-us,VS.85).gif&quot; src=&quot;http://i.msdn.microsoft.com/dynimg/IC53327.gif&quot; id=&quot;ie_fiddlerhttp_fig03&quot; title=&quot;Bb250442.ie_fiddlerhttp_fig03(en-us,VS.85).gif&quot; xmlns=&quot;&quot; /&gt;&lt;br /&gt;&lt;strong&gt;Figure 3. Internet Explorer Cache Options&lt;/strong&gt;&lt;br /&gt;The vast majority of users leave the setting at the default of &lt;strong&gt;Automatically&lt;/strong&gt;.&lt;br /&gt;The most important fact to keep in mind is that these four options mostly impact     the behavior when there are no caching headers on the HTTP responses; when     caching headers are present, Internet Explorer will always respect them. The     following table describes the impact of these settings on request behavior.&lt;br /&gt;&lt;strong&gt;Table 3. Cache behaviors&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;table id=&quot;Table5&quot;&gt;    &lt;tbody&gt;&lt;tr&gt;&lt;th&gt;Setting&lt;/th&gt;&lt;th&gt;Cache copy is fresh&lt;/th&gt;&lt;th&gt;Cache stale&lt;/th&gt;&lt;th&gt;No cache-directives were present&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Every visit to the page&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;No request&lt;/td&gt;&lt;td&gt;Conditional request&lt;/td&gt;&lt;td&gt;Conditional request&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Every time you start Internet Explorer&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;No request&lt;/td&gt;&lt;td&gt;Conditional request&lt;/td&gt;&lt;td&gt;Conditional request&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Automatically&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;No request&lt;/td&gt;&lt;td&gt;Conditional request&lt;/td&gt;&lt;td&gt;Heuristic (see below)&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Never&lt;/strong&gt;&lt;/td&gt;&lt;td&gt;No request&lt;/td&gt;&lt;td&gt;Conditional request&lt;/td&gt;&lt;td&gt;No request&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;Cached content is considered &lt;strong&gt;fresh&lt;/strong&gt; if the request is made during the     freshness lifetime specified by the &lt;strong&gt;Cache-Control&lt;/strong&gt; or &lt;strong&gt;Expires&lt;/strong&gt; headers     on the original response. Cached content is considered &lt;strong&gt;stale&lt;/strong&gt; if the     request is made after the end of the freshness lifetime specified.&lt;br /&gt;The &lt;strong&gt;Automatically&lt;/strong&gt; setting bears some explanation—how can WinInet     know if the cached resource is fresh when no caching directives were provided     on the server&#39;s HTTP response?   &lt;br /&gt;The answer is that WinInet can&#39;t know for sure and a Heuristic process is     followed to make a &quot;best guess&quot; effort. In the &lt;strong&gt;Automatically&lt;/strong&gt; state, the     Heuristic will issue a conditional request unless all of the following criteria     are met:   &lt;br /&gt;&lt;ul&gt;&lt;li&gt;    The cached resource bears a &lt;strong&gt;Content-Type&lt;/strong&gt;&lt;code&gt; &lt;/code&gt;that begins with &lt;strong&gt;image/&lt;/strong&gt;.&lt;/li&gt;&lt;li&gt;    The cached resource has a &lt;strong&gt;Last-Modified&lt;/strong&gt;&lt;code&gt; &lt;/code&gt;time.&lt;/li&gt;&lt;li&gt;    The URL to the cached resource does not contain a question mark (hinting that      it&#39;s a CGI request).&lt;/li&gt;&lt;li&gt;    The cached resource has been conditionally requested at least once within the      most recent 25 percent of its overall age in the cache.&lt;/li&gt;&lt;/ul&gt;If all of the criteria above are met, no request is made.   &lt;br /&gt;As a Web developer, you should always ensure that you send appropriate caching     headers to guarantee you get optimum cache behaviors.   &lt;br /&gt;&lt;h3&gt;Flagging Performance Problems&lt;/h3&gt;You can use Fiddler&#39;s Custom Rules to draw attention to potential performance     problems. For instance, you can flag any response larger than 25KB.   &lt;br /&gt;To add this rule, click &lt;strong&gt;Rules&lt;/strong&gt; and then &lt;strong&gt;Custom Rules&lt;/strong&gt;, and add the     following code inside the &lt;strong&gt;OnBeforeResponse &lt;/strong&gt;event handler:&lt;br /&gt;&lt;pre&gt;// Flag files over 25KB&lt;br /&gt;   if (oSession.responseBodyBytes.length &amp;gt; 25000){&lt;br /&gt;      oSession[&quot;ui-color&quot;] = &quot;red&quot;;&lt;br /&gt;      oSession[&quot;ui-bold&quot;] = &quot;true&quot;;&lt;br /&gt;      oSession[&quot;ui-customcolumn&quot;] = &quot;Large file&quot;;&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;Similarly, you can flag responses that do not specify caching information:&lt;br /&gt;&lt;pre&gt;   // Mark files which do not have caching information&lt;br /&gt;if (!oSession.oResponse.headers.Exists(&quot;Expires&quot;) &amp;amp;&amp;amp;&lt;br /&gt;!oSession.oResponse.headers.Exists(&quot;Cache-Control&quot;)){&lt;br /&gt;      &lt;br /&gt;oSession[&quot;ui-color&quot;] = &quot;purple&quot;;&lt;br /&gt;      oSession[&quot;ui-bold&quot;] = &quot;true&quot;;&lt;br /&gt;   }&lt;br /&gt;&lt;/pre&gt;&lt;h2&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; id=&quot;ie_introfiddler2_topic5&quot;&gt;&lt;/a&gt;Introduction to HTTP Compression&lt;/h2&gt;All popular Web servers and browsers offer support for HTTP Compression. HTTP     Compression can dramatically decrease the number of bytes that are transmitted     between the server and the client; savings of over 50 percent for HTML, XML,     CSS, and JS are common.&lt;br /&gt;A Web browser signals to the server that it is willing to accept HTTP compressed     content by listing the supported compression types in the request headers. For     instance, consider the following request to the new &lt;a href=&quot;http://search.msn.com/&quot;&gt;    MSN Search&lt;/a&gt; homepage:&lt;br /&gt;&lt;pre&gt;GET / HTTP/1.1&lt;br /&gt;Accept: */*&lt;br /&gt;Accept-Language: en-us&lt;br /&gt;&lt;strong&gt;Accept-Encoding: gzip, deflate&lt;/strong&gt;&lt;br /&gt;User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)&lt;br /&gt;Host: search.msn.com&lt;br /&gt;&lt;/pre&gt;The &lt;strong&gt;Accept-Encoding &lt;/strong&gt;header indicates Internet Explorer is willing to     accept responses that have been compressed using either the GZIP or DEFLATE     formats.&lt;br /&gt;The MSN Search server obligingly returns the compressed contents; the &lt;strong&gt;Content-Encoding&lt;/strong&gt;   response header indicates the GZIP format was used:&lt;br /&gt;&lt;pre&gt;HTTP/1.1 200 OK&lt;br /&gt;Content-Type: text/html; charset=utf-8&lt;br /&gt;Server: Microsoft-IIS/6.0 --Microsoft-HTTPAPI/1.0&lt;br /&gt;X-Powered-By: ASP.NET&lt;br /&gt;Vary: Accept-Encoding&lt;br /&gt;&lt;strong&gt;Content-Encoding: gzip&lt;br /&gt;&lt;/strong&gt;Date: Tue, 15 Feb 2006 09:14:36 GMT&lt;br /&gt;Content-Length: 1277&lt;br /&gt;Connection: close&lt;br /&gt;Cache-Control: private, max-age=3600&lt;br /&gt;&lt;/pre&gt;Using Fiddler, you can decompress the response using the Transformer tool on the     Session Inspector tab.&lt;br /&gt;&lt;img alt=&quot;Bb250442.ie_fiddlerhttp_fig04(en-us,VS.85).gif&quot; src=&quot;http://i.msdn.microsoft.com/dynimg/IC118910.gif&quot; id=&quot;ie_fiddlerhttp_fig04&quot; title=&quot;Bb250442.ie_fiddlerhttp_fig04(en-us,VS.85).gif&quot; xmlns=&quot;&quot; /&gt;&lt;br /&gt;&lt;strong&gt;Figure 4. Transformer Inspector before decompressing GZIP&#39;d response&lt;/strong&gt;&lt;br /&gt;Click the &lt;strong&gt;No Compression&lt;/strong&gt; radio button to decompress the response inside     Fiddler. Compression reduced the number of bytes transferred by over 57     percent.&lt;br /&gt;&lt;img alt=&quot;Bb250442.ie_fiddlerhttp_fig05(en-us,VS.85).gif&quot; src=&quot;http://i.msdn.microsoft.com/dynimg/IC170794.gif&quot; id=&quot;ie_fiddlerhttp_fig05&quot; title=&quot;Bb250442.ie_fiddlerhttp_fig05(en-us,VS.85).gif&quot; xmlns=&quot;&quot; /&gt;&lt;br /&gt;&lt;strong&gt;Figure 5. Transformer Inspector after decompressing response&lt;/strong&gt;&lt;br /&gt;The savings are more dramatic for the &lt;strong&gt;common.css&lt;/strong&gt; file used by the MSN     Search homepage; the CSS file was compressed 81 percent (from 25,288 bytes to     4,648 bytes). Note that image files like GIFs, JPEGs, and PNGs generally are     already compressed and thus usually are not delivered with HTTP compression.   &lt;br /&gt;You can use Fiddler to simulate HTTP compression by checking &quot;Simulate GZIP     Compression&quot; on the Fiddler Rules menu.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; id=&quot;ie_introfiddler2_topic6&quot;&gt;&lt;/a&gt;&lt;/h2&gt;&lt;br /&gt;Enabling compression for static files in IIS has a minimal CPU impact on IIS Web     servers, because the files are compressed only the first time and then cached     on the server. Enabling compression for dynamic files like ASP.NET pages may     impact your servers&#39; CPU performance; you&#39;ll want to evaluate this performance     impact before enabling dynamic compression on production Web servers.</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/2823527090319791091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/06/http-performance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/2823527090319791091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/2823527090319791091'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/06/http-performance.html' title='HTTP Performance'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-4477720484522197883</id><published>2013-05-21T09:26:00.003+10:00</published><updated>2013-05-21T09:33:46.367+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>xStream完美转换XML、JSON</title><content type='html'>&lt;br /&gt;&lt;b&gt;xStream&lt;/b&gt;&lt;b&gt;框架&lt;/b&gt;&lt;b&gt;&lt;/b&gt;  &lt;br /&gt;xStream可以轻易的将Java对象和xml文档相互转换，而且可以修改某个特定的属性和节点名称，而且也支持json的转换；  &lt;br /&gt;前面有介绍过json-lib这个框架，在线博文：&lt;a href=&quot;http://www.cnblogs.com/hoojo/archive/2011/04/21/2023805.html&quot;&gt;http://www.cnblogs.com/hoojo/archive/2011/04/21/2023805.html&lt;/a&gt;  &lt;br /&gt;以及Jackson这个框架，在线博文：&lt;a href=&quot;http://www.cnblogs.com/hoojo/archive/2011/04/22/2024628.html&quot;&gt;http://www.cnblogs.com/hoojo/archive/2011/04/22/2024628.html&lt;/a&gt;  &lt;br /&gt;它 们都完美支持JSON，但是对xml的支持还不是很好。一定程度上限制了对Java对象的描述，不能让xml完全体现到对Java对象的描述。这里将会介 绍xStream对JSON、XML的完美支持。xStream不仅对XML的转换非常友好，而且提供annotation注解，可以在JavaBean 中完成对xml节点、属性的描述。以及对JSON也支持，只需要提供相关的JSONDriver就可以完成转换。  &lt;br /&gt;&lt;b&gt;一、&lt;/b&gt;&lt;b&gt;准备工作&lt;/b&gt;&lt;b&gt;&lt;/b&gt;  &lt;br /&gt;1、 下载jar包、及官方资源  &lt;br /&gt;xStream的jar下载地址：  &lt;br /&gt;&lt;a href=&quot;https://nexus.codehaus.org/content/repositories/releases/com/thoughtworks/xstream/xstream-distribution/1.3.1/xstream-distribution-1.3.1-bin.zip&quot;&gt;https://nexus.codehaus.org/content/repositories/releases/com/thoughtworks/xstream/xstream-distribution/1.3.1/xstream-distribution-1.3.1-bin.zip&lt;/a&gt;  &lt;br /&gt;官方的示例很全，官方参考示例：&lt;a href=&quot;http://xstream.codehaus.org/tutorial.html&quot;&gt;http://xstream.codehaus.org/tutorial.html&lt;/a&gt;  &lt;br /&gt;添加xstream-1.3.1.jar文件到工程中，就可以开始下面的工作；需要的jar如下：  &lt;br /&gt;&lt;a href=&quot;http://images.cnblogs.com/cnblogs_com/hoojo/201104/201104221846024160.jpg&quot;&gt;&lt;img alt=&quot;clip_image002&quot; border=&quot;0&quot; src=&quot;http://images.cnblogs.com/cnblogs_com/hoojo/201104/20110422184606416.jpg&quot; height=&quot;77&quot; style=&quot;border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;&quot; title=&quot;clip_image002&quot; width=&quot;143&quot; /&gt;&lt;/a&gt;  &lt;br /&gt;2、 测试用例代码  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;package&lt;/span&gt; com.hoo.test;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.io.IOException;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.io.ObjectInputStream;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.io.ObjectOutputStream;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.io.StringReader;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.io.Writer;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.ArrayList;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.HashMap;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.Iterator;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.List;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.Map;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.Set;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; org.codehaus.jettison.json.JSONException;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; org.junit.After;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; org.junit.Before;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; org.junit.Test;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.hoo.entity.Birthday;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.hoo.entity.Classes;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.hoo.entity.ListBean;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.hoo.entity.Student;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.XStream;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.io.HierarchicalStreamWriter;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.io.json.JsonWriter;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;Java对象和XML字符串的相互转换&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * jar-lib-version: xstream-1.3.1&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 12:15:15 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @file XStreamTest.java&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @package com.hoo.test&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @project WebHttpUtils&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @blog http://blog.csdn.net/IBM_hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @email hoojo_@126.com&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @version 1.0&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@SuppressWarnings(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;unchecked&quot;&lt;/span&gt;)&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; XStreamTest {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; XStream xstream = null;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; ObjectOutputStream  out = null;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; ObjectInputStream in = null;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; Student bean = null;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     * &lt;b&gt;function:&lt;/b&gt;初始化资源准备&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     * @createDate Nov 27, 2010 12:16:28 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    @Before&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; init() {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            xstream = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; XStream();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: green;&quot;&gt;//xstream = new XStream(new DomDriver()); // 需要xpp3 jar&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        } &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (Exception e) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            e.printStackTrace();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setAddress(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setEmail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack@email.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setId(1);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Birthday day = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Birthday();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        day.setBirthday(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setBirthday(day);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     * &lt;b&gt;function:&lt;/b&gt;释放对象资源&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     * @createDate Nov 27, 2010 12:16:38 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    @After&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; destory() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream = null;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean = null;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (out != null) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;                out.flush();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;                out.close();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (in != null) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;                in.close();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        } &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (IOException e) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            e.printStackTrace();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        System.gc();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; fail(String string) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        System.out.println(string);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;final&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; failRed(String string) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        System.err.println(string);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;通过XStream对象的toXML方法就可以完成Java对象到XML的转换，toXML方法还有2个相同签名的方法，需要传递一个流。然后通过流来完成xml信息的输出。  &lt;br /&gt;3、 需要的JavaBean  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;package&lt;/span&gt; com.hoo.entity;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; Student {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; id;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; String name;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; String email;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; String address;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; Birthday birthday;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//getter、setter&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; String toString() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.name + &lt;span style=&quot;color: #006080;&quot;&gt;&quot;#&quot;&lt;/span&gt; + &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.id + &lt;span style=&quot;color: #006080;&quot;&gt;&quot;#&quot;&lt;/span&gt; + &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.address + &lt;span style=&quot;color: #006080;&quot;&gt;&quot;#&quot;&lt;/span&gt; + &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.birthday + &lt;span style=&quot;color: #006080;&quot;&gt;&quot;#&quot;&lt;/span&gt; + &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.email;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;b&gt;&lt;/b&gt; &lt;b&gt;二、&lt;/b&gt;&lt;b&gt;Java&lt;/b&gt;&lt;b&gt;转换成&lt;/b&gt;&lt;b&gt;XML&lt;/b&gt;  &lt;br /&gt;1、 JavaBean转换XM  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;Java对象转换成XML字符串&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 12:19:01 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; writeBean2XML() {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;------------Bean-&amp;gt;XML------------&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(xstream.toXML(bean));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;重命名后的XML&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//类重命名&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//xstream.alias(&quot;account&quot;, Student.class);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//xstream.alias(&quot;生日&quot;, Birthday.class);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//xstream.aliasField(&quot;生日&quot;, Student.class, &quot;birthday&quot;);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//xstream.aliasField(&quot;生日&quot;, Birthday.class, &quot;birthday&quot;);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//fail(xstream.toXML(bean));&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//属性重命名&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.aliasField(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;邮件&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;, &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//包重命名&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.aliasPackage(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;hoo&quot;&lt;/span&gt;, &lt;span style=&quot;color: #006080;&quot;&gt;&quot;com.hoo.entity&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(xstream.toXML(bean));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    } &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (Exception e) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        e.printStackTrace();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;看结果中的第一份xml内容，是没有经过然后修改或重命名的文档，按照原样输出。文档中的第二份文档的package经过重命名，email属性也经过重命名以及类名也可以进行重命名的。  &lt;br /&gt;运行后结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;------------Bean-&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;XML------------&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;com&lt;span style=&quot;color: #cc6633;&quot;&gt;.hoo&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.entity&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.Student&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;1&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack@email&lt;span style=&quot;color: #cc6633;&quot;&gt;.com&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;china&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;2010-11-22&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/com&lt;span style=&quot;color: #cc6633;&quot;&gt;.hoo&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.entity&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.Student&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;重命名后的XML&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;hoo&lt;span style=&quot;color: #cc6633;&quot;&gt;.Student&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;1&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;邮件&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack@email&lt;span style=&quot;color: #cc6633;&quot;&gt;.com&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/邮件&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;china&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;2010-11-22&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/hoo&lt;span style=&quot;color: #cc6633;&quot;&gt;.Student&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;2、 将List集合转换成xml文档  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;将Java的List集合转换成XML对象&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 12:20:07 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; writeList2XML() {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//修改元素名称&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;beans&quot;&lt;/span&gt;, ListBean.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;----------List--&amp;gt;XML----------&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        ListBean listBean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ListBean();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        listBean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;this is a List Collection&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        List&lt;object&gt; list = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ArrayList&lt;object&gt;();&lt;/object&gt;&lt;/object&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        list.add(bean);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        list.add(bean);&lt;span style=&quot;color: green;&quot;&gt;//引用bean&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//list.add(listBean);//引用listBean，父元素&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setAddress(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setEmail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setId(2);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Birthday day = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Birthday(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setBirthday(day);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        list.add(bean);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        listBean.setList(list);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//将ListBean中的集合设置空元素，即不显示集合元素标签&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//xstream.addImplicitCollection(ListBean.class, &quot;list&quot;);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//设置reference模型&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//xstream.setMode(XStream.NO_REFERENCES);//不引用&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.setMode(XStream.ID_REFERENCES);&lt;span style=&quot;color: green;&quot;&gt;//id引用&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//xstream.setMode(XStream.XPATH_ABSOLUTE_REFERENCES);//绝对路径引用&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;          &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//将name设置为父类（Student）的元素的属性&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.useAttributeFor(Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;, &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.useAttributeFor(Birthday.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;, &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//修改属性的name&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.aliasAttribute(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;姓名&quot;&lt;/span&gt;, &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.aliasField(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;生日&quot;&lt;/span&gt;, Birthday.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;, &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(xstream.toXML(listBean));&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    } &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (Exception e) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        e.printStackTrace();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;上面的代码运行后，结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;----------List--&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;XML----------&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;beans id=&quot;1&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;this is a List Collection&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;list id=&quot;2&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;student id=&quot;3&quot; 姓名=&quot;jack&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;1&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack@email&lt;span style=&quot;color: #cc6633;&quot;&gt;.com&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;china&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday id=&quot;4&quot; 生日=&quot;2010-11-22&quot;/&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/student&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;student reference=&quot;3&quot;/&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;student id=&quot;5&quot; 姓名=&quot;tom&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;2&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;tom@125&lt;span style=&quot;color: #cc6633;&quot;&gt;.com&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;china&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday id=&quot;6&quot; 生日=&quot;2010-11-22&quot;/&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/student&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/list&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/beans&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;如果不加xstream.addImplicitCollection(ListBean.&lt;b&gt;class&lt;/b&gt;, &quot;list&quot;);  &lt;br /&gt;这个设置的话，会出现一个List节点包裹着Student节点元素。添加addImplicitCollection可以忽略这个list节点元素。那么上面的list节点就不存在，只会在beans元素中出现name、student这2个xml元素标签；  &lt;br /&gt;setMode是设置相同的对象的引用方式，如果设置XStream.NO_REFERENCES就是不引用，会输出2分相同的 Student元素。如果是XStream.ID_REFERENCES会引用相同的那个对象的id属性，如果是 XStream.XPATH_ABSOLUTE_REFERENCES引用，那么它将显示xpath路径。上面采用的id引用，&lt;student reference=&quot;3&quot;&gt;这个引用了id=3的那个student标签元素；  &lt;/student&gt;&lt;br /&gt;useAttributeFor是设置某个节点显示到父节点的属性中，也就是将指定class中的指定属性，在这个class元素节点的属性中显示。  &lt;br /&gt;如：&lt;student&gt;&lt;name&gt;hoojo&lt;/name&gt;&lt;/student&gt;  &lt;br /&gt;设置好后就是这样的结果：&lt;student name=&quot;”hoojo”&quot;&gt;&lt;/student&gt;  &lt;br /&gt;aliasAttribute是修改属性名称。  &lt;br /&gt;3、 在JavaBean中添加Annotation注解进行重命名设置  &lt;br /&gt;先看看JavaBean的代码  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;package&lt;/span&gt; com.hoo.entity;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.Arrays;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.Calendar;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.GregorianCalendar;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.List;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.annotations.XStreamAlias;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.annotations.XStreamAsAttribute;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.annotations.XStreamConverter;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.annotations.XStreamImplicit;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.annotations.XStreamOmitField;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@XStreamAlias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;class&quot;&lt;/span&gt;)&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; Classes {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;/*&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     * 设置属性显示&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    @XStreamAsAttribute&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    @XStreamAlias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;名称&quot;&lt;/span&gt;)&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; String name;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;/*&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     * 忽略&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;     */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    @XStreamOmitField&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;int&lt;/span&gt; number;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    @XStreamImplicit(itemFieldName = &lt;span style=&quot;color: #006080;&quot;&gt;&quot;Students&quot;&lt;/span&gt;)&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; List&lt;student&gt; students;&lt;/student&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    @SuppressWarnings(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;unused&quot;&lt;/span&gt;)&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    @XStreamConverter(SingleValueCalendarConverter.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;)&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; Calendar created = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; GregorianCalendar();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Classes(){}&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Classes(String name, Student... stu) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.name = name;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.students = Arrays.asList(stu);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//getter、setter&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;SingleValueCalendarConverter.java这个是一个类型转换器  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;package&lt;/span&gt; com.hoo.entity;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.Calendar;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.Date;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; java.util.GregorianCalendar;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.converters.Converter;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.converters.MarshallingContext;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.converters.UnmarshallingContext;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.io.HierarchicalStreamReader;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;import&lt;/span&gt; com.thoughtworks.xstream.io.HierarchicalStreamWriter;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; SingleValueCalendarConverter &lt;span style=&quot;color: blue;&quot;&gt;implements&lt;/span&gt; Converter {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;     &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; marshal(Object source, HierarchicalStreamWriter writer,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;                MarshallingContext context) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            Calendar calendar = (Calendar) source;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            writer.setValue(String.valueOf(calendar.getTime().getTime()));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; Object unmarshal(HierarchicalStreamReader reader,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;                UnmarshallingContext context) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            GregorianCalendar calendar = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; GregorianCalendar();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            calendar.setTime(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Date(Long.parseLong(reader.getValue())));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; calendar;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        @SuppressWarnings(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;unchecked&quot;&lt;/span&gt;)&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;boolean&lt;/span&gt; canConvert(Class type) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; type.equals(GregorianCalendar.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;再看看测试用例代码  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; writeList2XML4Annotation() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;---------annotation Bean --&amp;gt; XML---------&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Student stu = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        stu.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Classes c = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Classes(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;一班&quot;&lt;/span&gt;, bean, stu);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        c.setNumber(2);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//对指定的类使用Annotation&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//xstream.processAnnotations(Classes.class);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//启用Annotation&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: green;&quot;&gt;//xstream.autodetectAnnotations(true);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(xstream.toXML(c));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    } &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (Exception e) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        e.printStackTrace();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;当启用annotation或是对某个特定的类启用annotation时，上面的classes这个类才有效果。如果不启用annotation，运行后结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;---------annotation Bean --&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt; XML---------&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;com&lt;span style=&quot;color: #cc6633;&quot;&gt;.hoo&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.entity&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.Classes&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;一班&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;number&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;2&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/number&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;students class=&quot;java&lt;span style=&quot;color: #cc6633;&quot;&gt;.util&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.Arrays&lt;/span&gt;$ArrayList&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;a class=&quot;student-array&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;student&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;1&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack@email&lt;span style=&quot;color: #cc6633;&quot;&gt;.com&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;china&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;          &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;2010-11-22&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/student&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;student&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;0&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/student&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/a&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/students&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;created&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;time&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;1303292056718&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/time&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;timezone&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;Asia/Shanghai&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/timezone&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/created&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/com&lt;span style=&quot;color: #cc6633;&quot;&gt;.hoo&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.entity&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.Classes&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;当启用annotation后xstream.processAnnotations(Classes.class)，结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;---------annotation Bean --&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt; XML---------&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;class 名称=&quot;一班&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;Students&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;1&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack@email&lt;span style=&quot;color: #cc6633;&quot;&gt;.com&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;china&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;2010-11-22&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/Students&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;Students&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;0&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/Students&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;created&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;1303292242937&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/created&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/class&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;4、 Map集合转换xml文档  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;Java Map集合转XML&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 1:13:26 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; writeMap2XML() {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;---------Map --&amp;gt; XML---------&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Map&lt;string student=&quot;&quot;&gt; map = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; HashMap&lt;string student=&quot;&quot;&gt;();&lt;/string&gt;&lt;/string&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        map.put(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.1&quot;&lt;/span&gt;, bean);&lt;span style=&quot;color: green;&quot;&gt;//put&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setAddress(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setEmail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setId(2);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Birthday day = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Birthday(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setBirthday(day);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        map.put(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.2&quot;&lt;/span&gt;, bean);&lt;span style=&quot;color: green;&quot;&gt;//put&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        map.put(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.3&quot;&lt;/span&gt;, bean);&lt;span style=&quot;color: green;&quot;&gt;//put&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;key&quot;&lt;/span&gt;, String.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.useAttributeFor(Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;, &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        xstream.useAttributeFor(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;, String.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(xstream.toXML(map));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    } &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (Exception e) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        e.printStackTrace();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;运行后结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;---------Map --&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt; XML---------&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;entry&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;key&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;No.3&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/key&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;student id=&quot;0&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/student&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/entry&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;entry&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;key&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;No.1&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/key&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;student id=&quot;1&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack@email&lt;span style=&quot;color: #cc6633;&quot;&gt;.com&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;china&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday birthday=&quot;2010-11-22&quot;/&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/student&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/entry&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;entry&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;key&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;No.2&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/key&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;student id=&quot;2&quot;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;tom&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;tom@125&lt;span style=&quot;color: #cc6633;&quot;&gt;.com&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/email&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;china&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;address&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday birthday=&quot;2010-11-22&quot;/&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/student&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/entry&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;map&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;5、 用OutStream输出流写XML  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;用OutStream输出流写XML&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 1:13:48 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; writeXML4OutStream() {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        out = xstream.createObjectOutputStream(System.out);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Student stu = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        stu.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Classes c = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Classes(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;一班&quot;&lt;/span&gt;, bean, stu);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        c.setNumber(2);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;---------ObjectOutputStream # JavaObject--&amp;gt; XML---------&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        out.writeObject(stu);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        out.writeObject(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Birthday(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-05-33&quot;&lt;/span&gt;));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        out.write(22);&lt;span style=&quot;color: green;&quot;&gt;//byte&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        out.writeBoolean(true);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        out.writeFloat(22.f);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        out.writeUTF(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;hello&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    } &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (Exception e) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        e.printStackTrace();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;使用输出流后，可以通过流对象完成xml的构建，即使没有JavaBean对象，你可以用流来构建一个复杂的xml文档，运行后结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;---------ObjectOutputStream # JavaObject--&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt; XML---------&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;-stream&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;com&lt;span style=&quot;color: #cc6633;&quot;&gt;.hoo&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.entity&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.Student&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;0&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/id&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;jack&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/name&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/com&lt;span style=&quot;color: #cc6633;&quot;&gt;.hoo&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.entity&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.Student&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;com&lt;span style=&quot;color: #cc6633;&quot;&gt;.hoo&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.entity&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.Birthday&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;2010-05-33&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/birthday&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/com&lt;span style=&quot;color: #cc6633;&quot;&gt;.hoo&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.entity&lt;/span&gt;&lt;span style=&quot;color: #cc6633;&quot;&gt;.Birthday&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;byte&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;22&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/byte&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;boolean&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;true&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/boolean&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;22.0&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;string&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;hello&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/string&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: #006080;&quot;&gt;&amp;lt;&lt;/span&gt;/&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt;-stream&lt;span style=&quot;color: #006080;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;b&gt;&lt;/b&gt; &lt;b&gt;三、&lt;/b&gt;&lt;b&gt;XML&lt;/b&gt;&lt;b&gt;内容转换&lt;/b&gt;&lt;b&gt;Java&lt;/b&gt;&lt;b&gt;对象&lt;/b&gt;&lt;b&gt;&lt;/b&gt;  &lt;br /&gt;1、 用InputStream将XML文档转换成java对象  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;用InputStream将XML文档转换成java对象 &lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * 需要额外的jar xpp3-main.jar&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 1:14:52 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; readXML4InputStream() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        String s = &lt;span style=&quot;color: #006080;&quot;&gt;&quot;&lt;object-stream&gt;&lt;com .hoo.entity.student=&quot;&quot;&gt;&lt;id&gt;0&lt;/id&gt;&lt;name&gt;jack&lt;/name&gt;&quot;&lt;/com&gt;&lt;/object-stream&gt;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;          &lt;span style=&quot;color: #006080;&quot;&gt;&quot;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;com .hoo.entity.birthday=&quot;&quot;&gt;&lt;birthday&gt;2010-05-33&lt;/birthday&gt;&quot;&lt;/com&gt; +&lt;br /&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;          &lt;span style=&quot;color: #006080;&quot;&gt;&quot;&lt;/span&gt;&lt;/pre&gt;&lt;byte&gt;22&lt;/byte&gt;&lt;boolean&gt;true&lt;/boolean&gt;&lt;float&gt;22.0&lt;/float&gt;&quot; +&lt;br /&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;          &lt;span style=&quot;color: #006080;&quot;&gt;&quot;&lt;string&gt;hello&lt;/string&gt;&lt;/span&gt;&lt;/pre&gt;&quot;;&lt;br /&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;---------ObjectInputStream## XML --&amp;gt; javaObject---------&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        StringReader reader = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; StringReader(s);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        in = xstream.createObjectInputStream(reader);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Student stu = (Student) in.readObject();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Birthday b = (Birthday) in.readObject();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;byte&lt;/span&gt; i = in.readByte();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;boolean&lt;/span&gt; bo = in.readBoolean();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;float&lt;/span&gt; f = in.readFloat();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        String str = in.readUTF();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        System.out.println(stu);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        System.out.println(b);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        System.out.println(i);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        System.out.println(bo);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        System.out.println(f);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        System.out.println(str);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    } &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (Exception e) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        e.printStackTrace();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;读取后，转换的Java对象，结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;---------ObjectInputStream## XML --&amp;gt; javaObject---------&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;jack#0#null#null#null&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;2010-05-33&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;22&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;true&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;22.0&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;hello&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;2、 将xml文档转换成Java对象  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;将XML字符串转换成Java对象&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 2:39:06 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; readXml2Object() {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt; {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;-----------Xml &amp;gt;&amp;gt;&amp;gt; Bean--------------&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Student stu = (Student) xstream.fromXML(xstream.toXML(bean));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(stu.toString());&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        List&lt;student&gt; list = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ArrayList&lt;student&gt;();&lt;/student&gt;&lt;/student&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        list.add(bean);&lt;span style=&quot;color: green;&quot;&gt;//add&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Map&lt;string student=&quot;&quot;&gt; map = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; HashMap&lt;string student=&quot;&quot;&gt;();&lt;/string&gt;&lt;/string&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        map.put(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.1&quot;&lt;/span&gt;, bean);&lt;span style=&quot;color: green;&quot;&gt;//put&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setAddress(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setEmail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setId(2);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Birthday day = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Birthday(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setBirthday(day);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        list.add(bean);&lt;span style=&quot;color: green;&quot;&gt;//add&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        map.put(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.2&quot;&lt;/span&gt;, bean);&lt;span style=&quot;color: green;&quot;&gt;//put&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        list.add(bean);&lt;span style=&quot;color: green;&quot;&gt;//add&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        map.put(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.3&quot;&lt;/span&gt;, bean);&lt;span style=&quot;color: green;&quot;&gt;//put&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;==========XML &amp;gt;&amp;gt;&amp;gt; List===========&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        List&lt;student&gt; studetns = (List&lt;student&gt;) xstream.fromXML(xstream.toXML(list));&lt;/student&gt;&lt;/student&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;size:&quot;&lt;/span&gt; + studetns.size());&lt;span style=&quot;color: green;&quot;&gt;//3&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;for&lt;/span&gt; (Student s : studetns) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            fail(s.toString());&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;==========XML &amp;gt;&amp;gt;&amp;gt; Map===========&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Map&lt;string student=&quot;&quot;&gt; maps = (Map&lt;string student=&quot;&quot;&gt;) xstream.fromXML(xstream.toXML(map));&lt;/string&gt;&lt;/string&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        fail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;size:&quot;&lt;/span&gt; + maps.size());&lt;span style=&quot;color: green;&quot;&gt;//3&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Set&lt;string&gt; key = maps.keySet();&lt;/string&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        Iterator&lt;string&gt; iter = key.iterator();&lt;/string&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (iter.hasNext()) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            String k = iter.next();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            fail(k + &lt;span style=&quot;color: #006080;&quot;&gt;&quot;:&quot;&lt;/span&gt; + map.get(k));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    } &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (Exception e) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        e.printStackTrace();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;运行后结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;-----------Xml &amp;gt;&amp;gt;&amp;gt; Bean--------------&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;jack#1#china#2010-11-22#jack@email.com&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;==========XML &amp;gt;&amp;gt;&amp;gt; List===========&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;size:3&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;jack#1#china#2010-11-22#jack@email.com&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;tom#2#china#2010-11-22#tom@125.com&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;jack#0#null#null#null&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;==========XML &amp;gt;&amp;gt;&amp;gt; Map===========&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;size:3&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;No.3:jack#0#null#null#null&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;No.1:jack#1#china#2010-11-22#jack@email.com&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;No.2:tom#2#china#2010-11-22#tom@125.com&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;怎么样，成功的完成XML到JavaBean、List、Map的转换，更多对象转换还需要大家一一尝试。用法类似~这里就不一样赘述。  &lt;br /&gt;&lt;b&gt;四、&lt;/b&gt;&lt;b&gt;XStream&lt;/b&gt;&lt;b&gt;对&lt;/b&gt;&lt;b&gt;JSON&lt;/b&gt;&lt;b&gt;的支持&lt;/b&gt;&lt;b&gt;&lt;/b&gt;  &lt;br /&gt;xStream对JSON也有非常好的支持，它提供了2个模型驱动。用这2个驱动可以完成Java对象到JSON的相互转换。使用JettisonMappedXmlDriver驱动，将Java对象转换成json，需要添加jettison.jar  &lt;br /&gt;1、 用JettisonMappedXmlDriver完成Java对象到JSON的转换  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;XStream结合JettisonMappedXmlDriver驱动，转换Java对象到JSON&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * 需要添加jettison jar&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 1:23:18 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; writeEntity2JETTSON() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;=======JettisonMappedXmlDriver===JavaObject &amp;gt;&amp;gt;&amp;gt;&amp;gt; JaonString=========&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; XStream(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JettisonMappedXmlDriver());&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream.setMode(XStream.NO_REFERENCES);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    fail(xstream.toXML(bean));&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;运行后结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;=======JettisonMappedXmlDriver===JavaObject &amp;gt;&amp;gt;&amp;gt;&amp;gt; JaonString=========&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;{&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;:{&lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;:1,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;:&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;:&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack@email.com&quot;&lt;/span&gt;,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;:&lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;:[{},&lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;]}}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;JSON的转换和XML的转换用法一样，只是创建XStream需要传递一个参数，这个参数就是xml到JSON映射转换的驱动。这里会降到两个驱动，分别是JettisonMappedXmlDriver、JsonHierarchicalStreamDriver。  &lt;br /&gt;2、 JsonHierarchicalStreamDriver完成Java对象到JSON的转换  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;用XStream结合JsonHierarchicalStreamDriver驱动&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * 转换java对象为JSON字符串&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 1:16:46 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; writeEntiry2JSON() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;======JsonHierarchicalStreamDriver====JavaObject &amp;gt;&amp;gt;&amp;gt;&amp;gt; JaonString=========&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; XStream(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JsonHierarchicalStreamDriver());&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//xstream.setMode(XStream.NO_REFERENCES);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;-------Object &amp;gt;&amp;gt;&amp;gt;&amp;gt; JSON---------&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    fail(xstream.toXML(bean));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//failRed(&quot;========JsonHierarchicalStreamDriver==删除根节点=========&quot;);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//删除根节点&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; XStream(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JsonHierarchicalStreamDriver() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; HierarchicalStreamWriter createWriter(Writer out) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JsonWriter(out, JsonWriter.DROP_ROOT_MODE);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    });&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//xstream.setMode(XStream.NO_REFERENCES);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    fail(xstream.toXML(bean));&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;运行后结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;======JsonHierarchicalStreamDriver====JavaObject &amp;gt;&amp;gt;&amp;gt;&amp;gt; JaonString=========&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;-------Object &amp;gt;&amp;gt;&amp;gt;&amp;gt; JSON---------&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;{&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 1,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack@email.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}}&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;{&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 1,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack@email.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;使用JsonHierarchicalStreamDriver转换默认会给转换后的对象添加一个根节点，但是在构建JsonHierarchicalStreamDriver驱动的时候，你可以重写createWriter方法，删掉根节点。  &lt;br /&gt;看上面的结果，一个是默认带根节点的JSON对象，它只是将类名作为一个属性，将对象作为该属性的一个值。而另一个没有带根属性的JSON就是通过重写createWriter方法完成的。  &lt;br /&gt;3、 将List集合转换成JSON字符串  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; writeList2JSON() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;======JsonHierarchicalStreamDriver====JavaObject &amp;gt;&amp;gt;&amp;gt;&amp;gt; JaonString=========&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    JsonHierarchicalStreamDriver driver = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JsonHierarchicalStreamDriver();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; XStream(driver);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//xstream = new XStream(new JettisonMappedXmlDriver());//转换错误&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//xstream.setMode(XStream.NO_REFERENCES);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    List&lt;student&gt; list = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ArrayList&lt;student&gt;();&lt;/student&gt;&lt;/student&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    list.add(bean);&lt;span style=&quot;color: green;&quot;&gt;//add&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setAddress(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setEmail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setId(2);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    Birthday day = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Birthday(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setBirthday(day);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    list.add(bean);&lt;span style=&quot;color: green;&quot;&gt;//add&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    list.add(bean);&lt;span style=&quot;color: green;&quot;&gt;//add&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    fail(xstream.toXML(list));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//failRed(&quot;========JsonHierarchicalStreamDriver==删除根节点=========&quot;);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//删除根节点&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; XStream(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JsonHierarchicalStreamDriver() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; HierarchicalStreamWriter createWriter(Writer out) {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JsonWriter(out, JsonWriter.DROP_ROOT_MODE);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    });&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    fail(xstream.toXML(list));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;运行后结果如下  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;======JsonHierarchicalStreamDriver====JavaObject &amp;gt;&amp;gt;&amp;gt;&amp;gt; JaonString=========&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;##{&lt;span style=&quot;color: #006080;&quot;&gt;&quot;list&quot;&lt;/span&gt;: [&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 1,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack@email.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  },&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 2,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  },&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 0,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;]}&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;#[&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 1,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack@email.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  },&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 2,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  },&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 0,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;]&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;上面的list1是使用JsonHierarchicalStreamDriver 转换的，当然你也可以使用JettisonMappedXmlDriver驱动进行转换；用JettisonMappedXmlDriver转换后，你会发现格式不同而且没有根属性。  &lt;br /&gt;4、 Map转换json  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; writeMap2JSON() {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    failRed(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;======JsonHierarchicalStreamDriver==== Map &amp;gt;&amp;gt;&amp;gt;&amp;gt; JaonString=========&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; XStream(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JsonHierarchicalStreamDriver());&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//xstream = new XStream(new JettisonMappedXmlDriver());&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    Map&lt;string student=&quot;&quot;&gt; map = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; HashMap&lt;string student=&quot;&quot;&gt;();&lt;/string&gt;&lt;/string&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    map.put(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.1&quot;&lt;/span&gt;, bean);&lt;span style=&quot;color: green;&quot;&gt;//put&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setAddress(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setEmail(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setId(2);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setBirthday(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Birthday(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-21&quot;&lt;/span&gt;));&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    map.put(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.2&quot;&lt;/span&gt;, bean);&lt;span style=&quot;color: green;&quot;&gt;//put&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Student();&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    bean.setName(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    map.put(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.3&quot;&lt;/span&gt;, bean);&lt;span style=&quot;color: green;&quot;&gt;//put&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    fail(xstream.toXML(map));&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//failRed(&quot;========JsonHierarchicalStreamDriver==删除根节点=========&quot;);&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//删除根节点&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; XStream(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JsonHierarchicalStreamDriver() {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; HierarchicalStreamWriter createWriter(Writer out) {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JsonWriter(out, JsonWriter.DROP_ROOT_MODE);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    });&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    fail(xstream.toXML(map));&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;运行后结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;======JsonHierarchicalStreamDriver==== Map &amp;gt;&amp;gt;&amp;gt;&amp;gt; JaonString=========&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;{&lt;span style=&quot;color: #006080;&quot;&gt;&quot;map&quot;&lt;/span&gt;: [&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  [&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.3&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 0,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  ],&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  [&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.1&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 1,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack@email.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  ],&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  [&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.2&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 2,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-21&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  ]&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;]}&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;[&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  [&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.3&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 0,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  ],&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  [&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.1&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 1,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;jack@email.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  ],&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  [&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;No.2&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 2,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-21&quot;&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;      }&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    }&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;  ]&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;]&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;5、 将JSON转换java对象  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt;/**&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * &lt;b&gt;function:&lt;/b&gt;JsonHierarchicalStreamDriver可以将简单的json字符串转换成java对象，list、map转换不成功；&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * JsonHierarchicalStreamDriver读取JSON字符串到java对象出错&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @author hoojo&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @createDate Nov 27, 2010 1:22:26 PM&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; * @throws JSONException&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: green;&quot;&gt; */&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;@Test&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; readJSON2Object() &lt;span style=&quot;color: blue;&quot;&gt;throws&lt;/span&gt; JSONException {&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    String json = &lt;span style=&quot;color: #006080;&quot;&gt;&quot;{\&quot;student\&quot;: {&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;id\&quot;: 1,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;name\&quot;: \&quot;haha\&quot;,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;email\&quot;: \&quot;email\&quot;,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;address\&quot;: \&quot;address\&quot;,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;birthday\&quot;: {&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;birthday\&quot;: \&quot;2010-11-22\&quot;&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;        &lt;span style=&quot;color: #006080;&quot;&gt;&quot;}&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: #006080;&quot;&gt;&quot;}}&quot;&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//JsonHierarchicalStreamDriver读取JSON字符串到java对象出错，但JettisonMappedXmlDriver可以&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; XStream(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; JettisonMappedXmlDriver());&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    xstream.alias(&lt;span style=&quot;color: #006080;&quot;&gt;&quot;student&quot;&lt;/span&gt;, Student.&lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt;);&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    fail(xstream.fromXML(json).toString());&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//JettisonMappedXmlDriver转换List集合出错，但JsonHierarchicalStreamDriver可以转换正确&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    &lt;span style=&quot;color: green;&quot;&gt;//JettisonMappedXmlDriver 转换的字符串 {&quot;list&quot;:{&quot;student&quot;:[{&quot;id&quot;:1,&quot;name&quot;:&quot;haha&quot;,&quot;email&quot;:&quot;email&quot;,&quot;address&quot;:&quot;address&quot;,&quot;birthday&quot;:[{},&quot;2010-11-22&quot;]}]},&quot;student&quot;:{&quot;id&quot;:2,&quot;name&quot;:&quot;tom&quot;,&quot;email&quot;:&quot;tom@125.com&quot;,&quot;address&quot;:&quot;china&quot;,&quot;birthday&quot;:[{},&quot;2010-11-22&quot;]}}&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    json = &lt;span style=&quot;color: #006080;&quot;&gt;&quot;{\&quot;list\&quot;: [{&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;id\&quot;: 1,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;name\&quot;: \&quot;haha\&quot;,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;email\&quot;: \&quot;email\&quot;,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;address\&quot;: \&quot;address\&quot;,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;birthday\&quot;: {&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;              &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;birthday\&quot;: \&quot;2010-11-22\&quot;&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;}&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;           &lt;span style=&quot;color: #006080;&quot;&gt;&quot;},{&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;id\&quot;: 2,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;name\&quot;: \&quot;tom\&quot;,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;email\&quot;: \&quot;tom@125.com\&quot;,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;address\&quot;: \&quot;china\&quot;,&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;birthday\&quot;: {&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;              &lt;span style=&quot;color: #006080;&quot;&gt;&quot;\&quot;birthday\&quot;: \&quot;2010-11-22\&quot;&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;            &lt;span style=&quot;color: #006080;&quot;&gt;&quot;}&quot;&lt;/span&gt; +&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;          &lt;span style=&quot;color: #006080;&quot;&gt;&quot;}]}&quot;&lt;/span&gt;;&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    System.out.println(json);&lt;span style=&quot;color: green;&quot;&gt;//用js转换成功&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    List list = (List) xstream.fromXML(json);&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;    System.out.println(list.size());&lt;span style=&quot;color: green;&quot;&gt;//0好像转换失败&lt;/span&gt;&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;运行后结果如下：  &lt;br /&gt;&lt;div id=&quot;codeSnippetWrapper&quot;&gt;&lt;div id=&quot;codeSnippet&quot; style=&quot;background-color: #f4f4f4; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; overflow: visible; padding: 0px; width: 100%;&quot;&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;haha#1#address#2010-11-22#email&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;{&lt;span style=&quot;color: #006080;&quot;&gt;&quot;list&quot;&lt;/span&gt;: [{&lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 1,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;haha&quot;&lt;/span&gt;,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;}},&lt;/pre&gt;&lt;pre style=&quot;background-color: white; border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;{&lt;span style=&quot;color: #006080;&quot;&gt;&quot;id&quot;&lt;/span&gt;: 2,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;name&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom&quot;&lt;/span&gt;,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;email&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;tom@125.com&quot;&lt;/span&gt;,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;address&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;china&quot;&lt;/span&gt;,&lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: {&lt;span style=&quot;color: #006080;&quot;&gt;&quot;birthday&quot;&lt;/span&gt;: &lt;span style=&quot;color: #006080;&quot;&gt;&quot;2010-11-22&quot;&lt;/span&gt;}}]}&lt;/pre&gt;&lt;pre style=&quot;border-style: none; direction: ltr; font-family: &#39;Courier New&#39;, courier, monospace; font-size: 10pt; line-height: 12pt; margin: 0em; overflow: visible; padding: 0px; width: 100%;&quot;&gt;0&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;JSON到Java的转换是fromXML方法。&lt;br /&gt;&lt;br /&gt;出处：http://www.cnblogs.com/hoojo/archive/2011/04/22/2025197.html</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/4477720484522197883/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/05/xstreamxmljson.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/4477720484522197883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/4477720484522197883'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/05/xstreamxmljson.html' title='xStream完美转换XML、JSON'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-2718917270181202710</id><published>2013-05-21T09:23:00.001+10:00</published><updated>2013-05-21T09:46:33.628+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>用Kibana和logstash快速搭建实时日志查询、收集与分析系统 </title><content type='html'>&lt;br /&gt;&amp;nbsp; Logstash是一个完全开源的工具，他可以对你的日志进行收集、分析，并将其存储供以后使用（如，搜索），您可以使用它。说到搜索，logstash带有一个web界面，搜索和展示所有日志。&lt;br /&gt;kibana 也是一个开源和免费的工具，他可以帮助您汇总、分析和搜索重要数据日志并提供友好的web界面。他可以为 Logstash 和 ElasticSearch 提供的日志分析的 Web 界面&lt;br /&gt;说到这里，我们看看 kibana 和 logstash到底能为我们做些什么呢？下面是kibana的界面&lt;br /&gt;&lt;a href=&quot;http://img1.51cto.com/attachment/201303/131035239.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://img1.51cto.com/attachment/201303/131035239.png&quot; width=&quot;650&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;&amp;nbsp; 简单来讲他具体的工作流程就是 logstash agent 监控并过滤日志，将过滤后的日志内容发给redis(这里的redis只处理队列不做存储)，logstash index将日志收集在一起交给&lt;br /&gt;全文搜索服务ElasticSearch 可以用ElasticSearch进行自定义搜索 通过Kibana 来结合 自定义搜索进行页面展示，下图是 Kibana官网上的流程图&lt;/span&gt;&lt;br /&gt;&lt;a href=&quot;http://img1.51cto.com/attachment/201303/131135111.png&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://img1.51cto.com/attachment/201303/131135111.png&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;好了 让我们一步步的把这套环境搭建起来吧，先看看都需要安装什么软件包&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;ruby 运行Kibana 必须，&lt;br /&gt;rubygems 安装ruby扩展必须&lt;br /&gt;bundler 功能类似于yum&lt;br /&gt;JDK 运行java程序必须 &lt;br /&gt;redis 用来处理日志队列&lt;br /&gt;logstash 收集、过滤日志&lt;br /&gt;ElasticSearch 全文搜索服务(logstash集成了一个)&lt;br /&gt;kibana 页面展示&lt;/span&gt;&lt;br /&gt;这里有三台服务器&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;192.168.233.128 logstash index，ElasticSearch，kibana，JDK&lt;br /&gt;192.168.233.129 logstash agent，JDK&lt;br /&gt;192.168.233.130 redis&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;首先到 logstash index服务器上面，logstash分为 index和aget ，agent负责监控、过滤日志，index负责收集日志并将日志交给ElasticSearch 做搜索&lt;br /&gt;此外 logstash 的收集方式分为 standalone 和 centralized。&lt;br /&gt;standalone 是所有功能都在一个服务器上面，自发自收，centralized 就是集中收集，一台服务器接收所有shipper(个人理解就是logstash agent)的日志。&lt;br /&gt;其实 logstash本身不分 什么 shipper 和 collector ，只不过就是配置文件不同而已，我们这次按照集中的方式来测试&lt;br /&gt;&lt;br /&gt;在 logstash index上安装基础的软件环境&lt;br /&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:~]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;cd&amp;nbsp;/soft/&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;wget&amp;nbsp;http://down1.chinaunix.net/distfiles/jdk-6u13-dlj-linux-i586.bin&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;从oracle下载实在是太慢了，从CU下载会快一些，如果需要最新版本请访问这里&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;sh&amp;nbsp;jdk-6u13-dlj-linux-i586.bin&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;输入yes&amp;nbsp;便开始安装了&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;安装完成后设置一下&amp;nbsp;JAVA_HOME&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft/Kibana-0.2.0]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;vim&amp;nbsp;/etc/profile&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;export&amp;nbsp;JAVA_HOME=/usr/java&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;export&amp;nbsp;PATH=$JAVA_HOME/bin:$PATH&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;export&amp;nbsp;CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;安装ruby&amp;nbsp;就比较简单了(Kibana需要ruby&amp;nbsp;1.8.7以上版本)&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;yum&amp;nbsp;install&amp;nbsp;ruby&amp;nbsp;rubygems&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;.....&amp;nbsp;安装内容省略&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;安装完成后用&amp;nbsp;rubygems&amp;nbsp;来安装bundler&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;/usr/bin/gem&amp;nbsp;install&amp;nbsp;bundler&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;.....&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;ok&amp;nbsp;这样基本的环境就已经有了，下面就是安装kibana&amp;nbsp;和&amp;nbsp;logstash&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;其实logstash&amp;nbsp;就是一个java脚本，不需要安装...&amp;nbsp;下载即用&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;wget&amp;nbsp;http://logstash.objects.dreamhost.com/release/logstash-1.1.0-monolithic.jar&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;现在看看&amp;nbsp;这个脚本应该怎么去执行&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;java&amp;nbsp;-jar&amp;nbsp;/soft/logstash-1.1.0-monolithic.jar&amp;nbsp;-h&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;No&lt;/span&gt;&amp;nbsp;such&amp;nbsp;command&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&quot;-h&quot;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Available&amp;nbsp;commands:&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;-v&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;-V&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--version&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;agent&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;web&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;test&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;显然没有&amp;nbsp;-h&amp;nbsp;参数，不过列出了能用的参数，但是logstash的参数可不止这些，&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;java&amp;nbsp;-jar&amp;nbsp;/soft/logstash-1.1.0-monolithic.jar&amp;nbsp;agent&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--help&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;这些是在agent模式下的命令参数&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;-f,&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--config&amp;nbsp;CONFIGFILE&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;Load&lt;/span&gt;&amp;nbsp;the&amp;nbsp;logstash&amp;nbsp;config&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt;&amp;nbsp;a&amp;nbsp;specific&amp;nbsp;file,&amp;nbsp;directory,&amp;nbsp;&lt;span class=&quot;op&quot;&gt;or&lt;/span&gt;&amp;nbsp;a&amp;nbsp;wildcard.&amp;nbsp;If&amp;nbsp;given&amp;nbsp;a&amp;nbsp;directory&amp;nbsp;&lt;span class=&quot;op&quot;&gt;or&lt;/span&gt;&amp;nbsp;wildcard,&amp;nbsp;config&amp;nbsp;files&amp;nbsp;will&amp;nbsp;be&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;read&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;op&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;order&lt;/span&gt;&amp;nbsp;lexigraphically.&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;-e&amp;nbsp;CONFIGSTRING&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Use&amp;nbsp;the&amp;nbsp;given&amp;nbsp;string&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;as&lt;/span&gt;&amp;nbsp;the&amp;nbsp;configuration&amp;nbsp;data.&amp;nbsp;Same&amp;nbsp;syntax&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;as&lt;/span&gt;&amp;nbsp;the&amp;nbsp;config&amp;nbsp;file.&amp;nbsp;If&amp;nbsp;&lt;span class=&quot;op&quot;&gt;not&lt;/span&gt;&amp;nbsp;input&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;specified,&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;stdin&amp;nbsp;{&amp;nbsp;type&amp;nbsp;=&amp;gt;&amp;nbsp;stdin&amp;nbsp;}&#39;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;default&lt;/span&gt;.&amp;nbsp;If&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;no&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;output&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;specified,&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;stdout&amp;nbsp;{&amp;nbsp;debug&amp;nbsp;=&amp;gt;&amp;nbsp;true&amp;nbsp;}}&#39;&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;default&lt;/span&gt;.&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;-w,&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--filterworks&amp;nbsp;COUNT&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Run&amp;nbsp;&lt;span class=&quot;func&quot;&gt;COUNT&lt;/span&gt;&amp;nbsp;filter&amp;nbsp;workers&amp;nbsp;(&lt;span class=&quot;keyword&quot;&gt;default&lt;/span&gt;:&amp;nbsp;1)&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;--watchdog-timeout&amp;nbsp;TIMEOUT&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;Set&lt;/span&gt;&amp;nbsp;watchdog&amp;nbsp;timeout&amp;nbsp;value.&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;-l,&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--log&amp;nbsp;FILE&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Log&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;a&amp;nbsp;given&amp;nbsp;path.&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;Default&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;log&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;stdout&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;-v&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Increase&amp;nbsp;verbosity.&amp;nbsp;There&amp;nbsp;are&amp;nbsp;multiple&amp;nbsp;levels&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;of&lt;/span&gt;&amp;nbsp;verbosity&amp;nbsp;available&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;with&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;-vv&#39;&lt;/span&gt;&amp;nbsp;currently&amp;nbsp;being&amp;nbsp;the&amp;nbsp;highest&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;--pluginpath&amp;nbsp;PLUGIN_PATH&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;A&amp;nbsp;colon-delimted&amp;nbsp;path&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;find&amp;nbsp;other&amp;nbsp;logstash&amp;nbsp;plugins&amp;nbsp;&lt;span class=&quot;op&quot;&gt;in&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;java&amp;nbsp;-jar&amp;nbsp;/soft/logstash-1.1.0-monolithic.jar&amp;nbsp;web&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--help&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;下面的是在web界面的参数&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;--log&amp;nbsp;FILE&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Log&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;a&amp;nbsp;given&amp;nbsp;path.&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;Default&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;stdout.&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;--address&amp;nbsp;ADDRESS&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Address&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;on&lt;/span&gt;&amp;nbsp;which&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;start&amp;nbsp;webserver.&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;Default&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;0.0.0.0.&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;span class=&quot;comment&quot;&gt;--port&amp;nbsp;PORT&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Port&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;on&lt;/span&gt;&amp;nbsp;which&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;start&amp;nbsp;webserver.&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;Default&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;9292.&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;-B,&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--elasticsearch-bind-host&amp;nbsp;ADDRESS&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Address&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;on&lt;/span&gt;&amp;nbsp;which&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;bind&amp;nbsp;elastic&amp;nbsp;search&amp;nbsp;node.&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;-b,&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--backend&amp;nbsp;URL&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;The&amp;nbsp;backend&amp;nbsp;URL&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;use.&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;Default&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;elasticsearch:///&amp;nbsp;(assumes&amp;nbsp;multicast&amp;nbsp;discovery).&amp;nbsp;You&amp;nbsp;can&amp;nbsp;specify&amp;nbsp;elasticsearch://[host][:port]/[clustername]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;span style=&quot;font-size: 14px;&quot;&gt;如果上面的这些命令都能执行正常的话就表示 logstash可以使用了，但要让他启动还需要一个配置文件&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;vim&amp;nbsp;redis.conf&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;input&amp;nbsp;{&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;redis&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;host&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;192.168.233.130&#39;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;data_type&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;list&#39;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;port&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&quot;6379&quot;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;key&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;logstash:redis&#39;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;type&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;redis-input&#39;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;output&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;elasticsearch&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;embedded&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;true&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;解释一下 logstash的配置文件由 input filter output 等几个基本的部分组成，顾名思义 input 就是在那收集数据，output就是输出到哪，filter代表一个过滤规则意思是什么内容&lt;br /&gt;会被收集。&lt;br /&gt;上面这段是让 logstash 去192.168.233.130 这个redis服务器上去收集日志 redis端口为6379，key是 logstash:redis 类型为 redis-input ，（注意:这几个值必须跟logstash agent的&lt;br /&gt;output 所对应），收集完成后输出到 elasticsearch ,embedded =&amp;gt; true 的意思是使用logstash 内嵌的 elasticsearch。如果有独立的elasticsearch服务器，需要将 这条改为&lt;br /&gt;host =&amp;gt; &#39;elasticsearch的ip&#39; port =&amp;gt; 端口&lt;br /&gt;好了，这个简单的配置文件可以让logstash开始启动了&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;java&amp;nbsp;-jar&amp;nbsp;/soft/logstash-1.1.0-monolithic.jar&amp;nbsp;agent&amp;nbsp;-f&amp;nbsp;/soft/redis.conf&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--&amp;nbsp;web&amp;nbsp;--backend&amp;nbsp;elasticsearch:///?local&amp;nbsp;&amp;amp;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[1]&amp;nbsp;5205&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;...这里要等待约5秒钟...&amp;nbsp;为什么？去问开发者吧&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;I,&amp;nbsp;[2013-03-19T03:23:10.749000&amp;nbsp;#5205]&amp;nbsp;&amp;nbsp;INFO&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--&amp;nbsp;:&amp;nbsp;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;redis&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&amp;nbsp;{&quot;timestamp&quot;:&quot;2013-03-19T03:23:10.732000&amp;nbsp;-0700&quot;,&quot;message&quot;:&quot;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;redis&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&quot;,&quot;level&quot;:&quot;info&quot;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;file:/soft/logstash-1.1.0-monolithic.jar!/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53&amp;nbsp;warning:&amp;nbsp;already&amp;nbsp;initialized&amp;nbsp;constant&amp;nbsp;WFKV_&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Mizuno&amp;nbsp;0.5.0&amp;nbsp;(Jetty&amp;nbsp;8.0.y.z-SNAPSHOT)&amp;nbsp;listening&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;on&lt;/span&gt;&amp;nbsp;0.0.0.0:9292&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;解释一下&amp;nbsp;上面的命令&amp;nbsp;agent&amp;nbsp;代理模式&amp;nbsp;-f&amp;nbsp;指定配置文件&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--web&amp;nbsp;其实是个分隔符等于又启动了一个命令，后面的参数就是开启一个web页面默认端口是9292,这个命令如果拆成两个就是这个样子&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;java&amp;nbsp;-jar&amp;nbsp;/soft/logstash-1.1.0-monolithic.jar&amp;nbsp;agent&amp;nbsp;-f&amp;nbsp;/soft/redis.conf&amp;nbsp;&amp;amp;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;java&amp;nbsp;-jar&amp;nbsp;/soft/logstash-1.1.0-monolithic.jar&amp;nbsp;web&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--backend&amp;nbsp;elasticsearch:///?local&amp;nbsp;&amp;amp;&lt;/span&gt; (其实如果用kibana来做web界面的话这一步完全可以省掉了)&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;好了，看到9292 端口启动就代表 启动成功了，检查一下&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;lsof&amp;nbsp;-i:9292&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;COMMAND&amp;nbsp;&amp;nbsp;PID&amp;nbsp;&lt;span class=&quot;func&quot;&gt;USER&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FD&amp;nbsp;&amp;nbsp;&amp;nbsp;TYPE&amp;nbsp;DEVICE&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;SIZE&lt;/span&gt;&amp;nbsp;NODE&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;NAME&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;java&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5205&amp;nbsp;root&amp;nbsp;&amp;nbsp;465u&amp;nbsp;&amp;nbsp;IPv4&amp;nbsp;130805&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TCP&amp;nbsp;*:armtechdaemon&amp;nbsp;(LISTEN)&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;其实logstash还启动了一个端口9200，因为启动了内嵌的&amp;nbsp;elasticsearch，这个9200是&amp;nbsp;elasticsearch在监听&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;lsof&amp;nbsp;-i:9200&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;COMMAND&amp;nbsp;&amp;nbsp;PID&amp;nbsp;&lt;span class=&quot;func&quot;&gt;USER&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FD&amp;nbsp;&amp;nbsp;&amp;nbsp;TYPE&amp;nbsp;DEVICE&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;SIZE&lt;/span&gt;&amp;nbsp;NODE&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;NAME&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;java&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5205&amp;nbsp;root&amp;nbsp;&amp;nbsp;160u&amp;nbsp;&amp;nbsp;IPv4&amp;nbsp;130682&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TCP&amp;nbsp;*:wap-wsp&amp;nbsp;(LISTEN)&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;现在可以通过浏览器访问一下 http://192.168.233.128:9292 看看logstash是的页面是个什么样子&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;a href=&quot;http://img1.51cto.com/attachment/201303/133957451.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://img1.51cto.com/attachment/201303/133957451.jpg&quot; width=&quot;650&quot; /&gt;&lt;/a&gt;现在还不能搜索因为现在还没有数据，其实这个时候 http://192.168.233.128:9200 也是可以访问的，&lt;br /&gt;很多开发自己写代码来调用elasticsearch 来实现他们自己的需要，这里就不多说了&lt;br /&gt;192.168.233.128 这台logstash index的操作暂时告一段落，&lt;span style=&quot;color: magenta;&quot;&gt;下面开始配置logstash的agent&lt;/span&gt;&lt;br /&gt;登录到 服务器 192.168.233.129 安装基本软件包和logstash&lt;br /&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.129&amp;nbsp;root@noded:~]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;cd&amp;nbsp;/soft/&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.129&amp;nbsp;root@noded:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;wget&amp;nbsp;http://down1.chinaunix.net/distfiles/jdk-6u13-dlj-linux-i586.bin&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.129&amp;nbsp;root@noded:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;sh&amp;nbsp;jdk-6u13-dlj-linux-i586.bin&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;设置&amp;nbsp;JAVA_HOME&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;[192.168.233.129&amp;nbsp;root@noded:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;vim&amp;nbsp;/etc/profile&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;export&amp;nbsp;JAVA_HOME=/usr/java&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;export&amp;nbsp;PATH=$JAVA_HOME/bin:$PATH&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;export&amp;nbsp;CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:$CLASSPATH&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.129&amp;nbsp;root@noded:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;yum&amp;nbsp;install&amp;nbsp;ruby&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;192.168.233.129&amp;nbsp;root@noded:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;wget&amp;nbsp;http://logstash.objects.dreamhost.com/release/logstash-1.1.0-monolithic.jar&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.129&amp;nbsp;root@noded:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;vim&amp;nbsp;redis.conf&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;input&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;file&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&quot;producer&quot;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;path&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&quot;/soft/apache.log&quot;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;file&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;type&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&quot;php-log&quot;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;path&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&quot;/soft/php.log&quot;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;filter&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;grep&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;match&amp;nbsp;=&amp;gt;&amp;nbsp;[&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&quot;@message&quot;&lt;/span&gt;,&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&quot;mysql|GET|error&quot;&lt;/span&gt;&amp;nbsp;]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;output&lt;/span&gt;&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;redis&amp;nbsp;{&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;host&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;192.168.233.130&#39;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;data_type&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;list&#39;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;key&lt;/span&gt;&amp;nbsp;=&amp;gt;&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;logstash:redis&#39;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; 大概说一下这个配置文件 input 里的file就是要监视的文件了 这里我监视了两个文件，如果这两个文件有追加的内容就会通过下面的output设置发给 redis服务器&lt;br /&gt;filter 里的grep 意思就是 grep...&amp;nbsp; 后面这段就是 日志内容里面只要有匹配 &lt;span style=&quot;color: magenta;&quot;&gt;mysql或GET或error&lt;/span&gt;的内容就会被过滤出来，发送到 logstash index&lt;br /&gt;以上就是一个比较简单的配置文件了，让我们启动他&lt;br /&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.129&amp;nbsp;root@noded:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;java&amp;nbsp;-jar&amp;nbsp;/soft/logstash-1.1.0-monolithic.jar&amp;nbsp;agent&amp;nbsp;-f&amp;nbsp;/soft/redis.conf&amp;nbsp;&amp;amp;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;I,&amp;nbsp;[2013-03-19T19:45:35.762000&amp;nbsp;#2721]&amp;nbsp;&amp;nbsp;INFO&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--&amp;nbsp;:&amp;nbsp;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;file&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&amp;nbsp;{&quot;timestamp&quot;:&quot;2013-03-19T19:45:35.752000&amp;nbsp;-0700&quot;,&quot;message&quot;:&quot;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;file&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&quot;,&quot;level&quot;:&quot;info&quot;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;I,&amp;nbsp;[2013-03-19T19:45:35.778000&amp;nbsp;#2721]&amp;nbsp;&amp;nbsp;INFO&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--&amp;nbsp;:&amp;nbsp;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;file&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&amp;nbsp;{&quot;timestamp&quot;:&quot;2013-03-19T19:45:35.778000&amp;nbsp;-0700&quot;,&quot;message&quot;:&quot;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;file&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&quot;,&quot;level&quot;:&quot;info&quot;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;I,&amp;nbsp;[2013-03-19T19:45:35.804000&amp;nbsp;#2721]&amp;nbsp;&amp;nbsp;INFO&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--&amp;nbsp;:&amp;nbsp;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;grep&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&amp;nbsp;{&quot;timestamp&quot;:&quot;2013-03-19T19:45:35.803000&amp;nbsp;-0700&quot;,&quot;message&quot;:&quot;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;grep&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&quot;,&quot;level&quot;:&quot;info&quot;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;I,&amp;nbsp;[2013-03-19T19:45:35.854000&amp;nbsp;#2721]&amp;nbsp;&amp;nbsp;INFO&amp;nbsp;&lt;span class=&quot;comment&quot;&gt;--&amp;nbsp;:&amp;nbsp;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;redis&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&amp;nbsp;{&quot;timestamp&quot;:&quot;2013-03-19T19:45:35.853000&amp;nbsp;-0700&quot;,&quot;message&quot;:&quot;Using&amp;nbsp;beta&amp;nbsp;plugin&amp;nbsp;&#39;redis&#39;.&amp;nbsp;For&amp;nbsp;more&amp;nbsp;information&amp;nbsp;about&amp;nbsp;plugin&amp;nbsp;statuses,&amp;nbsp;see&amp;nbsp;http://logstash.net/docs/1.1.0/plugin-status&amp;nbsp;&quot;,&quot;level&quot;:&quot;info&quot;}&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;只要没有 warning 和 error就算是正常启动了&lt;br /&gt;启动之前请确定 192.168.233.130的 redis服务器已经启动，不然会报错&lt;br /&gt;&lt;span style=&quot;color: magenta;&quot;&gt;下面登录到 192.168.233.130 上看看 redis服务的状态&lt;/span&gt;&lt;br /&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.130&amp;nbsp;root@nodea:/data/redis/etc]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;lsof&amp;nbsp;-i:6379&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;COMMAND&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;PID&amp;nbsp;&lt;span class=&quot;func&quot;&gt;USER&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FD&amp;nbsp;&amp;nbsp;&amp;nbsp;TYPE&amp;nbsp;DEVICE&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;SIZE&lt;/span&gt;&amp;nbsp;NODE&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;NAME&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;redis-ser&amp;nbsp;2732&amp;nbsp;root&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4u&amp;nbsp;&amp;nbsp;IPv4&amp;nbsp;&amp;nbsp;&amp;nbsp;7946&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TCP&amp;nbsp;*:6379&amp;nbsp;(LISTEN)&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;redis-ser&amp;nbsp;2732&amp;nbsp;root&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5u&amp;nbsp;&amp;nbsp;IPv4&amp;nbsp;&amp;nbsp;&amp;nbsp;7963&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TCP&amp;nbsp;localhost.localdomain:6379-&amp;gt;localhost.localdomain:19214&amp;nbsp;(ESTABLISHED)&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;java&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2733&amp;nbsp;root&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9u&amp;nbsp;&amp;nbsp;IPv4&amp;nbsp;&amp;nbsp;&amp;nbsp;7959&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TCP&amp;nbsp;localhost.localdomain:19214-&amp;gt;localhost.localdomain:6379&amp;nbsp;(ESTABLISHED)&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;状态正常，端口处于监听状态，我用的是最简单的&amp;nbsp;配置，&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;[192.168.233.130&amp;nbsp;root@nodea:/data/redis/etc]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;vim&amp;nbsp;redis.conf&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#this&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;is&lt;/span&gt;&amp;nbsp;the&amp;nbsp;config&amp;nbsp;file&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt;&amp;nbsp;redis&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;pidfile&amp;nbsp;/var/run/redis.pid&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;port&amp;nbsp;6379&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;timeout&amp;nbsp;0&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;loglevel&amp;nbsp;verbose&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;logfile&amp;nbsp;/data/redis/log/redis.log&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;dbfilename&amp;nbsp;dump.rdb&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;dir&amp;nbsp;/data/redis/db/&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;vm-swap-file&amp;nbsp;/tmp/redis.swap&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;activerehashing&amp;nbsp;yes&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;启动命令如下&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.130&amp;nbsp;root@nodea:/data/redis/etc]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;redis-server&amp;nbsp;/data/redis/etc/redis.conf&amp;nbsp;&amp;amp;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;下载安装就比较简单了&lt;br /&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.130&amp;nbsp;root@nodea:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;wget&amp;nbsp;http://redis.googlecode.com/files/redis-2.4.14.tar.gz&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.130&amp;nbsp;root@nodea:/data/redis/etc]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;make&amp;nbsp;–j24&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.130&amp;nbsp;root@nodea:/data/redis/etc]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;make&amp;nbsp;install&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;配置文件里的那几个路径要提前建好&lt;br /&gt;&lt;br /&gt;最后我们回到 logstash agent 上面测试一下&lt;br /&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.129&amp;nbsp;root@noded:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;echo&amp;nbsp;GET12313&amp;nbsp;&amp;gt;&amp;gt;&amp;nbsp;apache.log&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.129&amp;nbsp;root@noded:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;echo&amp;nbsp;errorabcd&amp;nbsp;&amp;gt;&amp;gt;&amp;nbsp;apache.log&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;ok 到 http://192.168.233.128:9292 去搜索一下 刚才的两个内容&lt;br /&gt;&lt;a href=&quot;http://img1.51cto.com/attachment/201303/132952247.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://img1.51cto.com/attachment/201303/132952247.jpg&quot; width=&quot;650&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://img1.51cto.com/attachment/201303/133019112.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://img1.51cto.com/attachment/201303/133019112.jpg&quot; width=&quot;650&quot; /&gt;&lt;/a&gt;&lt;br /&gt;嗯，就是这样了，我现在找个php的错误日志给他追加到php.log文件里 &lt;br /&gt;[192.168.233.129 root@noded:/soft]&lt;br /&gt;# cat php-error.log &amp;gt;&amp;gt; php.log&lt;br /&gt;在看看 logstash的页面 搜索一下 error&lt;br /&gt;&lt;a href=&quot;http://img1.51cto.com/attachment/201303/202133777.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://img1.51cto.com/attachment/201303/202133777.jpg&quot; width=&quot;650&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;OK，最后就是 Kibana了 ，我把Kibana装在了 logstash index上面&lt;br /&gt;下载地址为 http://kibana.org/intro.html&lt;br /&gt;&lt;pre&gt;&lt;ol class=&quot;dp-sql&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;tar&amp;nbsp;xf&amp;nbsp;Kibana-0.2.0.tar.gz&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;cd&amp;nbsp;Kibana-0.2.0&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft/Kibana-0.2.0]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;bundle&amp;nbsp;install&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;直接安装就好了，非常简单，因为之前咱们已经安装好了&amp;nbsp;bundle&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;编辑配置文件，指定&amp;nbsp;elasticsearch&amp;nbsp;的位置&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft/Kibana-0.2.0]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;#&amp;nbsp;vim&amp;nbsp;KibanaConfig.rb&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;.....&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;Elasticsearch&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&quot;localhost:9200&quot;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;nbsp;&amp;nbsp;KibanaPort&amp;nbsp;=&amp;nbsp;5601&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;nbsp;&amp;nbsp;KibanaHost&amp;nbsp;=&amp;nbsp;&lt;span class=&quot;string&quot;&gt;&#39;0.0.0.0&#39;&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;.....&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;主要是这几个参数&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;启动的话需要ruby&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft/Kibana-0.2.0]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;/usr/bin/ruby&amp;nbsp;kibana.rb&amp;nbsp;&amp;amp;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft/Kibana-0.2.0]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;==&amp;nbsp;Sinatra/1.3.5&amp;nbsp;has&amp;nbsp;taken&amp;nbsp;the&amp;nbsp;stage&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;on&lt;/span&gt;&amp;nbsp;5601&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt;&amp;nbsp;development&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;with&lt;/span&gt;&amp;nbsp;backup&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt;&amp;nbsp;Thin&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;gt;&amp;gt;&amp;nbsp;Thin&amp;nbsp;web&amp;nbsp;server&amp;nbsp;(v1.5.0&amp;nbsp;codename&amp;nbsp;Knife)&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;&amp;gt;&amp;gt;&amp;nbsp;Maximum&amp;nbsp;connections&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;set&lt;/span&gt;&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;1024&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&amp;gt;&amp;gt;&amp;nbsp;Listening&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;on&lt;/span&gt;&amp;nbsp;0.0.0.0:5601,&amp;nbsp;CTRL+C&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;to&lt;/span&gt;&amp;nbsp;stop&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;如果ruby的东西都不缺的话，启动会很顺利，ok&amp;nbsp;现在看看5601端口的状态&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;[192.168.233.128&amp;nbsp;root@nodec:/soft/Kibana-0.2.0]&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;#&amp;nbsp;lsof&amp;nbsp;-i:5601&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;COMMAND&amp;nbsp;&amp;nbsp;PID&amp;nbsp;&lt;span class=&quot;func&quot;&gt;USER&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;FD&amp;nbsp;&amp;nbsp;&amp;nbsp;TYPE&amp;nbsp;DEVICE&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;SIZE&lt;/span&gt;&amp;nbsp;NODE&amp;nbsp;&lt;span class=&quot;keyword&quot;&gt;NAME&lt;/span&gt;&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot;&gt;ruby&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3116&amp;nbsp;root&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5u&amp;nbsp;&amp;nbsp;IPv4&amp;nbsp;&amp;nbsp;28947&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TCP&amp;nbsp;*:esmagent&amp;nbsp;(LISTEN)&amp;nbsp;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;访问一下 试试看 http://192.168.233.128:5601 尝试搜索一下php的错误日志，比如mysql&lt;br /&gt;&lt;a href=&quot;http://img1.51cto.com/attachment/201303/133220759.jpg&quot; target=&quot;_blank&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://img1.51cto.com/attachment/201303/133220759.jpg&quot; width=&quot;650&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;呵呵，要的就是这个效果，日志会实时的汇总到 logstash index 上供我们查询，当然这只是开始使用logstash的第一步而已，更多的高级功能可以看看官方文档&lt;br /&gt;http://logstash.net/docs/1.1.9/&lt;br /&gt;&lt;br /&gt;出处：http://storysky.blog.51cto.com/628458/1158707</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/2718917270181202710/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/05/kibanalogstash.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/2718917270181202710'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/2718917270181202710'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/05/kibanalogstash.html' title='用Kibana和logstash快速搭建实时日志查询、收集与分析系统 '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-6279512720202278965</id><published>2013-05-20T15:22:00.003+10:00</published><updated>2013-05-20T15:22:24.603+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operating system"/><title type='text'>Kibana installation</title><content type='html'>&lt;br /&gt;&lt;h3&gt;kibana:&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;code style=&quot;background-color: #eeeeee; border: 1px solid rgb(204,204,204); font-family: Consolas,Monaco,&#39;DejaVu Sans Mono&#39;,monospace; font-style: inherit; outline: 0px;&quot;&gt;yum install rubygems ruby-devel make gcc gcc-c++&lt;/code&gt;&lt;/li&gt;&lt;li&gt;download kibana into  &lt;code style=&quot;background-color: #eeeeee; border: 1px solid rgb(204,204,204); font-family: Consolas,Monaco,&#39;DejaVu Sans Mono&#39;,monospace; font-style: inherit; outline: 0px;&quot;&gt;/opt&lt;/code&gt;&lt;/li&gt;&lt;li&gt;edit  &lt;code style=&quot;background-color: #eeeeee; border: 1px solid rgb(204,204,204); font-family: Consolas,Monaco,&#39;DejaVu Sans Mono&#39;,monospace; font-style: inherit; outline: 0px;&quot;&gt;KibanaConfig.rb&lt;/code&gt;:&lt;/li&gt;&lt;/ul&gt;&lt;div style=&quot;border-width: 1px;&quot;&gt;&lt;pre&gt;Elasticsearch = &quot;elasticsearch-lab:9200&quot;&lt;br /&gt;KibanaHost = &#39;10.10.10.7&#39;    # (kibana-host)&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;code style=&quot;background-color: #eeeeee; border: 1px solid rgb(204,204,204); font-family: Consolas,Monaco,&#39;DejaVu Sans Mono&#39;,monospace; font-style: inherit; outline: 0px;&quot;&gt;gem install bundler&lt;/code&gt;&lt;/li&gt;&lt;li&gt;&lt;code style=&quot;background-color: #eeeeee; border: 1px solid rgb(204,204,204); font-family: Consolas,Monaco,&#39;DejaVu Sans Mono&#39;,monospace; font-style: inherit; outline: 0px;&quot;&gt;bundle install&lt;/code&gt;&lt;/li&gt;&lt;li&gt;iptables allow inbound tcp:5601 (web interface)&lt;/li&gt;&lt;/ul&gt;Start with:&lt;br /&gt;  &lt;ul&gt;&lt;li&gt;&lt;code style=&quot;background-color: #eeeeee; border: 1px solid rgb(204,204,204); font-family: Consolas,Monaco,&#39;DejaVu Sans Mono&#39;,monospace; font-style: inherit; outline: 0px;&quot;&gt;ruby kibana.rb&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;Browse to: &lt;tt&gt;&lt;a href=&quot;http://kibana-host:5601/&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;http://kibana-host:5601/&lt;/a&gt;&lt;/tt&gt;&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/6279512720202278965/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/05/kibana-installation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/6279512720202278965'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/6279512720202278965'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/05/kibana-installation.html' title='Kibana installation'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-2818398270603830543</id><published>2013-05-20T12:26:00.001+10:00</published><updated>2013-05-20T12:26:04.605+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operating system"/><title type='text'>How to install Sun Java JDK in CentOS 6</title><content type='html'>&lt;br /&gt;But by default OpenJDK based java was installed in my system.&lt;br /&gt; &lt;blockquote&gt;[root@server2 sandbox]# java -version&lt;br /&gt;java version “1.6.0_17″&lt;br /&gt;OpenJDK Runtime Environment (IcedTea6 1.7.9) (rhel-1.36.b17.el6_0-x86_64)&lt;br /&gt;OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)&lt;/blockquote&gt;&lt;span id=&quot;more-352&quot;&gt;&lt;/span&gt;&lt;br /&gt; &lt;strong&gt;Step 1:&lt;/strong&gt; Donwload JDK from &lt;a href=&quot;http://www.java.com/&quot; rel=&quot;nofollow&quot;&gt;http://www.java.com&lt;/a&gt;. I got JDK version 7 in rpm format.&lt;br /&gt; &lt;blockquote&gt;mohamed@SilentStorm $ ls *.rpm&lt;br /&gt;jdk-7-linux-x64.rpm&lt;/blockquote&gt;&lt;strong&gt;Step 2:&lt;/strong&gt; Install the RPM.&lt;br /&gt; &lt;blockquote&gt;[root@server2 sandbox]# rpm -i jdk-7-linux-x64.rpm&lt;br /&gt;Unpacking JAR files…&lt;br /&gt;rt.jar…&lt;br /&gt;jsse.jar…&lt;br /&gt;charsets.jar…&lt;br /&gt;tools.jar…&lt;br /&gt;localedata.jar…&lt;/blockquote&gt;By default Java will be installed to &lt;strong&gt;&lt;em&gt;/usr/java/jdk1.7.0/&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt; &lt;strong&gt;Step 3:&lt;/strong&gt;&amp;nbsp; Add this new java to the alternatives configuration &amp;amp; Update the java alternatives&lt;br /&gt; &lt;blockquote&gt;[root@server2 sandbox]# alternatives &lt;strong&gt;- -&lt;/strong&gt;install /usr/bin/java java /usr/java/jdk1.7.0/bin/java 2&lt;br /&gt;[root@server2 sandbox]# alternatives&lt;strong&gt; – -&lt;/strong&gt;config java&lt;br /&gt; There are 3 programs which provide ‘java’.&lt;br /&gt; Selection Command&lt;br /&gt;———————————————–&lt;br /&gt;*+ 1 /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java&lt;br /&gt;2 /usr/lib/jvm/jre-1.5.0-gcj/bin/java&lt;br /&gt;&lt;strong&gt;3 /usr/java/jdk1.7.0/bin/java&lt;/strong&gt;&lt;br /&gt; Enter to keep the current selection[+], or type selection number: &lt;strong&gt;3&lt;/strong&gt;&lt;/blockquote&gt;&lt;strong&gt;Step 4&lt;/strong&gt;: Now verify the java version&lt;br /&gt; &lt;blockquote&gt;[root@server2 sandbox]# java -version&lt;br /&gt;java version “1.7.0″&lt;br /&gt;Java(TM) SE Runtime Environment (build 1.7.0-b147)&lt;br /&gt;Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)&lt;/blockquote&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/2818398270603830543/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/05/how-to-install-sun-java-jdk-in-centos-6.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/2818398270603830543'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/2818398270603830543'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/05/how-to-install-sun-java-jdk-in-centos-6.html' title='How to install Sun Java JDK in CentOS 6'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-9154781618900636812</id><published>2013-05-19T05:22:00.002+10:00</published><updated>2013-07-02T19:17:20.942+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operating system"/><title type='text'>ubuntu为什么没有/etc/inittab文件? 深究ubuntu的启动流程分析</title><content type='html'>&lt;br /&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Linux 内核启动 init ，init进程ID是1，是所有进程的父进程，所有进程由它控制。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Ubuntu 的启动由&lt;strong style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;upstart&lt;/strong&gt;控制，自9.10后不再使用/etc/event.d目录的配置文件，改为/etc/init。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;查看当前的运行级别，Ubuntu 桌面默认是2。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_837353&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;runlevel&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Ubuntu 的系统运行级别：&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_887826&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line number4 index3 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line number5 index4 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;5&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;0&lt;/code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;系统停机状态&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;1&lt;/code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;单用户或系统维护状态&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;2&lt;/code&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;~&lt;/code&gt;&lt;code class=&quot;actionscript3 value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;5&lt;/code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;多用户状态&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number4 index3 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;6&lt;/code&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;重新启动&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number5 index4 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;S&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;切换运行级别，执行命令：&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_594671&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;init [0123456Ss]&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;即在 init 命令后跟一个参数，此参数是要切换到的运行级的运行级代号，如：用 init 0 命令关机；用 init 6 命令重新启动。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;这就是我们的关机命令之一 $ sudo init 0 &amp;nbsp;的由来:&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_25127&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;$ sudo init &lt;/code&gt;&lt;code class=&quot;actionscript3 value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;0&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;查看系统当前运行等级：&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_109877&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;runlevel&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;h1 style=&quot;background-color: white; border: 0px; clear: both; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 22.390625px; margin: 0px 0px 0.7em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: black; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;查看系统在什么地方设置这个初始值，打开文件： （后面详细介绍为什么）&lt;/span&gt;&lt;/h1&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_399361&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;$ nano /etc/init/rc-sysinit.conf&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;h1 style=&quot;background-color: white; border: 0px; clear: both; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 22.390625px; margin: 0px 0px 0.7em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: black; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;你会发现这么一句： &amp;nbsp;&lt;/span&gt;&lt;/h1&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_740299&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;3&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;# Default runlevel, &lt;/code&gt;&lt;code class=&quot;actionscript3 keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: &#39;Courier New&#39; !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;this&lt;/code&gt; &lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;may be overriden on the kernel command-line&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;# or by faking an old /etc/inittab entry&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 spaces&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;env DEFAULT_RUNLEVEL=&lt;/code&gt;&lt;code class=&quot;actionscript3 value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;2&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;h1 style=&quot;background-color: white; border: 0px; clear: both; color: #333333; font-family: &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 18px; line-height: 22.390625px; margin: 0px 0px 0.7em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: red; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;Ubuntu init启动流程分析:&lt;/span&gt;&lt;/h1&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;现行的Linux distros主流的有两种init方式：一种是广为流传的System V initialization，它来源于Unix并且至今仍被各种Linux distros所采用；另一种是近几年提出的Upstart方式，基于事件机制，系统的所有服务，任务都是由事件驱动的。据我所知，采用后一种方式的目前有Ubuntu（6.10 and later），Fedora（9.10 and later），Debian（optional）。虽然采用Upstart的发行版并不多，但它旨在取代旧式的System V initialization。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;作为知识梳理，我现在就先在这里总结一下这两种方式各自的初始化流程，这也是为了方便整理思路：&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: red; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;之前在查找Linux系统init流程的相关资料时总是能够看到inittab的身影，但是在我的Ubuntu上是没有这个文件的，到后来才知道采用 Upstart方式的Ubuntu上是没有inittab这个文件的。在旧式的System V initialization中，/etc/inittab可是个相当重要的文件。init进程启动后第一时间找的就是它！inittab负责初始化系统，设置系统runlevel及进 入各runlevel对应要执行的命令。假设当前inittab中设置的默认runlevle是5，则init会运行/etc/init.d/rc 5命令，该命令会依据系统服务的依赖关系遍历执行/etc/rc5.d中的脚本/程序。进入/etc/rc5.d目录可以发现里面的文件都是到/etc /init.d/下对应的脚本/程序的软链接。以S开头的为启动的意思，以K开头的为停止。并且S/K后面的两位数数字代表了服务的启动顺序（由服务依赖关系决定）&lt;/span&gt;。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: red; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;【注】 &amp;nbsp;&lt;/span&gt;&amp;nbsp;网上查了一下， .d 文件的作用 ：&amp;nbsp;.d代表目录即文件夹的意思。/etc是存放配置文件的目录，配置文件有的是单独的，有的是一类，通常单独的配置文件后缀是.conf，一类的配置文件放在一个目录中，目录名就叫XX.d，XX指的是哪方面的配置文件，比如init.d就存放有关linux启动的配置文件。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;那么Upstart job是怎么样的呢？我们知道，System V initializaiton是以runlevel为核心，依据服务间依赖关系的init方式，但在Upstart job，runlevel虽说对于服务的启动也有影响但已不是关键所在。Upstart job是事件驱动的，系统服务的启动、&lt;span style=&quot;border: 0px; color: lime; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;停止等等均是由事件决定的&lt;/span&gt;，反过来，系统服务的启动、停止也可以作为事件源触发其他服务。并且事件并不一定得由系统内部产生&lt;span style=&quot;border: 0px; color: lime; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;，用户可以手工的键入start/stop [Service]产生事件来启动/终止服务。man upstart-evnets查看upstart job所定义的事件，可以发现，runlevel也被当作事件来对待（因runlevel的改变而产生的事件），诸如此类还有其他如 startup，started，filesystem等等。&lt;/span&gt;那么系统服务又是如何知道自己应该什么时候启动，什么时候终止的呢？答案就在于/etc /init中（有的distros可能是在/etc/event.d）。进入/etc/init目录下一看，均是系统服务的配置文件，或者说，是job definition files。（实际上Upstart init只需要/etc/init这么一个目录，不像System V init，“拐弯抹脚”转好多圈才到达目的地，在性能上不如前者）。随便打开一个文件，比如cron.conf：&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_332321&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;3&lt;/div&gt;&lt;div class=&quot;line number4 index3 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;4&lt;/div&gt;&lt;div class=&quot;line number5 index4 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;5&lt;/div&gt;&lt;div class=&quot;line number6 index5 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;6&lt;/div&gt;&lt;div class=&quot;line number7 index6 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;7&lt;/div&gt;&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;8&lt;/div&gt;&lt;div class=&quot;line number9 index8 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;9&lt;/div&gt;&lt;div class=&quot;line number10 index9 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;10&lt;/div&gt;&lt;div class=&quot;line number11 index10 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;11&lt;/div&gt;&lt;div class=&quot;line number12 index11 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;12&lt;/div&gt;&lt;div class=&quot;line number13 index12 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;13&lt;/div&gt;&lt;div class=&quot;line number14 index13 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;14&lt;/div&gt;&lt;div class=&quot;line number15 index14 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;15&lt;/div&gt;&lt;div class=&quot;line number16 index15 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;16&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 949px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;# cron - regular background program processing daemon&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;#&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;# cron &lt;/code&gt;&lt;code class=&quot;actionscript3 keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 102, 153) !important; float: none !important; font-family: &#39;Courier New&#39; !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;is&lt;/code&gt; &lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;a standard UNIX program that runs user-specified programs at&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number4 index3 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line number5 index4 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;# periodic scheduled times&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number6 index5 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line number7 index6 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;description &lt;/code&gt;&lt;code class=&quot;actionscript3 string&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: blue !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&quot;regular background program processing daemon&quot;&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number8 index7 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line number9 index8 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;start on runlevel [&lt;/code&gt;&lt;code class=&quot;actionscript3 value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;2345&lt;/code&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;]&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number10 index9 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;stop on runlevel [!&lt;/code&gt;&lt;code class=&quot;actionscript3 value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;2345&lt;/code&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;]&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number11 index10 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line number12 index11 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;expect fork&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number13 index12 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line number14 index13 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;respawn&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number15 index14 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;line number16 index15 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;exec cron&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;相信敏锐的程序猿们都发现了：start on runlevel [2345]；stop on runlevel [！2345]&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;没错，配置文件就是通过这个来设置服务何时启动，何时终止的。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;实际上并不仅仅在系统启动初期，&lt;span style=&quot;border: 0px; color: red; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;在系统运转的任何时期都可以通过发送事件来启动或终止服务。这便是Upstart job的优点之一，除了用于系统初始化，还可以在系统运行阶段发挥作用&lt;/span&gt;。&lt;span style=&quot;border: 0px; color: navy; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: lime; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;相比之下System V initialization方式下的配置文件一般只用于系统初始化阶段，当然系统运行阶段我们可以通过/etc/init.d/Service start/stop/otherCommand来操作服务，但很明显不如Upstart方式简洁明白&lt;/span&gt;。&lt;/span&gt;(如果你是linux 用户，你一定不陌生这些，一定很清楚。)&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;好，介绍完System V initialization和Upstart，那么现在就能介绍Ubuntu init系统初始化流程。前面提过Ubuntu使用的是Upstart方式的initialization，其实不全然，考虑到6.10之前的版本采用的System V init及某些服务的需要，Ubuntu采用的是兼容模式，即：系统中既有System V-style启动的服务，也有Upstart启动的服务。如果你使用的是Ubuntu11.04（我目前PC上的系统），那么你可以看到系统中有这么几个目录：&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_112563&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;3&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;/etc/init&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;/etc/init.d&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;/etc/rc${runlevel}.d&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;作为两种init方式各自特征的/etc/init.d，/etc/rc${runlevel}.d目录和/etc/init目录在Ubuntu中都有了，那么Ubuntu是如何实现兼容的？实际上，Ubuntu中并没有直接采用System V-style启动服务，要知道，Ubuntu中的init已被替换为Upstart init，而System V-style的服务是存放于/etc/rc${runlevel}.d目录中的，（而/etc/rc${runlevle}.d/下的文件是到/etc/init.d的软链接）可Upstart init并不会直接跑到这里面去启动服务。它是通过间接调用来启动这类服务的。&lt;span style=&quot;border: 0px; color: red; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;换句话说，Ubuntu中的init并不会直接奔着/etc/init.d或者/etc/rc${runlevel}.d/而去，它采用了折衷的办法，通过/etc/init下的某些配置文件调用/etc/rc${runlevel}.d/中的脚本以启动采用旧式System V-style的服务。&lt;/span&gt;（这是精髓）唉，说的我自己都觉得好绕，还是见实例吧，看下面。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;进入/etc/init目录（Upstart init会到该目录下读取配置文件），会发现几个跟rc有关的配置文件：&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_767105&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;2&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;3&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;rc.conf&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;rc-sysinit.conf&lt;/code&gt;&lt;/div&gt;&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;rcS.conf&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rc-sysinit在startup事件发生时被启动，rc在系统runlevel变化时被启动，rcS在系统runlevel为S时启动。在配置文件的注释中说明了，这几个文件，正是Upstart init处理System V-style服务的关键。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;rc-sysinit在startup事件发生时被启动，即，Upstart init会首先读取rc-sysinit.conf并执行相关配置和脚本。rc-sysinit.conf的主要工作是设置系统默认runlevel，检测是否存在/etc/inittab或内核命令行，若存在，则按内核命令行&amp;gt;/etc/inittab&amp;gt;默认runlevel的顺序设置系统 runlevel。最后，调用telinit进入设置的runlevel。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;由于调用了telinit进入了设定的runlevel，runlevel改变的事件发生，此时rc服务启动（当然其他服务也会）。那么，我们就有必要来看看rc.conf中到底有什么东西。打开rc.conf，注意到最后一行：&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; line-height: 22.390625px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;div class=&quot;syntaxhighlighter notranslate actionscript3&quot; id=&quot;highlighter_453539&quot; style=&quot;border: 0px; font-family: &#39;Courier New&#39; !important; font-size: 15px !important; margin: 1em 0px !important; outline: 0px; overflow-x: auto !important; overflow-y: hidden !important; padding: 1px !important; position: relative !important; vertical-align: baseline; width: 993.859375px;&quot;&gt;&lt;div class=&quot;toolbar&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: none !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; float: none !important; font-size: 10px !important; height: 11px !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: absolute !important; right: 1px !important; top: 1px !important; vertical-align: baseline !important; width: 11px !important; z-index: 10 !important;&quot;&gt;&lt;span style=&quot;border: 0px; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;a class=&quot;toolbar_item command_help help&quot; href=&quot;http://www.ginchenorlee.com/?p=315#&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: white !important; display: block !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 1px 0px 0px !important; position: static !important; right: auto !important; text-align: center !important; text-decoration: none !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;?&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-spacing: 0px; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 15px !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 993px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;gutter&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(175, 175, 175) !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-color: rgb(108, 226, 108) !important; border-bottom-color: green !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-style: solid !important; border-right-color: rgb(108, 226, 108) !important; border-right-style: solid !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-width: 0px 3px 1px 0px !important; bottom: auto !important; box-sizing: content-box !important; color: black; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 0.5em 0px 1em !important; position: static !important; right: auto !important; text-align: right !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;1&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 958px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre !important; width: auto !important;&quot;&gt;&lt;code class=&quot;actionscript3 plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: green !important; float: none !important; font-family: &#39;Courier New&#39; !important; height: auto !important; left: auto !important; line-height: 1.1em !important; margin: 0px !important; min-height: auto !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;exec /etc/init.d/rc $RUNLEVEL&lt;/code&gt;&lt;/div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;是不是感觉/etc/init.d/rc很熟悉，没错，在System V initialization中，/etc/inittab中的各runlevel对应的命令行就是通过这种形式设置的。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;很明显，/etc/init.d/rc被调用了，并且传入了早前设置好的系统runlevel作为参数。而/etc/init.d/rc会根据传入 的runlevel参数调用/etc/rc${runlevel}.d/下的脚本（以S开头）以启动服务，终止在前次runlevel启动而当前在 runlevel需要终止的服务。至此，Ubuntu处理System V-style服务的流程是不是渐渐明朗了。通过rc-sysinit和rc间接的调用/etc/init.d/rc从而启动System V-style服务，Ubuntu在采用新式Upstart init照顾了旧式的System V init。&lt;/div&gt;&lt;div style=&quot;background-color: white; border: 0px; color: #333333; font-family: &#39;Courier New&#39;, monospace; line-height: 26px; margin-bottom: 1.4em; outline: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;采用Upstart方式启动的服务则在/etc/init/目录中有属于自己的一份配置文件，终端下键入：initctl list，看看列出的服务是否同/etc/init/下的服务完全一致！&lt;br /&gt;&lt;br /&gt;Linux: /etc/inittab -&amp;gt; /etc/rc*.d -&amp;gt; /etc/init.d&lt;br /&gt;Ubuntu: /etc/init/*.conf -&amp;gt; /etc/rc*.d -&amp;gt; /etc/init.d&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/9154781618900636812/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/05/ubuntuetcinittab-ubuntu.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/9154781618900636812'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/9154781618900636812'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/05/ubuntuetcinittab-ubuntu.html' title='ubuntu为什么没有/etc/inittab文件? 深究ubuntu的启动流程分析'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-1304781504081018383</id><published>2013-05-14T21:24:00.002+10:00</published><updated>2013-05-14T21:24:52.762+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="software engineering"/><title type='text'>Installing Apache Archiva as a Web Application</title><content type='html'>&lt;a href=&quot;http://archiva.apache.org/docs/1.3.6/adminguide/webapp.html&quot;&gt;http://archiva.apache.org/docs/1.3.6/adminguide/webapp.html&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;https://cwiki.apache.org/confluence/display/ARCHIVA/Archiva+on+Tomcat&quot;&gt;https://cwiki.apache.org/confluence/display/ARCHIVA/Archiva+on+Tomcat&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/1304781504081018383/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/05/installing-apache-archiva-as-web.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/1304781504081018383'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/1304781504081018383'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/05/installing-apache-archiva-as-web.html' title='Installing Apache Archiva as a Web Application'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-5786561738120112781</id><published>2013-05-04T20:54:00.001+10:00</published><updated>2013-05-04T20:54:03.302+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>Clearing a Solr search index</title><content type='html'>&lt;br /&gt;&lt;div style=&quot;background-color: white; font-family: &#39;Istok Web&#39;, sans-serif; font-size: 16px;&quot;&gt;When developing a search project using&amp;nbsp;&lt;a href=&quot;http://lucene.apache.org/solr/&quot; style=&quot;color: blue; text-decoration: none;&quot; target=&quot;http://lucene.apache.org/solr/&quot;&gt;Apache Solr&lt;img class=&quot;externalLink&quot; src=&quot;http://www.alphadevx.com/alpha/images/icons/page_go.png&quot; style=&quot;border: none; margin: 0px; padding: 0px; vertical-align: bottom;&quot; /&gt;&lt;/a&gt;, you often need to clear out the search index and start again. A typical example of this is when you make a schema change. Luckily, there is an easy way to do this via the Solr REST API.&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: &#39;Istok Web&#39;, sans-serif; font-size: 16px;&quot;&gt;According to the official&amp;nbsp;&lt;a href=&quot;http://wiki.apache.org/solr/FAQ#How_can_I_delete_all_documents_from_my_index.3F&quot; style=&quot;color: blue; text-decoration: none;&quot; target=&quot;http://wiki.apache.org/solr/FAQ#How_can_I_delete_all_documents_from_my_index.3F&quot;&gt;Solr FAQ&lt;img class=&quot;externalLink&quot; src=&quot;http://www.alphadevx.com/alpha/images/icons/page_go.png&quot; style=&quot;border: none; margin: 0px; padding: 0px; vertical-align: bottom;&quot; /&gt;&lt;/a&gt;, you can clear out a Solr index by issuing the following query:&lt;/div&gt;&lt;pre style=&quot;background-color: white; font-size: 16px;&quot;&gt;&lt;code&gt;&lt;div class=&quot;luminous&quot; style=&quot;font-family: &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, VeraMono, &#39;Andale Mono&#39;, &#39;Lucida Sans Typewriter&#39;, FreeMono, &#39;Liberation Mono&#39;, Consolas, &#39;Lucida Console&#39;, monospace !important; font-size: inherit; line-height: 19px; max-width: 100%; min-width: 100%; position: relative !important;&quot;&gt;&lt;br /&gt;&lt;div class=&quot;code_container&quot; style=&quot;font-family: inherit !important; font-size: inherit !important; max-height: 500px; max-width: 100%; overflow: auto; position: relative !important; width: auto !important;&quot;&gt;&lt;br /&gt;&lt;table class=&quot;code_container&quot; style=&quot;border-collapse: collapse !important; border: 0px !important; font-family: inherit !important; font-size: inherit !important; margin: 0px !important; max-height: 100%; padding: 0px !important; width: 908px;&quot;&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;td class=&quot;line_number_bar&quot; style=&quot;background-color: rgb(224, 224, 224) !important; border-right-color: black !important; border-right-style: solid !important; border-width: 0px 1px 0px 0px !important; font-size: 8pt; padding: 0px !important; text-align: right !important; vertical-align: top !important;&quot;&gt;&lt;pre class=&quot;line_numbers&quot; style=&quot;background-image: none !important; font-family: inherit !important; font-size: inherit !important; max-height: 100%; overflow: hidden; padding: 0px !important; position: relative; width: auto !important;&quot;&gt;&lt;a class=&quot;line_number&quot; href=&quot;&quot; id=&quot;lineno_1527890052_1&quot;&gt;&lt;span class=&quot;line_number&quot; style=&quot;margin: 0px !important; text-align: center !important;&quot;&gt;&amp;nbsp;1&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-color: rgb(252, 252, 252) !important; border: 0px !important; font-size: 8pt; padding: 0px !important; vertical-align: top !important; width: 886px;&quot;&gt;&lt;pre class=&quot;code&quot; style=&quot;background-image: none !important; font-family: inherit !important; font-size: inherit !important; max-height: 100%; overflow: hidden; padding: 0px !important; position: relative; width: auto !important;&quot;&gt;&lt;span class=&quot;line&quot; id=&quot;line_1527890052_1&quot; style=&quot;border: 0px; display: block; font-size: inherit; margin: 0px; padding: 0px 0px 0px 1em;&quot;&gt;&amp;lt;&lt;span class=&quot;htmltag&quot; style=&quot;color: purple !important; font-weight: bold !important;&quot;&gt;delete&lt;/span&gt;&amp;gt;&amp;lt;&lt;span class=&quot;htmltag&quot; style=&quot;color: purple !important; font-weight: bold !important;&quot;&gt;query&lt;/span&gt;&amp;gt;*:*&amp;lt;&lt;span class=&quot;htmltag&quot; style=&quot;color: purple !important; font-weight: bold !important;&quot;&gt;/query&lt;/span&gt;&amp;gt;&amp;lt;&lt;span class=&quot;htmltag&quot; style=&quot;color: purple !important; font-weight: bold !important;&quot;&gt;/delete&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: white; font-family: &#39;Istok Web&#39;, sans-serif; font-size: 16px;&quot;&gt;To run this query, you can issue it via the REST API using curl:&lt;/div&gt;&lt;pre style=&quot;background-color: white; font-size: 16px;&quot;&gt;&lt;code&gt;&lt;div class=&quot;luminous&quot; style=&quot;font-family: &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, VeraMono, &#39;Andale Mono&#39;, &#39;Lucida Sans Typewriter&#39;, FreeMono, &#39;Liberation Mono&#39;, Consolas, &#39;Lucida Console&#39;, monospace !important; font-size: inherit; line-height: 19px; max-width: 100%; min-width: 100%; position: relative !important;&quot;&gt;&lt;br /&gt;&lt;div class=&quot;code_container&quot; style=&quot;font-family: inherit !important; font-size: inherit !important; max-height: 500px; max-width: 100%; overflow: auto; position: relative !important; width: auto !important;&quot;&gt;&lt;br /&gt;&lt;table class=&quot;code_container&quot; style=&quot;border-collapse: collapse !important; border: 0px !important; font-family: inherit !important; font-size: inherit !important; margin: 0px !important; max-height: 100%; padding: 0px !important; width: 908px;&quot;&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;td class=&quot;line_number_bar&quot; style=&quot;background-color: rgb(224, 224, 224) !important; border-right-color: black !important; border-right-style: solid !important; border-width: 0px 1px 0px 0px !important; font-size: 8pt; padding: 0px !important; text-align: right !important; vertical-align: top !important;&quot;&gt;&lt;pre class=&quot;line_numbers&quot; style=&quot;background-image: none !important; font-family: inherit !important; font-size: inherit !important; max-height: 100%; overflow: hidden; padding: 0px !important; position: relative; width: auto !important;&quot;&gt;&lt;a class=&quot;line_number&quot; href=&quot;&quot; id=&quot;lineno_2096842626_1&quot;&gt;&lt;span class=&quot;line_number&quot; style=&quot;margin: 0px !important; text-align: center !important;&quot;&gt;&amp;nbsp;1&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/a&gt;&lt;a class=&quot;line_number&quot; href=&quot;&quot; id=&quot;lineno_2096842626_2&quot;&gt;&lt;span class=&quot;line_number&quot; style=&quot;margin: 0px !important; text-align: center !important;&quot;&gt;&amp;nbsp;2&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-color: rgb(252, 252, 252) !important; border: 0px !important; font-size: 8pt; padding: 0px !important; vertical-align: top !important; width: 886px;&quot;&gt;&lt;pre class=&quot;code&quot; style=&quot;background-image: none !important; font-family: inherit !important; font-size: inherit !important; max-height: 100%; overflow: hidden; padding: 0px !important; position: relative; width: auto !important;&quot;&gt;&lt;span class=&quot;line&quot; id=&quot;line_2096842626_1&quot; style=&quot;border: 0px; display: block; font-size: inherit; margin: 0px; padding: 0px 0px 0px 1em;&quot;&gt;curl http://localhost:&lt;span class=&quot;numeric&quot; style=&quot;color: blue !important;&quot;&gt;8080&lt;/span&gt;/solr/update -H &lt;span class=&quot;string&quot; style=&quot;background-color: rgba(255, 157, 157, 0.2) !important; color: red !important;&quot;&gt;&quot;Content-type: text/xml&quot;&lt;/span&gt; \&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;line line_alt&quot; id=&quot;line_2096842626_2&quot; style=&quot;background-color: #f3f3f3; border: 0px; display: block; font-size: inherit; margin: 0px; padding: 0px 0px 0px 1em;&quot;&gt;--data-binary &lt;span class=&quot;string&quot; style=&quot;background-color: rgba(255, 157, 157, 0.2) !important; color: red !important;&quot;&gt;&#39;&lt;delete&gt;&lt;query&gt;*:*&lt;/query&gt;&lt;/delete&gt;&#39;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: white; font-family: &#39;Istok Web&#39;, sans-serif; font-size: 16px;&quot;&gt;Note that you will also need to tell Solr to commit this change:&lt;/div&gt;&lt;pre style=&quot;background-color: white; font-size: 16px;&quot;&gt;&lt;code&gt;&lt;div class=&quot;luminous&quot; style=&quot;font-family: &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, VeraMono, &#39;Andale Mono&#39;, &#39;Lucida Sans Typewriter&#39;, FreeMono, &#39;Liberation Mono&#39;, Consolas, &#39;Lucida Console&#39;, monospace !important; font-size: inherit; line-height: 19px; max-width: 100%; min-width: 100%; position: relative !important;&quot;&gt;&lt;br /&gt;&lt;div class=&quot;code_container&quot; style=&quot;font-family: inherit !important; font-size: inherit !important; max-height: 500px; max-width: 100%; overflow: auto; position: relative !important; width: auto !important;&quot;&gt;&lt;br /&gt;&lt;table class=&quot;code_container&quot; style=&quot;border-collapse: collapse !important; border: 0px !important; font-family: inherit !important; font-size: inherit !important; margin: 0px !important; max-height: 100%; padding: 0px !important; width: 908px;&quot;&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;td class=&quot;line_number_bar&quot; style=&quot;background-color: rgb(224, 224, 224) !important; border-right-color: black !important; border-right-style: solid !important; border-width: 0px 1px 0px 0px !important; font-size: 8pt; padding: 0px !important; text-align: right !important; vertical-align: top !important;&quot;&gt;&lt;pre class=&quot;line_numbers&quot; style=&quot;background-image: none !important; font-family: inherit !important; font-size: inherit !important; max-height: 100%; overflow: hidden; padding: 0px !important; position: relative; width: auto !important;&quot;&gt;&lt;a class=&quot;line_number&quot; href=&quot;&quot; id=&quot;lineno_1376245147_1&quot;&gt;&lt;span class=&quot;line_number&quot; style=&quot;margin: 0px !important; text-align: center !important;&quot;&gt;&amp;nbsp;1&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/a&gt;&lt;a class=&quot;line_number&quot; href=&quot;&quot; id=&quot;lineno_1376245147_2&quot;&gt;&lt;span class=&quot;line_number&quot; style=&quot;margin: 0px !important; text-align: center !important;&quot;&gt;&amp;nbsp;2&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-color: rgb(252, 252, 252) !important; border: 0px !important; font-size: 8pt; padding: 0px !important; vertical-align: top !important; width: 886px;&quot;&gt;&lt;pre class=&quot;code&quot; style=&quot;background-image: none !important; font-family: inherit !important; font-size: inherit !important; max-height: 100%; overflow: hidden; padding: 0px !important; position: relative; width: auto !important;&quot;&gt;&lt;span class=&quot;line&quot; id=&quot;line_1376245147_1&quot; style=&quot;border: 0px; display: block; font-size: inherit; margin: 0px; padding: 0px 0px 0px 1em;&quot;&gt;curl http://localhost:&lt;span class=&quot;numeric&quot; style=&quot;color: blue !important;&quot;&gt;8080&lt;/span&gt;/solr/update -H &lt;span class=&quot;string&quot; style=&quot;background-color: rgba(255, 157, 157, 0.2) !important; color: red !important;&quot;&gt;&quot;Content-type: text/xml&quot;&lt;/span&gt; \&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;line line_alt&quot; id=&quot;line_1376245147_2&quot; style=&quot;background-color: #f3f3f3; border: 0px; display: block; font-size: inherit; margin: 0px; padding: 0px 0px 0px 1em;&quot;&gt;--data-binary &lt;span class=&quot;string&quot; style=&quot;background-color: rgba(255, 157, 157, 0.2) !important; color: red !important;&quot;&gt;&#39;&lt;commit&gt;&#39;&lt;/commit&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: white; font-family: &#39;Istok Web&#39;, sans-serif; font-size: 16px;&quot;&gt;...and it is also a good idea to tell Solr to optimize it&#39;s index at this point:&lt;/div&gt;&lt;pre style=&quot;background-color: white; font-size: 16px;&quot;&gt;&lt;code&gt;&lt;div class=&quot;luminous&quot; style=&quot;font-family: &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, VeraMono, &#39;Andale Mono&#39;, &#39;Lucida Sans Typewriter&#39;, FreeMono, &#39;Liberation Mono&#39;, Consolas, &#39;Lucida Console&#39;, monospace !important; font-size: inherit; line-height: 19px; max-width: 100%; min-width: 100%; position: relative !important;&quot;&gt;&lt;br /&gt;&lt;div class=&quot;code_container&quot; style=&quot;font-family: inherit !important; font-size: inherit !important; max-height: 500px; max-width: 100%; overflow: auto; position: relative !important; width: auto !important;&quot;&gt;&lt;br /&gt;&lt;table class=&quot;code_container&quot; style=&quot;border-collapse: collapse !important; border: 0px !important; font-family: inherit !important; font-size: inherit !important; margin: 0px !important; max-height: 100%; padding: 0px !important; width: 908px;&quot;&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;&lt;td class=&quot;line_number_bar&quot; style=&quot;background-color: rgb(224, 224, 224) !important; border-right-color: black !important; border-right-style: solid !important; border-width: 0px 1px 0px 0px !important; font-size: 8pt; padding: 0px !important; text-align: right !important; vertical-align: top !important;&quot;&gt;&lt;pre class=&quot;line_numbers&quot; style=&quot;background-image: none !important; font-family: inherit !important; font-size: inherit !important; max-height: 100%; overflow: hidden; padding: 0px !important; position: relative; width: auto !important;&quot;&gt;&lt;a class=&quot;line_number&quot; href=&quot;&quot; id=&quot;lineno_829355005_1&quot;&gt;&lt;span class=&quot;line_number&quot; style=&quot;margin: 0px !important; text-align: center !important;&quot;&gt;&amp;nbsp;1&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/a&gt;&lt;a class=&quot;line_number&quot; href=&quot;&quot; id=&quot;lineno_829355005_2&quot;&gt;&lt;span class=&quot;line_number&quot; style=&quot;margin: 0px !important; text-align: center !important;&quot;&gt;&amp;nbsp;2&amp;nbsp;&lt;br /&gt;&lt;/span&gt;&lt;/a&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot; style=&quot;background-color: rgb(252, 252, 252) !important; border: 0px !important; font-size: 8pt; padding: 0px !important; vertical-align: top !important; width: 886px;&quot;&gt;&lt;pre class=&quot;code&quot; style=&quot;background-image: none !important; font-family: inherit !important; font-size: inherit !important; max-height: 100%; overflow: hidden; padding: 0px !important; position: relative; width: auto !important;&quot;&gt;&lt;span class=&quot;line&quot; id=&quot;line_829355005_1&quot; style=&quot;border: 0px; display: block; font-size: inherit; margin: 0px; padding: 0px 0px 0px 1em;&quot;&gt;curl http://localhost:&lt;span class=&quot;numeric&quot; style=&quot;color: blue !important;&quot;&gt;8080&lt;/span&gt;/solr/update -H &lt;span class=&quot;string&quot; style=&quot;background-color: rgba(255, 157, 157, 0.2) !important; color: red !important;&quot;&gt;&quot;Content-type: text/xml&quot;&lt;/span&gt; \&lt;br /&gt;&lt;/span&gt;&lt;span class=&quot;line line_alt&quot; id=&quot;line_829355005_2&quot; style=&quot;background-color: #f3f3f3; border: 0px; display: block; font-size: inherit; margin: 0px; padding: 0px 0px 0px 1em;&quot;&gt;--data-binary &lt;span class=&quot;string&quot; style=&quot;background-color: rgba(255, 157, 157, 0.2) !important; color: red !important;&quot;&gt;&#39;&lt;optimize&gt;&#39;&lt;/optimize&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: white; font-family: &#39;Istok Web&#39;, sans-serif; font-size: 16px;&quot;&gt;To confirm that your index is now empty, load up the Solr admin web interface in your browser, and click on the&amp;nbsp;&lt;em&gt;statistics&lt;/em&gt;link. You should now see that the number of documents listed in your index is now zero.&lt;/div&gt;&lt;div style=&quot;background-color: white; font-family: &#39;Istok Web&#39;, sans-serif; font-size: 16px;&quot;&gt;Note that the final optimize command is passed to Solr to tell it to physically remove the deleted documents, which will not only free up disc space, but will also increase search performance. Following the above procedure of delete/commit/optimize will ensure that you start off with a clean slate each time.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/5786561738120112781/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/05/clearing-solr-search-index.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/5786561738120112781'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/5786561738120112781'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/05/clearing-solr-search-index.html' title='Clearing a Solr search index'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-4991383650746273047</id><published>2013-04-27T07:28:00.000+10:00</published><updated>2013-04-27T07:28:08.686+10:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Sport"/><title type='text'>跑步新手如何开始你的跑步训练</title><content type='html'>&lt;br /&gt;&lt;div class=&quot;exp-content-block exp-content-block-1&quot; style=&quot;background-color: white; color: #333333; font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px;&quot;&gt;&lt;div class=&quot;exp-content-body&quot; style=&quot;margin-top: 5px; text-align: justify;&quot;&gt;&lt;div class=&quot;exp-content-listblock&quot;&gt;&lt;div class=&quot;content-listblock-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;在任何运动中获得成功，你必须遵循一些基本规则。例如，高尔夫中要低头，网球中要保持从始到终的正确姿势，而跑步则是：正确训练，而不是过度训练。&lt;/div&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;content-listblock-media&quot; style=&quot;text-align: center;&quot;&gt;&lt;div class=&quot;content-listblock-image&quot;&gt;&lt;img alt=&quot;跑步新手如何开始你的跑步训练&quot; class=&quot;exp-image-default&quot; src=&quot;http://a.hiphotos.baidu.com/exp/w=500/sign=51c71eb9b80e7bec23da03e11f2fb9fa/9358d109b3de9c82b99ef3396c81800a18d84388.jpg&quot; style=&quot;border: 1.5px solid rgb(255, 255, 255);&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;exp-content-block exp-content-block-2&quot; style=&quot;background-color: white; color: #333333; font-family: arial, 宋体, sans-serif; font-size: 14px; line-height: 24px;&quot;&gt;&lt;h2 class=&quot;exp-content-head&quot; style=&quot;border-bottom-color: rgb(241, 241, 241); border-bottom-style: solid; border-bottom-width: 1px; font-family: &#39;microsoft yahei&#39;; font-size: 16px; height: 30px; line-height: 30px; margin: 40px 0px 0px; padding: 0px;&quot;&gt;步骤/方法&lt;/h2&gt;&lt;div class=&quot;exp-content-body&quot; style=&quot;margin-top: 5px; text-align: justify;&quot;&gt;&lt;ol class=&quot;exp-conent-orderlist&quot; style=&quot;clear: both; list-style: none; margin: 0px; padding: 0px;&quot;&gt;&lt;li class=&quot;exp-content-list-under20 list-item-1&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: 0px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;跑步永远不会太迟。如果你决定开始跑步了，那这对你来说是件好事。因为不管你年龄多大，跑步都是有益处的。有规律的锻炼能够使人更有活力、降低患心脏病和癌症的几率、减肥、睡眠更好等等。因此，什么时候开始跑步都不晚。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-2&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -32px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;慢慢来。有些人不跑步是因为他们不知道怎么开始。新手的跑步计划应该将走和跑都包括在内。刚开始时，尤其是没有接受过任何训练时，不能跑太远，因为这样受伤的风险很大，对身体健康也不利。所以慢慢来，几周内你就能有很大进步。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-3&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -64px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;使用计时器。假如你要进行3分钟跑加1分钟走的间歇跑，你就可以在间隔计时器上，将两个时间同时分别设定好，然后将计时器夹在裤子上，它会震动或响铃来提醒你时间到。这样你就不用老分散注意力看表了。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-4&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -96px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;测心率。很多新手在开始跑步后会经常称体重，然而他们经常忘记测心率。跑步对心脑血管有好处。心脏向全身输送血液，经过适当锻炼，每一次心跳为身体注入的血液也会增加，此时你就会需要较少的心跳次数来为锻炼提供足够的血液。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-5&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -128px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;记跑步日记。写日记是很好的记录进步的方式。你可以记录下跑步的基本信息，如距离、时间、跑步类型，还可以有规律地记录体重和心率变化。看到自己跑步距离不断增加、体重和心率不断减缓会使自己越发有动力将跑步进行下去。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-6&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -160px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;听从身体的反应。跑完步会感觉疲劳和肌肉酸痛，这在一定程度上说，是很正常的。然而，如果在跑步中或跑步后感觉眩晕或胸部、背部、腿部不适，那就要小心了。这时要立即停止跑步，休息或走一会，直到恢复。如果不适感持续或感觉不放心，可以咨询医生。听从身体的召唤，做自己的教练。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-7&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -192px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;起步阶段保持低强度锻炼。新手出现问题的一个主要原因是开始时强度太大。他们定好跑步路线以后，每跑一次都会计时，把注意力都放在速度上。如果你是新手，最好慢慢开始，因为快跑对身体压力很大，太早进行快跑会很容易受伤。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-8&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -224px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;有规律的锻炼是进步的关键。如果是为强身健体而跑的话，最好是一周跑三或四次，一次30分钟，不要一周只跑一次，一次跑2个小时。跑步计划要有规律，并循序渐进。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-9&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -256px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;如果体重下降不明显，不要灰心。如果你选择跑步减肥的话，恭喜你选择了最好的减肥方法之一。但要注意可能不会立马就有效果，因为肌肉比脂肪重，适当的锻炼会减少赘肉，增加肌肉，因此有时可能会增加体重。但看上去会更瘦，穿衣效果也更好些。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-10&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -288px 0px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;合理搭配饮食。体重超标往往是由锻炼不足和不良饮食习惯造成的。所以花点时间研究下怎样提高饮食质量。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-11&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: 0px -32px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;热身与冷却。热身运动很重要，因为它能让身体做好锻炼的准备，心脏和腿及时做出调整。因此，不要一出门就快跑，先花几分钟时间走和慢跑，然后做伸展动作。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-12&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -32px -32px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;交叉训练。跑步是项很好的运动。然而，跑步过程中腿部承受巨大冲击力。每迈出一步，腿部承受的冲击力都是自身体重的两三倍。因此，最好加入其它锻炼方式，如骑自行车、游泳、散步、普拉提等等，缓解腿部所受冲击力同时增强腿部受力能力。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;li class=&quot;exp-content-list-under20 list-item-13&quot; style=&quot;height: auto; margin: 0px; min-height: 20px; padding: 1px 0px 22px 42px !important; position: relative; zoom: 1;&quot;&gt;&lt;div class=&quot;list-icon&quot; style=&quot;background-image: url(http://img.baidu.com/img/iknow/exp/global/exp_item_num_under20.png); background-position: -64px -32px; background-repeat: no-repeat no-repeat; height: 32px; left: 0px; position: absolute; top: 3px; width: 32px;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;content-list-text&quot;&gt;&lt;div style=&quot;margin-bottom: 6px; margin-top: 6px; padding: 0px;&quot;&gt;保持动力。跑步最难的就是坚持。可以找个跑友一起，这样为不让朋友失望你会坚持出来跑步，而且朋友还能帮你设定和实现目标。还可以报名参加比赛，来督促自己坚持训练计划。&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/4991383650746273047/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2013/04/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/4991383650746273047'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/4991383650746273047'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2013/04/blog-post.html' title='跑步新手如何开始你的跑步训练'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-7825730608824595414</id><published>2012-12-28T16:35:00.002+11:00</published><updated>2012-12-28T16:41:50.341+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>INSTALLING APACHE SOLR ON TOMCAT</title><content type='html'>&lt;a href=&quot;http://contextllc.com/node/76&quot;&gt;http://contextllc.com/node/76&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/7825730608824595414/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2012/12/installing-apache-solr-on-tomcat.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/7825730608824595414'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/7825730608824595414'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2012/12/installing-apache-solr-on-tomcat.html' title='INSTALLING APACHE SOLR ON TOMCAT'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-5888557134083032907</id><published>2012-12-16T00:02:00.002+11:00</published><updated>2012-12-16T00:02:19.609+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operating system"/><title type='text'>通过xinetd启动SSH服务</title><content type='html'>&lt;br /&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;作为例子，本节将带领读者配置SSH服务的xinetd实现。总的来说，在xinetd中添加服务无非是下面这几步：&lt;/div&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;（1）修改（增加）配置文件；&lt;/div&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;（2）停用该服务的守护进程；&lt;/div&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;（3）重启xinetd使配置生效；&lt;/div&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;（4）如果需要，从相应的rc目录中移除该服务的启动脚本。&lt;/div&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;下面就来逐一实现以上各个步骤。首先在/etc/xinetd.d目录下建立文件ssh，包含下面这些内容。&lt;/div&gt;&lt;pre style=&quot;background-color: #e6e6e6; color: #333333; font-family: &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 28px; margin-bottom: 1em; overflow: auto; padding: 0px; width: 591.0166625976563px;&quot;&gt;&lt;ol class=&quot;dp-xml&quot; style=&quot;background-color: #f7f7f7; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin-bottom: 1px !important; margin-left: 55px; margin-right: 0px !important; margin-top: 0px !important; padding: 5px 0px; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;service&amp;nbsp;ssh &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;{ &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute&quot; style=&quot;background-color: inherit; border: none; color: red; margin: 0px; padding: 0px;&quot;&gt;socket_type&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute-value&quot; style=&quot;background-color: inherit; border: none; color: blue; margin: 0px; padding: 0px;&quot;&gt;stream&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute&quot; style=&quot;background-color: inherit; border: none; color: red; margin: 0px; padding: 0px;&quot;&gt;protocol&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute-value&quot; style=&quot;background-color: inherit; border: none; color: blue; margin: 0px; padding: 0px;&quot;&gt;tcp&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute&quot; style=&quot;background-color: inherit; border: none; color: red; margin: 0px; padding: 0px;&quot;&gt;wait&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute-value&quot; style=&quot;background-color: inherit; border: none; color: blue; margin: 0px; padding: 0px;&quot;&gt;no&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute&quot; style=&quot;background-color: inherit; border: none; color: red; margin: 0px; padding: 0px;&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute-value&quot; style=&quot;background-color: inherit; border: none; color: blue; margin: 0px; padding: 0px;&quot;&gt;root&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute&quot; style=&quot;background-color: inherit; border: none; color: red; margin: 0px; padding: 0px;&quot;&gt;server&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;/usr/sbin/sshd &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute&quot; style=&quot;background-color: inherit; border: none; color: red; margin: 0px; padding: 0px;&quot;&gt;server_args&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;-i &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;log_on_success&amp;nbsp;&amp;nbsp;+=&amp;nbsp;DURATION &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute&quot; style=&quot;background-color: inherit; border: none; color: red; margin: 0px; padding: 0px;&quot;&gt;disable&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;=&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;attribute-value&quot; style=&quot;background-color: inherit; border: none; color: blue; margin: 0px; padding: 0px;&quot;&gt;no&lt;/span&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;}&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;注意log_on_success参数允许使用&quot;+=&quot;这样的赋值方式，表示在原有默认值的基础上添加，而不是推倒重来。类似地，也可以使用&quot;-=&quot;在默认值的基础上减去一些值。参数的默认值通常在/etc/xinetd.conf中设置。&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;&lt;span style=&quot;font-family: Courier New;&quot;&gt;下一步停用SSH守护进程，为xinetd接管22端口铺平道路。&lt;/span&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: #e6e6e6; color: #333333; font-family: &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 28px; margin-bottom: 1em; overflow: auto; padding: 0px; width: 591.0166625976563px;&quot;&gt;&lt;ol class=&quot;dp-xml&quot; style=&quot;background-color: #f7f7f7; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin-bottom: 1px !important; margin-left: 55px; margin-right: 0px !important; margin-top: 0px !important; padding: 5px 0px; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;$&amp;nbsp;sudo&amp;nbsp;/etc/init.d/ssh&amp;nbsp;stop &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;*&amp;nbsp;Stopping&amp;nbsp;OpenBSD&amp;nbsp;Secure&amp;nbsp;Shell&amp;nbsp;server&amp;nbsp;sshd&amp;nbsp;&amp;nbsp;&lt;br /&gt;[&amp;nbsp;OK&amp;nbsp;]&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;重新启动xinetd使配置生效。&lt;/div&gt;&lt;pre style=&quot;background-color: #e6e6e6; color: #333333; font-family: &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 28px; margin-bottom: 1em; overflow: auto; padding: 0px; width: 591.0166625976563px;&quot;&gt;&lt;ol class=&quot;dp-xml&quot; style=&quot;background-color: #f7f7f7; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin-bottom: 1px !important; margin-left: 55px; margin-right: 0px !important; margin-top: 0px !important; padding: 5px 0px; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;$&amp;nbsp;sudo&amp;nbsp;/etc/init.d/xinetd&amp;nbsp;restart &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;*&amp;nbsp;Stopping&amp;nbsp;internet&amp;nbsp;superserver&amp;nbsp;xinetd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;[&amp;nbsp;OK&amp;nbsp;]&amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;&amp;nbsp;*&amp;nbsp;Starting&amp;nbsp;internet&amp;nbsp;superserver&amp;nbsp;xinetd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;[&amp;nbsp;OK&amp;nbsp;]&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;运行netstat -tulnp命令查看22端口的情况，发现xinetd已经顺利接管了SSH通信端口。&lt;/div&gt;&lt;pre style=&quot;background-color: #e6e6e6; color: #333333; font-family: &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 28px; margin-bottom: 1em; overflow: auto; padding: 0px; width: 591.0166625976563px;&quot;&gt;&lt;ol class=&quot;dp-xml&quot; style=&quot;background-color: #f7f7f7; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin-bottom: 1px !important; margin-left: 55px; margin-right: 0px !important; margin-top: 0px !important; padding: 5px 0px; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;$&amp;nbsp;sudo&amp;nbsp;netstat&amp;nbsp;-tulnp&amp;nbsp;|&amp;nbsp;grep&amp;nbsp;22&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;##查看22端口状态 &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;tcp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&amp;nbsp;0.0.0.0:22&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;0.0.0.0:*&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;LISTEN&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8356/xinetd&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;现在尝试连接本地的SSH服务。对于客户端而言，看上去和standalone方式没有什么不同。&lt;/div&gt;&lt;pre style=&quot;background-color: #e6e6e6; color: #333333; font-family: &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 28px; margin-bottom: 1em; overflow: auto; padding: 0px; width: 591.0166625976563px;&quot;&gt;&lt;ol class=&quot;dp-xml&quot; style=&quot;background-color: #f7f7f7; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin-bottom: 1px !important; margin-left: 55px; margin-right: 0px !important; margin-top: 0px !important; padding: 5px 0px; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;$&amp;nbsp;ssh&amp;nbsp;localhost&amp;nbsp;-l&amp;nbsp;lewis &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;lewis@localhost&#39;s&amp;nbsp;password:&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;如果在安装SSH服务器的时候选择了随系统启动（通常这是默认配置），那么接下来还要从相应的rc目录中移除SSH服务的启动脚本，否则下次启动系统的时候xinetd将无法运行。假设系统默认启动到运行级5（可以参考22.1节获取有关运行级的详细信息）。&lt;/div&gt;&lt;pre style=&quot;background-color: #e6e6e6; color: #333333; font-family: &#39;Courier New&#39;, monospace; font-size: 12px; line-height: 28px; margin-bottom: 1em; overflow: auto; padding: 0px; width: 591.0166625976563px;&quot;&gt;&lt;ol class=&quot;dp-xml&quot; style=&quot;background-color: #f7f7f7; border: none; color: #5c5c5c; list-style-image: initial; list-style-position: initial; margin-bottom: 1px !important; margin-left: 55px; margin-right: 0px !important; margin-top: 0px !important; padding: 5px 0px; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;$&amp;nbsp;cd&amp;nbsp;/etc/rc5.d/&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;##进入相应的rc目录 &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;$&amp;nbsp;ls&amp;nbsp;|&amp;nbsp;grep&amp;nbsp;ssh&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br /&gt;##查找SSH启动脚本 &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li class=&quot;alt&quot; style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; color: inherit; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;S16ssh &amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;li style=&quot;background-attachment: scroll; background-color: transparent; background-image: url(http://images.51cto.com/images/art1105/images/0.gif); background-position: -498px -70px; background-repeat: no-repeat repeat; border: none; line-height: 18px; list-style: none; margin: 0px !important; padding: 0px 3px 0px 10px !important; word-break: normal; word-wrap: break-word;&quot;&gt;&lt;span style=&quot;background-color: inherit; border: none; color: black; margin: 0px; padding: 0px;&quot;&gt;$&amp;nbsp;sudo&amp;nbsp;mv&amp;nbsp;S16ssh&amp;nbsp;../rc_bak.d/S16ssh_rc5_bak&amp;nbsp;&lt;br /&gt;##移动到另一个地方备份起来&amp;nbsp;&lt;/span&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;/pre&gt;&lt;div style=&quot;background-color: #f8f8f8; color: #333333; font-family: 宋体; font-size: 14px; line-height: 28px; margin-bottom: 10px; margin-top: 10px; padding: 0px; text-indent: 28px;&quot;&gt;注意：不要随便删除启动脚本，而应该把它移动到另一个地方，并且取一个有意义的名字。这样在以后需要的时候可以方便地找回来。&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/5888557134083032907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2012/12/xinetdssh.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/5888557134083032907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/5888557134083032907'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2012/12/xinetdssh.html' title='通过xinetd启动SSH服务'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-3910488995695241598</id><published>2012-12-15T18:40:00.002+11:00</published><updated>2012-12-16T00:02:31.599+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operating system"/><title type='text'>Linux利用外部邮箱发送邮件的方法</title><content type='html'>&lt;strong style=&quot;font-family: 宋体, &#39;Arial Narrow&#39;, arial, serif; font-size: 14px; line-height: 28px; margin: 0px; padding: 0px;&quot;&gt;利用外部邮箱发送邮件的方法&lt;/strong&gt;&lt;br /&gt;&lt;div style=&quot;font-family: 宋体, &#39;Arial Narrow&#39;, arial, serif; font-size: 14px; line-height: 28px; margin: 0px; padding: 0px;&quot;&gt;bin/mail会默认使用本地sendmail发送邮件，这样要求本地的机器必须安装和启动Sendmail服务，配置非常麻烦，而且会带来不必要的&lt;br /&gt;资源占用。而通过修改配置文件可以使用外部SMTP服务器，可以达到不使用sendmail而用外部的smtp服务器发送邮件的目的：&lt;br /&gt;修改/etc/nail.rc (/etc/mail.rc)&lt;br /&gt;set from=fromUser@domain.com smtp=smtp.domain.comset smtp-auth-user=username smtp-auth-password=passwordset smtp-auth=login&lt;br /&gt;说明：&lt;br /&gt;from是发送的邮件地址&lt;br /&gt;smtp是发生的外部smtp服务器的地址&lt;br /&gt;smtp-auth-user是外部smtp服务器认证的用户名&lt;br /&gt;smtp-auth-password是外部smtp服务器认证的用户密码&lt;br /&gt;smtp-auth是邮件认证的方式&lt;br /&gt;配置成功后，就可以使用了&lt;br /&gt;可以发送一封邮件测试一下：&lt;br /&gt;mail -s &quot;test&quot; user@sohu.com &lt;content .txt=&quot;.txt&quot; content.txt=&quot;content.txt&quot; div=&quot;div&quot; s=&quot;s&quot; sohu.com=&quot;sohu.com&quot; user=&quot;user&quot;&gt;&lt;/content&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/3910488995695241598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2012/12/linux.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/3910488995695241598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/3910488995695241598'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2012/12/linux.html' title='Linux利用外部邮箱发送邮件的方法'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-8548247306817845263</id><published>2012-12-09T10:58:00.000+11:00</published><updated>2012-12-09T10:58:55.959+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operating system"/><title type='text'>Grep学习笔记</title><content type='html'>&lt;br /&gt;&lt;div class=&quot;sect1&quot; lang=&quot;en&quot; style=&quot;background-color: white; margin-left: 10px; margin-right: 10px;&quot;&gt;&lt;div class=&quot;titlepage&quot;&gt;&lt;div&gt;&lt;h2 class=&quot;title&quot; style=&quot;clear: both;&quot;&gt;1.&amp;nbsp;grep简介&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;grep （global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来）是一种强大的文本搜索工具，它能使用正则表达式搜索文本，并把匹配的行打印出来。Unix的grep家族包 括grep、egrep和fgrep。egrep和fgrep的命令只跟grep有很小不同。egrep是grep的扩展，支持更多的re元字符， fgrep就是fixed grep或fast grep，它们把所有的字母都看作单词，也就是说，正则表达式中的元字符表示回其自身的字面意义，不再特殊。linux使用GNU版本的grep。它功能 更强，可以通过-G、-E、-F命令行选项来使用egrep和fgrep的功能。&lt;br /&gt;grep的工作方式是这样的，它在一个或多个文件中搜索字符串模板。如果模板包括空格，则必须被引用，模板后的所有字符串被看作文件名。搜索的结果被送到屏幕，不影响原文件内容。&lt;br /&gt;grep可用于shell脚本，因为grep通过返回一个状态值来说明搜索的状态，如果模板搜索成功，则返回0，如果搜索不成功，则返回1，如果搜索的文件不存在，则返回2。我们利用这些返回值就可进行一些自动化的文本处理工作。&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;sect1&quot; lang=&quot;en&quot; style=&quot;background-color: white; margin-left: 10px; margin-right: 10px;&quot;&gt;&lt;div class=&quot;titlepage&quot;&gt;&lt;div&gt;&lt;h2 class=&quot;title&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; name=&quot;id2875155&quot;&gt;&lt;/a&gt;2.&amp;nbsp;grep正则表达式元字符集（基本集）&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;variablelist&quot;&gt; &lt;dl&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;^&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;锚定行的开始 如：&#39;^grep&#39;匹配所有以grep开头的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;$&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;锚定行的结束 如：&#39;grep$&#39;匹配所有以grep结尾的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;.&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;匹配一个非换行符的字符 如：&#39;gr.p&#39;匹配gr后接一个任意字符，然后是p。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;*&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;匹配零个或多个先前字符 如：&#39;*grep&#39;匹配所有一个或多个空格后紧跟grep的行。 .*一起用代表任意字符。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;匹配一个指定范围内的字符，如&#39;[Gg]rep&#39;匹配Grep和grep。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[^]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;匹配一个不在指定范围内的字符，如：&#39;[^A-FH-Z]rep&#39;匹配不包含A-R和T-Z的一个字母开头，紧跟rep的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;\(..\)&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;标记匹配字符，如&#39;\(love\)&#39;，love被标记为1。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;\&amp;lt;&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;锚定单词的开始，如:&#39;\&lt;grep grep=&quot;grep&quot; p=&quot;p&quot;&gt;&lt;/grep&gt;&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;\&amp;gt;&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;锚定单词的结束，如&#39;grep\&amp;gt;&#39;匹配包含以grep结尾的单词的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;x\{m\}&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;重复字符x，m次，如：&#39;0\{5\}&#39;匹配包含5个o的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;x\{m,\}&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;重复字符x,至少m次，如：&#39;o\{5,\}&#39;匹配至少有5个o的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;x\{m,n\}&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;重复字符x，至少m次，不多于n次，如：&#39;o\{5,10\}&#39;匹配5--10个o的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;\w&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;匹配文字和数字字符，也就是[A-Za-z0-9]，如：&#39;G\w*p&#39;匹配以G后跟零个或多个文字或数字字符，然后是p。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;\W&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;\w的反置形式，匹配一个或多个非单词字符，如点号句号等。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;\b&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;单词锁定符，如: &#39;\bgrep\b&#39;只匹配grep。&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;sect1&quot; lang=&quot;en&quot; style=&quot;background-color: white; margin-left: 10px; margin-right: 10px;&quot;&gt;&lt;div class=&quot;titlepage&quot;&gt;&lt;div&gt;&lt;h2 class=&quot;title&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; name=&quot;id2810113&quot;&gt;&lt;/a&gt;3.&amp;nbsp;用于egrep和 grep -E的元字符扩展集&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;variablelist&quot;&gt; &lt;dl&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;+&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;匹配一个或多个先前的字符。如：&#39;[a-z]+able&#39;，匹配一个或多个小写字母后跟able的串，如loveable,enable,disable等。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;?&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;匹配零个或多个先前的字符。如：&#39;gr?p&#39;匹配gr后跟一个或没有字符，然后是p的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;a|b|c&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;匹配a或b或c。如：grep|sed匹配grep或sed&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;()&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;分组符号，如：love(able|rs)ov+匹配loveable或lovers，匹配一个或多个ov。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;x{m},x{m,},x{m,n}&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;作用同x\{m\},x\{m,\},x\{m,n\}&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;sect1&quot; lang=&quot;en&quot; style=&quot;background-color: white; margin-left: 10px; margin-right: 10px;&quot;&gt;&lt;div class=&quot;titlepage&quot;&gt;&lt;div&gt;&lt;h2 class=&quot;title&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; name=&quot;id2810216&quot;&gt;&lt;/a&gt;4.&amp;nbsp;POSIX字符类&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;为 了在不同国家的字符编码中保持一至，POSIX(The Portable Operating System Interface)增加了特殊的字符类，如[:alnum:]是A-Za-z0-9的另一个写法。要把它们放到[]号内才能成为正则表达式，如[A- Za-z0-9]或[[:alnum:]]。在linux下的grep除fgrep外，都支持POSIX的字符类。&lt;br /&gt;&lt;div class=&quot;variablelist&quot;&gt; &lt;dl&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:alnum:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;文字数字字符&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:alpha:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;文字字符&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:digit:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;数字字符&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:graph:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;非空字符（非空格、控制字符）&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:lower:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;小写字符&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:cntrl:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;控制字符&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:print:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;非空字符（包括空格）&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:punct:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;标点符号&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:space:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;所有空白字符（新行，空格，制表符）&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:upper:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;大写字符&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;[:xdigit:]&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;十六进制数字（0-9，a-f，A-F）&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;sect1&quot; lang=&quot;en&quot; style=&quot;background-color: white; margin-left: 10px; margin-right: 10px;&quot;&gt;&lt;div class=&quot;titlepage&quot;&gt;&lt;div&gt;&lt;h2 class=&quot;title&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; name=&quot;id2810431&quot;&gt;&lt;/a&gt;5.&amp;nbsp;Grep命令选项&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;variablelist&quot;&gt; &lt;dl&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-?&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;同时显示匹配行上下的？行，如：grep -2 pattern filename同时显示匹配行的上下2行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-b，--byte-offset&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;打印匹配行前面打印该行所在的块号码。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-c,--count&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;只打印匹配的行数，不显示匹配的内容。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-f File，--file=File&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;从文件中提取模板。空文件中包含0个模板，所以什么都不匹配。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-h，--no-filename&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;当搜索多个文件时，不显示匹配文件名前缀。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-i，--ignore-case&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;忽略大小写差别。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-q，--quiet&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;取消显示，只返回退出状态。0则表示找到了匹配的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-l，--files-with-matches&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;打印匹配模板的文件清单。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-L，--files-without-match&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;打印不匹配模板的文件清单。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-n，--line-number&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;在匹配的行前面打印行号。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-s，--silent&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;不显示关于不存在或者无法读取文件的错误信息。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-v，--revert-match&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;反检索，只显示不匹配的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-w，--word-regexp&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;如果被\&amp;lt;和\&amp;gt;引用，就把表达式做为一个单词搜索。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;-V，--version&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;显示软件版本信息。&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;sect1&quot; lang=&quot;en&quot; style=&quot;background-color: white; margin-left: 10px; margin-right: 10px;&quot;&gt;&lt;div class=&quot;titlepage&quot;&gt;&lt;div&gt;&lt;h2 class=&quot;title&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://www.blogger.com/blogger.g?blogID=28274498&quot; name=&quot;id2861488&quot;&gt;&lt;/a&gt;6.&amp;nbsp;实例&lt;/h2&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;要用好grep这个工具，其实就是要写好正则表达式，所以这里不对grep的所有功能进行实例讲解，只列几个例子，讲解一个正则表达式的写法。&lt;br /&gt;&lt;div class=&quot;variablelist&quot;&gt; &lt;dl&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;$ ls -l | grep &#39;^a&#39;&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;通过管道过滤ls -l输出的内容，只显示以a开头的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;$ grep &#39;test&#39; d*&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;显示所有以d开头的文件中包含test的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;$ grep &#39;test&#39; aa bb cc&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;显示在aa，bb，cc文件中匹配test的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;$ grep &#39;[a-z]\{5\}&#39; aa&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;显示所有包含每个字符串至少有5个连续小写字符的字符串的行。&lt;/dd&gt;&lt;dt&gt;&lt;span class=&quot;term&quot;&gt;$ grep &#39;w\(es\)t.*\1&#39; aa&lt;/span&gt;&lt;/dt&gt;&lt;dd&gt;如果west被匹配，则es就被存储到内存中，并标记为1，然后搜索任意个字符（.*），这些字符后面紧跟着另外一个es（\1），找到就显示该行。如果用egrep或grep -E，就不用&quot;\&quot;号进行转义，直接写成&#39;w(es)t.*\1&#39;就可以了。&lt;/dd&gt;&lt;/dl&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/8548247306817845263/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2012/12/grep.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/8548247306817845263'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/8548247306817845263'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2012/12/grep.html' title='Grep学习笔记'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-6547567581742212826</id><published>2012-12-07T22:58:00.003+11:00</published><updated>2012-12-07T22:58:59.748+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="operating system"/><title type='text'>linux下面用ssh上传，下载文件</title><content type='html'>&lt;br /&gt;一，ssh上传文件&lt;br /&gt;scp file username@hostIP:文件地址 例:&lt;br /&gt;[zhangy@BlackGhost ~]$ scp test.sql zhangying@192.168.1.5:/var/www/zhangying&lt;br /&gt;zhangying@192.168.1.5&#39;s password:&lt;br /&gt;test.sql &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100% 7884 &amp;nbsp; &amp;nbsp; 7.7KB/s &amp;nbsp; 00:00&lt;br /&gt;[zhangy@BlackGhost ~]$&lt;br /&gt;二，ssh下载文件&lt;br /&gt;scp username@hostIP:文件所在地址 &amp;nbsp; 文件目录 例:&lt;br /&gt;[zhangy@BlackGhost ~]$ scp zhangying@192.168.1.5:/var/www/zhangying/test.sql /home/zhangy/database_bak/&lt;br /&gt;zhangying@192.168.1.5&#39;s password:&lt;br /&gt;test.sql &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100% 7884 &amp;nbsp; &amp;nbsp; 7.7KB/s &amp;nbsp; 00:00&lt;br /&gt;[zhangy@BlackGhost ~]$&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/6547567581742212826/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2012/12/linuxssh.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/6547567581742212826'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/6547567581742212826'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2012/12/linuxssh.html' title='linux下面用ssh上传，下载文件'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-28274498.post-653366408777685802</id><published>2012-12-04T11:12:00.002+11:00</published><updated>2012-12-04T11:12:46.423+11:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><title type='text'>Java获取各种常用时间方法</title><content type='html'>&lt;br /&gt;package com.hefeng.test;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;import java.text.DateFormat;&lt;br /&gt;import java.text.ParsePosition;&lt;br /&gt;import java.text.SimpleDateFormat;&lt;br /&gt;import java.util.Calendar;&lt;br /&gt;import java.util.Date;&lt;br /&gt;import java.util.GregorianCalendar;&lt;br /&gt;&lt;br /&gt;public class TimeTest {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//用来全局控制 上一周，本周，下一周的周数变化&lt;br /&gt;&amp;nbsp; &amp;nbsp; private &amp;nbsp;int weeks = 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; private int MaxDate;//一月最大天数&lt;br /&gt;&amp;nbsp; &amp;nbsp; private int MaxYear;//一年最大天数&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/**&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; * @param args&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; */&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static void main(String[] args) {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;TimeTest tt = new TimeTest();&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取当天日期:&quot;+tt.getNowTime(&quot;yyyy-MM-dd&quot;));&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取本周一日期:&quot;+tt.getMondayOFWeek());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取本周日的日期~:&quot;+tt.getCurrentWeekday());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取上周一日期:&quot;+tt.getPreviousWeekday());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取上周日日期:&quot;+tt.getPreviousWeekSunday());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取下周一日期:&quot;+tt.getNextMonday());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取下周日日期:&quot;+tt.getNextSunday());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获得相应周的周六的日期:&quot;+tt.getNowTime(&quot;yyyy-MM-dd&quot;));&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取本月第一天日期:&quot;+tt.getFirstDayOfMonth());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取本月最后一天日期:&quot;+tt.getDefaultDay());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取上月第一天日期:&quot;+tt.getPreviousMonthFirst());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取上月最后一天的日期:&quot;+tt.getPreviousMonthEnd());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取下月第一天日期:&quot;+tt.getNextMonthFirst());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取下月最后一天日期:&quot;+tt.getNextMonthEnd());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取本年的第一天日期:&quot;+tt.getCurrentYearFirst());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取本年最后一天日期:&quot;+tt.getCurrentYearEnd());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取去年的第一天日期:&quot;+tt.getPreviousYearFirst());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取去年的最后一天日期:&quot;+tt.getPreviousYearEnd());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取明年第一天日期:&quot;+tt.getNextYearFirst());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取明年最后一天日期:&quot;+tt.getNextYearEnd());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取本季度第一天到最后一天:&quot;+tt.getThisSeasonTime(11));&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;System.out.println(&quot;获取两个日期之间间隔天数2008-12-1~2008-9.29:&quot;+TimeTest.getTwoDay(&quot;2008-12-1&quot;,&quot;2008-9-29&quot;));&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/**&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* 得到二个日期间的间隔天数&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static String getTwoDay(String sj1, String sj2) {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;SimpleDateFormat myFormatter = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;long day = 0;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;try {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; java.util.Date date = myFormatter.parse(sj1);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; java.util.Date mydate = myFormatter.parse(sj2);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;} catch (Exception e) {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; return &quot;&quot;;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;return day + &quot;&quot;;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/**&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* 根据一个日期，返回是星期几的字符串&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;*&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* @param sdate&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* @return&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static String getWeek(String sdate) {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;// 再转换为时间&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;Date date = TimeTest.strToDate(sdate);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;Calendar c = Calendar.getInstance();&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;c.setTime(date);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;// int hour=c.get(Calendar.DAY_OF_WEEK);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;// hour中存的就是星期几了，其范围 1~7&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;// 1=星期日 7=星期六，其他类推&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;return new SimpleDateFormat(&quot;EEEE&quot;).format(c.getTime());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/**&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* 将短时间格式字符串转换为时间 yyyy-MM-dd&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;*&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* @param strDate&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* @return&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static Date strToDate(String strDate) {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;SimpleDateFormat formatter = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;ParsePosition pos = new ParsePosition(0);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;Date strtodate = formatter.parse(strDate, pos);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;return strtodate;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/**&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* 两个时间之间的天数&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;*&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* @param date1&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* @param date2&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;* @return&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public static long getDays(String date1, String date2) {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;if (date1 == null || date1.equals(&quot;&quot;))&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; return 0;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;if (date2 == null || date2.equals(&quot;&quot;))&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; return 0;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;// 转换为标准时间&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;SimpleDateFormat myFormatter = new SimpleDateFormat(&quot;yyyy-MM-dd&quot;);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;java.util.Date date = null;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;java.util.Date mydate = null;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;try {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; date = myFormatter.parse(date1);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp; mydate = myFormatter.parse(date2);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;} catch (Exception e) {&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;long day = (date.getTime() - mydate.getTime()) / (24 * 60 * 60 * 1000);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; &amp;nbsp;return day;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// 计算当月最后一天,返回字符串&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public String getDefaultDay(){ &lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; String str = &quot;&quot;;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; SimpleDateFormat sdf=new SimpleDateFormat(&quot;yyyy-MM-dd&quot;); &amp;nbsp; &lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; Calendar lastDate = Calendar.getInstance();&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; lastDate.set(Calendar.DATE,1);//设为当前月的1号&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; lastDate.add(Calendar.MONTH,1);//加一个月，变为下月的1号&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; lastDate.add(Calendar.DATE,-1);//减去一天，变为当月最后一天&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; str=sdf.format(lastDate.getTime());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; return str; &lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// 上月第一天&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public String getPreviousMonthFirst(){ &lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; String str = &quot;&quot;;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; SimpleDateFormat sdf=new SimpleDateFormat(&quot;yyyy-MM-dd&quot;); &amp;nbsp; &lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; Calendar lastDate = Calendar.getInstance();&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; lastDate.set(Calendar.DATE,1);//设为当前月的1号&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; lastDate.add(Calendar.MONTH,-1);//减一个月，变为下月的1号&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; //lastDate.add(Calendar.DATE,-1);//减去一天，变为当月最后一天&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; str=sdf.format(lastDate.getTime());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; return str; &lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//获取当月第一天&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public String getFirstDayOfMonth(){ &lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; String str = &quot;&quot;;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; SimpleDateFormat sdf=new SimpleDateFormat(&quot;yyyy-MM-dd&quot;); &amp;nbsp; &lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; Calendar lastDate = Calendar.getInstance();&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; lastDate.set(Calendar.DATE,1);//设为当前月的1号&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; str=sdf.format(lastDate.getTime());&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; return str; &lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;// 获得本周星期日的日期 &lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getCurrentWeekday() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weeks = 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int mondayPlus = this.getMondayPlus();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GregorianCalendar currentDate = new GregorianCalendar();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; currentDate.add(GregorianCalendar.DATE, mondayPlus+6);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date monday = currentDate.getTime();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DateFormat df = DateFormat.getDateInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String preMonday = df.format(monday);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return preMonday;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;//获取当天时间&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getNowTime(String dateformat){&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Date &amp;nbsp; now &amp;nbsp; = &amp;nbsp; new &amp;nbsp; Date(); &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;SimpleDateFormat &amp;nbsp; dateFormat &amp;nbsp; = &amp;nbsp; new &amp;nbsp; SimpleDateFormat(dateformat);//可以方便地修改日期格式 &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String &amp;nbsp;hehe &amp;nbsp;= dateFormat.format(now); &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return hehe;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; // 获得当前日期与本周日相差的天数&lt;br /&gt;&amp;nbsp; &amp;nbsp; private int getMondayPlus() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Calendar cd = Calendar.getInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // 获得今天是一周的第几天，星期日是第一天，星期二是第二天......&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK)-1; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;//因为按中国礼拜一作为第一天所以这里减1&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (dayOfWeek == 1) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; } else {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return 1 - dayOfWeek;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; //获得本周一的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getMondayOFWeek(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; weeks = 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int mondayPlus = this.getMondayPlus();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;GregorianCalendar currentDate = new GregorianCalendar();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;currentDate.add(GregorianCalendar.DATE, mondayPlus);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date monday = currentDate.getTime();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DateFormat df = DateFormat.getDateInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;String preMonday = df.format(monday);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return preMonday;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得相应周的周六的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getSaturday() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int mondayPlus = this.getMondayPlus();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GregorianCalendar currentDate = new GregorianCalendar();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks + 6);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date monday = currentDate.getTime();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DateFormat df = DateFormat.getDateInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String preMonday = df.format(monday);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return preMonday;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;// 获得上周星期日的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getPreviousWeekSunday() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;weeks=0;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weeks--;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int mondayPlus = this.getMondayPlus();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GregorianCalendar currentDate = new GregorianCalendar();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; currentDate.add(GregorianCalendar.DATE, mondayPlus+weeks);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date monday = currentDate.getTime();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DateFormat df = DateFormat.getDateInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String preMonday = df.format(monday);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return preMonday;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&lt;br /&gt;&amp;nbsp;// 获得上周星期一的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getPreviousWeekday() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weeks--;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int mondayPlus = this.getMondayPlus();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GregorianCalendar currentDate = new GregorianCalendar();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * weeks);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date monday = currentDate.getTime();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DateFormat df = DateFormat.getDateInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String preMonday = df.format(monday);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return preMonday;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; // 获得下周星期一的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getNextMonday() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; weeks++;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int mondayPlus = this.getMondayPlus();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GregorianCalendar currentDate = new GregorianCalendar();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; currentDate.add(GregorianCalendar.DATE, mondayPlus + 7);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date monday = currentDate.getTime();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DateFormat df = DateFormat.getDateInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String preMonday = df.format(monday);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return preMonday;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;// 获得下周星期日的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getNextSunday() {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; int mondayPlus = this.getMondayPlus();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GregorianCalendar currentDate = new GregorianCalendar();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; currentDate.add(GregorianCalendar.DATE, mondayPlus + 7+6);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date monday = currentDate.getTime();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DateFormat df = DateFormat.getDateInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; String preMonday = df.format(monday);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return preMonday;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; private int getMonthPlus(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Calendar cd = Calendar.getInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int monthOfNumber = cd.get(Calendar.DAY_OF_MONTH);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cd.set(Calendar.DATE, 1);//把日期设置为当月第一天&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cd.roll(Calendar.DATE, -1);//日期回滚一天，也就是最后一天&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;MaxDate=cd.get(Calendar.DATE);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(monthOfNumber == 1){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return -MaxDate;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}else{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return 1-monthOfNumber;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得上月最后一天的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getPreviousMonthEnd(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;String str = &quot;&quot;;&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; SimpleDateFormat sdf=new SimpleDateFormat(&quot;yyyy-MM-dd&quot;); &amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; Calendar lastDate = Calendar.getInstance();&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.add(Calendar.MONTH,-1);//减一个月&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.set(Calendar.DATE, 1);//把日期设置为当月第一天&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.roll(Calendar.DATE, -1);//日期回滚一天，也就是本月最后一天&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; str=sdf.format(lastDate.getTime());&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; return str; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得下个月第一天的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getNextMonthFirst(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;String str = &quot;&quot;;&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; SimpleDateFormat sdf=new SimpleDateFormat(&quot;yyyy-MM-dd&quot;); &amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; Calendar lastDate = Calendar.getInstance();&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.add(Calendar.MONTH,1);//减一个月&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.set(Calendar.DATE, 1);//把日期设置为当月第一天&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; str=sdf.format(lastDate.getTime());&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; return str; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得下个月最后一天的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getNextMonthEnd(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;String str = &quot;&quot;;&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; SimpleDateFormat sdf=new SimpleDateFormat(&quot;yyyy-MM-dd&quot;); &amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; Calendar lastDate = Calendar.getInstance();&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.add(Calendar.MONTH,1);//加一个月&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.set(Calendar.DATE, 1);//把日期设置为当月第一天&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.roll(Calendar.DATE, -1);//日期回滚一天，也就是本月最后一天&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; str=sdf.format(lastDate.getTime());&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; return str; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; //获得明年最后一天的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getNextYearEnd(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;String str = &quot;&quot;;&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; SimpleDateFormat sdf=new SimpleDateFormat(&quot;yyyy-MM-dd&quot;); &amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;Calendar lastDate = Calendar.getInstance();&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.add(Calendar.YEAR,1);//加一个年&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.set(Calendar.DAY_OF_YEAR, 1);&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; lastDate.roll(Calendar.DAY_OF_YEAR, -1);&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; str=sdf.format(lastDate.getTime());&lt;br /&gt;&amp;nbsp;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; return str; &lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得明年第一天的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getNextYearFirst(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;String str = &quot;&quot;;&lt;br /&gt;&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp; SimpleDateFormat sdf=new SimpleDateFormat(&quot;yyyy-MM-dd&quot;); &amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;Calendar lastDate = Calendar.getInstance();&lt;br /&gt;&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.add(Calendar.YEAR,1);//加一个年&lt;br /&gt;&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;lastDate.set(Calendar.DAY_OF_YEAR, 1);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;str=sdf.format(lastDate.getTime());&lt;br /&gt;&amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt; &amp;nbsp;return str; &lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得本年有多少天&lt;br /&gt;&amp;nbsp; &amp;nbsp; private int getMaxYear(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Calendar cd = Calendar.getInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cd.set(Calendar.DAY_OF_YEAR,1);//把日期设为当年第一天&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cd.roll(Calendar.DAY_OF_YEAR,-1);//把日期回滚一天。&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int MaxYear = cd.get(Calendar.DAY_OF_YEAR);&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return MaxYear;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp; private int getYearPlus(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Calendar cd = Calendar.getInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int yearOfNumber = cd.get(Calendar.DAY_OF_YEAR);//获得当天是一年中的第几天&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cd.set(Calendar.DAY_OF_YEAR,1);//把日期设为当年第一天&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;cd.roll(Calendar.DAY_OF_YEAR,-1);//把日期回滚一天。&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int MaxYear = cd.get(Calendar.DAY_OF_YEAR);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;if(yearOfNumber == 1){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return -MaxYear;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}else{&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return 1-yearOfNumber;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; //获得本年第一天的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getCurrentYearFirst(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int yearPlus = this.getYearPlus();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;GregorianCalendar currentDate = new GregorianCalendar();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;currentDate.add(GregorianCalendar.DATE,yearPlus);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Date yearDay = currentDate.getTime();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;DateFormat df = DateFormat.getDateInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;String preYearDay = df.format(yearDay);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return preYearDay;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得本年最后一天的日期 *&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getCurrentYearEnd(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Date date = new Date();&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;SimpleDateFormat &amp;nbsp; dateFormat &amp;nbsp; = &amp;nbsp; new &amp;nbsp; SimpleDateFormat(&quot;yyyy&quot;);//可以方便地修改日期格式 &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String &amp;nbsp;years &amp;nbsp;= dateFormat.format(date); &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return years+&quot;-12-31&quot;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得上年第一天的日期 *&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getPreviousYearFirst(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Date date = new Date();&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;SimpleDateFormat &amp;nbsp; dateFormat &amp;nbsp; = &amp;nbsp; new &amp;nbsp; SimpleDateFormat(&quot;yyyy&quot;);//可以方便地修改日期格式 &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String &amp;nbsp;years &amp;nbsp;= dateFormat.format(date); int years_value = Integer.parseInt(years); &lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;years_value--;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return years_value+&quot;-1-1&quot;;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得上年最后一天的日期&lt;br /&gt;&amp;nbsp; &amp;nbsp; public String getPreviousYearEnd(){&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;weeks--;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;int yearPlus = this.getYearPlus();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;GregorianCalendar currentDate = new GregorianCalendar();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;currentDate.add(GregorianCalendar.DATE,yearPlus+MaxYear*weeks+(MaxYear-1));&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Date yearDay = currentDate.getTime();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;DateFormat df = DateFormat.getDateInstance();&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;String preYearDay = df.format(yearDay);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;getThisSeasonTime(11);&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;return preYearDay;&lt;br /&gt;&amp;nbsp; &amp;nbsp; }&lt;br /&gt;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp; //获得本季度&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;public String getThisSeasonTime(int month){&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int array[][] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int season = 1;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(month&amp;gt;=1&amp;amp;&amp;amp;month&amp;lt;=3){&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;season = 1;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(month&amp;gt;=4&amp;amp;&amp;amp;month&amp;lt;=6){&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;season = 2;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(month&amp;gt;=7&amp;amp;&amp;amp;month&amp;lt;=9){&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;season = 3;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;if(month&amp;gt;=10&amp;amp;&amp;amp;month&amp;lt;=12){&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;   &lt;/span&gt;season = 4;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int start_month = array[season-1][0];&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int end_month = array[season-1][2];&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;Date date = new Date();&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;SimpleDateFormat &amp;nbsp; dateFormat &amp;nbsp; = &amp;nbsp; new &amp;nbsp; SimpleDateFormat(&quot;yyyy&quot;);//可以方便地修改日期格式 &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String &amp;nbsp;years &amp;nbsp;= dateFormat.format(date); &amp;nbsp;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int years_value = Integer.parseInt(years);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int start_days =1;//years+&quot;-&quot;+String.valueOf(start_month)+&quot;-1&quot;;//getLastDayOfMonth(years_value,start_month);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;int end_days = getLastDayOfMonth(years_value,end_month);&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;String seasonDate = years_value+&quot;-&quot;+start_month+&quot;-&quot;+start_days+&quot;;&quot;+years_value+&quot;-&quot;+end_month+&quot;-&quot;+end_days;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;return seasonDate;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt;  &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;}&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;&lt;br /&gt;&lt;span class=&quot;Apple-tab-span&quot; style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;/**&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* 获取某年某月的最后一天&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @param year 年&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @param month 月&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;* @return 最后一天&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;*/&lt;br /&gt;&amp;nbsp; &amp;nbsp;private int getLastDayOfMonth(int year, int month) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|| month == 10 || month == 12) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return 31;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (month == 4 || month == 6 || month == 9 || month == 11) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return 30;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (month == 2) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (isLeapYear(year)) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return 29;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;} else {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return 28;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return 0;&lt;br /&gt;&amp;nbsp; &amp;nbsp;}&lt;br /&gt;&amp;nbsp; &amp;nbsp;/**&lt;br /&gt;&amp;nbsp; &amp;nbsp; * 是否闰年&lt;br /&gt;&amp;nbsp; &amp;nbsp; * @param year 年&lt;br /&gt;&amp;nbsp; &amp;nbsp; * @return&lt;br /&gt;&amp;nbsp; &amp;nbsp; */&lt;br /&gt;&amp;nbsp; public boolean isLeapYear(int year) {&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return (year % 4 == 0 &amp;amp;&amp;amp; year % 100 != 0) || (year % 400 == 0);&lt;br /&gt;&amp;nbsp; }&lt;br /&gt;}&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://suange.blogspot.com/feeds/653366408777685802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://suange.blogspot.com/2012/12/java.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/653366408777685802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/28274498/posts/default/653366408777685802'/><link rel='alternate' type='text/html' href='http://suange.blogspot.com/2012/12/java.html' title='Java获取各种常用时间方法'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/12736710513969888050</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>