﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-LIULIANG-随笔分类-java web</title><link>http://www.cppblog.com/LIULIANG/category/19789.html</link><description /><language>zh-cn</language><lastBuildDate>Sat, 06 Jul 2013 08:11:55 GMT</lastBuildDate><pubDate>Sat, 06 Jul 2013 08:11:55 GMT</pubDate><ttl>60</ttl><item><title>Struts2文件上传的大小限制问题  转载</title><link>http://www.cppblog.com/LIULIANG/archive/2013/07/06/201564.html</link><dc:creator>BIG森林</dc:creator><author>BIG森林</author><pubDate>Sat, 06 Jul 2013 08:07:00 GMT</pubDate><guid>http://www.cppblog.com/LIULIANG/archive/2013/07/06/201564.html</guid><wfw:comment>http://www.cppblog.com/LIULIANG/comments/201564.html</wfw:comment><comments>http://www.cppblog.com/LIULIANG/archive/2013/07/06/201564.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/LIULIANG/comments/commentRss/201564.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/LIULIANG/services/trackbacks/201564.html</trackback:ping><description><![CDATA[<div class="postbody"><strong style="color: red">问题：上传大文件大小限制</strong><strong><br /><br /></strong></div>
<div class="postbody">解决方案：修改struts.xml文件中的参数如下
<div style="font-size: 13px; border-top: #cccccc 1px solid; border-right: #cccccc 1px solid; border-bottom: #cccccc 1px solid; word-break: break-all; padding-bottom: 4px; padding-top: 4px; padding-left: 4px; border-left: #cccccc 1px solid; padding-right: 5px; width: 98%; background-color: #eeeeee"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><span style="color: #0000ff">&lt;</span><span style="color: #800000">constant&nbsp;</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="struts.multipart.maxSize"</span><span style="color: #ff0000">&nbsp;value</span><span style="color: #0000ff">="55000000"</span><span style="color: #0000ff">/&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">&lt;</span><span style="color: #800000">action&nbsp;</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="UploadFile"</span><span style="color: #ff0000">&nbsp;class</span><span style="color: #0000ff">="com.buptisc.srpms.action.UploadFileAction"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">result&nbsp;</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="UploadFileResult"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">/pages/ShowOtherFiles.jsp</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">result</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">result&nbsp;</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="JGBsuccess"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">/pages/JGBdetail.jsp</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">result</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">interceptor-ref&nbsp;</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="fileUpload"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">param&nbsp;</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="savePath"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">/data</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">param</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">&nbsp;&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">param&nbsp;</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="maximumSize"</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">52428800</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">param</span><span style="color: #0000ff">&gt;</span><span style="color: #000000">&nbsp;<br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">interceptor-ref</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">&lt;</span><span style="color: #800000">interceptor-ref&nbsp;</span><span style="color: #ff0000">name</span><span style="color: #0000ff">="defaultStack"</span><span style="color: #0000ff">&gt;&lt;/</span><span style="color: #800000">interceptor-ref</span><span style="color: #0000ff">&gt;</span><span style="color: #000000"><br /><img align="top" src="http://www.cppblog.com/images/OutliningIndicators/None.gif"  alt="" /></span><span style="color: #0000ff">&lt;/</span><span style="color: #800000">action</span><span style="color: #0000ff">&gt;</span></div></div>
<p>struts.xml文件中的大小与实际文件大小的关系：<span style="color: rgb(255,0,0)">1048576（Bytes） = 1024*1024 = 1M实际文件大小.<br /></span><span style="color: rgb(255,0,0)">struts.multipart.maxSize掌控整个项目所上传文件的最大的Size<br /></span>struts.multipart.maxSize和fileUpload拦截器的maximumSize属性分工不同，总结如下：<br />1.struts.multipart.maxSize掌控整个项目所上传文件的最大的Size。超过了这个size，后台报错，程序处理不了如此大的文件。fielderror里面会有如下的提示：<br />the request was rejected because its size (16272982) exceeds the configured maximum (9000000）<br />2.fileUpload拦截器的maximumSize属性必须小于struts.multipart.maxSize的值。<br />struts.multipart.maxSize默认2M，当maximumSize大于2M时,必须设置struts.multipart.maxSize的值大于maximumSize。<br />3.当上传的文件大于struts.multipart.maxSize时，系统报错<br />当上传的文件在struts.multipart.maxSize和maximumSize之间时，系统提示：<br />File too large: file "MSF的概念.ppt" "upload__5133e516_129ce85285f__7ffa_00000005.tmp" 6007104 <br />当上传的文件小于maximumSize，上传成功。<br /><br />转自：<a href="http://www.cnblogs.com/forlina/archive/2011/9/8.html">http://www.cnblogs.com/forlina/archive/2011/9/8.html</a></p><img src ="http://www.cppblog.com/LIULIANG/aggbug/201564.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/LIULIANG/" target="_blank">BIG森林</a> 2013-07-06 16:07 <a href="http://www.cppblog.com/LIULIANG/archive/2013/07/06/201564.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ASCII，Unicode和UTF-8</title><link>http://www.cppblog.com/LIULIANG/archive/2012/11/18/195326.html</link><dc:creator>BIG森林</dc:creator><author>BIG森林</author><pubDate>Sun, 18 Nov 2012 13:00:00 GMT</pubDate><guid>http://www.cppblog.com/LIULIANG/archive/2012/11/18/195326.html</guid><wfw:comment>http://www.cppblog.com/LIULIANG/comments/195326.html</wfw:comment><comments>http://www.cppblog.com/LIULIANG/archive/2012/11/18/195326.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/LIULIANG/comments/commentRss/195326.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/LIULIANG/services/trackbacks/195326.html</trackback:ping><description><![CDATA[<p><span style="font-family: Arial; color: #333333" color="#333333" face="Arial"><span style="color: #ff0000; font-size: 18pt">UTF-8是Unicode的一种实现方式，也就是它的字节结构有特殊要求，所以我们说一个汉字的范围是0X4E00到0x9FA5，是指unicode值，至于放在utf-8的编码里去就是由三个字节来组织，所以可以看出unicode是给出一个字符的范围，定义了这个字是码值是多少，至于具体的实现方式可以有多种多样来实现。</span><br /><br /><br /><br /></span></p>
<p><span style="line-height: 26px; font-family: Arial; color: #333333" class="Apple-style-span">UTF-8是一种变长字节编码方式。对于某一个字符的UTF-8编码，如果只有一个字节则其最高二进制位为0；如果是多字节，其第一个字节从最高位开始，连续的二进制位值为1的个数决定了其编码的位数，其余各字节均以10开头。UTF-8最多可用到6个字节。&nbsp;<br />如表：&nbsp;<br />1字节 0xxxxxxx&nbsp;<br />2字节 110xxxxx 10xxxxxx&nbsp;<br />3字节 1110xxxx 10xxxxxx 10xxxxxx&nbsp;<br />4字节 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx&nbsp;<br />5字节 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx&nbsp;<br />6字节 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx&nbsp;<br />因此UTF-8中可以用来表示字符编码的实际位数最多有31位，即上表中x所表示的位。除去那些控制位（每字节开头的10等），这些x表示的位与UNICODE编码是一一对应的，位高低顺序也相同。&nbsp;<br />实际将UNICODE转换为UTF-8编码时应先去除高位0，然后根据所剩编码的位数决定所需最小的UTF-8编码位数。&nbsp;<br />因此那些基本ASCII字符集中的字符（UNICODE兼容ASCII）只需要一个字节的UTF-8编码（7个二进制位）便可以表示。&nbsp;<br /><br />对于上面的问题，代码中给出的两个字节是&nbsp;<br />十六进制：C0 B1&nbsp;<br />二进制：11000000 10110001&nbsp;<br />对比两个字节编码的表示方式：&nbsp;<br />110xxxxx 10xxxxxx&nbsp;<br />提取出对应的UNICODE编码：&nbsp;<br />00000 110001&nbsp;<br />可以看出此编码并非&#8220;标准&#8221;的UTF-8编码，因为其第一个字节的&#8220;有效编码&#8221;全为0，去除高位0后的编码仅有6位。由前面所述，此字符仅用一个字节的UTF-8编码表示就够了。&nbsp;<br />JAVA在把字符还原为UTF-8编码时，是按照&#8220;标准&#8221;的方式处理的，因此我们得到的是仅有1个字节的编码。&nbsp;<br /><br />大家可以试试运行这段代码：&nbsp;<br /></span></p>
<div class="cnblogs_Highlighter">
<div>
<div id="highlighter_751042" class="syntaxhighlighter nogutter  java ie">
<div class="toolbar"><span><a class="toolbar_item command_help help" href="http://www.cnblogs.com/chenwenbiao/archive/2011/08/11/2134503.html#">?</a></span></div>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="code">
<div class="container">
<div class="line number1 index0 alt2"><code class="java keyword">public</code> <code class="java keyword">class</code> <code class="java plain">TestUTF8 {&nbsp; </code></div>
<div class="line number2 index1 alt1"><code class="java keyword">public</code> <code class="java keyword">static</code> <code class="java keyword">void</code> <code class="java plain">main(String[] args) </code><code class="java keyword">throws</code> <code class="java plain">Exception {&nbsp; </code></div>
<div class="line number3 index2 alt2"><code class="java keyword">byte</code><code class="java plain">[][] bytes = {&nbsp; </code></div>
<div class="line number4 index3 alt1"><code class="java comments">// 00110001&nbsp; </code></div>
<div class="line number5 index4 alt2"><code class="java plain">{(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x31</code><code class="java plain">},&nbsp; </code></div>
<div class="line number6 index5 alt1"><code class="java comments">// 11000000 10110001&nbsp; </code></div>
<div class="line number7 index6 alt2"><code class="java plain">{(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xC0</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xB1</code><code class="java plain">},&nbsp; </code></div>
<div class="line number8 index7 alt1"><code class="java comments">// 11100000 10000000 10110001&nbsp; </code></div>
<div class="line number9 index8 alt2"><code class="java plain">{(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xE0</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xB1</code><code class="java plain">},&nbsp; </code></div>
<div class="line number10 index9 alt1"><code class="java comments">// 11110000 10000000 10000000 10110001&nbsp; </code></div>
<div class="line number11 index10 alt2"><code class="java plain">{(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xF0</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xB1</code><code class="java plain">},&nbsp; </code></div>
<div class="line number12 index11 alt1"><code class="java comments">// 11111000 10000000 10000000 10000000 10110001&nbsp; </code></div>
<div class="line number13 index12 alt2"><code class="java plain">{(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xF8</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xB1</code><code class="java plain">},&nbsp; </code></div>
<div class="line number14 index13 alt1"><code class="java comments">// 11111100 10000000 10000000 10000000 10000000 10110001&nbsp; </code></div>
<div class="line number15 index14 alt2"><code class="java plain">{(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xFC</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0x80</code><code class="java plain">,(</code><code class="java keyword">byte</code><code class="java plain">)</code><code class="java value">0xB1</code><code class="java plain">},&nbsp; </code></div>
<div class="line number16 index15 alt1"><code class="java plain">};&nbsp; </code></div>
<div class="line number17 index16 alt2"><code class="java keyword">for</code> <code class="java plain">(</code><code class="java keyword">int</code> <code class="java plain">i = </code><code class="java value">0</code><code class="java plain">; i &lt; </code><code class="java value">6</code><code class="java plain">; i++) {&nbsp; </code></div>
<div class="line number18 index17 alt1"><code class="java plain">String str = </code><code class="java keyword">new</code> <code class="java plain">String(bytes[i], </code><code class="java string">"UTF-8"</code><code class="java plain">);&nbsp; </code></div>
<div class="line number19 index18 alt2"><code class="java plain">System.out.println(</code><code class="java string">"原数组长度："</code> <code class="java plain">+ bytes[i].length +&nbsp; </code></div>
<div class="line number20 index19 alt1"><code class="java string">"/t转换为字符串："</code> <code class="java plain">+ str +&nbsp; </code></div>
<div class="line number21 index20 alt2"><code class="java string">"/t转回后数组长度："</code> <code class="java plain">+ str.getBytes(</code><code class="java string">"UTF-8"</code><code class="java plain">).length);&nbsp; </code></div>
<div class="line number22 index21 alt1"><code class="java plain">}&nbsp; </code></div>
<div class="line number23 index22 alt2"><code class="java plain">}&nbsp; </code></div>
<div class="line number24 index23 alt1"><code class="java plain">}</code></div></div></td></tr></tbody></table></div></div></div>
<p>　　<span style="font-family: Arial; color: #333333" class="Apple-style-span">运行结果为：&nbsp;</span></p>
<p><span style="line-height: 26px; font-family: Arial; color: #333333" class="Apple-style-span">原数组长度：1 转换为字符串：1 转回后数组长度：1&nbsp;<br />原数组长度：2 转换为字符串：1 转回后数组长度：1&nbsp;<br />原数组长度：3 转换为字符串：1 转回后数组长度：1&nbsp;<br />原数组长度：4 转换为字符串：1 转回后数组长度：1&nbsp;<br />原数组长度：5 转换为字符串：1 转回后数组长度：1&nbsp;<br />原数组长度：6 转换为字符串：1 转回后数组长度：1&nbsp;</span></p>
<p><span style="line-height: 26px; font-family: Arial; color: #333333" class="Apple-style-span"><br /></span></p>
<p><span style="font-family: Arial; color: #333333" color="#333333" face="Arial"><br /><br /><br />另转：</span></p>
<p><span style="font-family: Arial; color: #333333" color="#333333" face="Arial"><span style="line-height: 21px; background-color: #f5f5d5; font-family: Georgia, serif; color: #111111; font-size: 12px; word-spacing: 2px" class="Apple-style-span"></span></span></p>
<h1 style="border-bottom: #d3d3d3 1px solid; text-align: left; padding-bottom: 0.2em; line-height: 72px; border-right-style: none; text-transform: capitalize; list-style-type: none; font-style: normal; margin: 0.4em 0px 0.2em; padding-left: 0px; padding-right: 0px; border-top-style: none; letter-spacing: -0.03em; color: #000000; font-size: 2.88em; border-left-style: none; font-weight: 900; text-decoration: none; padding-top: 0px" id="page-title" class="asset-name entry-title">字符编码笔记：ASCII，Unicode和UTF-8</h1>
<p><span style="font-family: Arial; color: #333333" color="#333333" face="Arial"><span style="line-height: 21px; background-color: #f5f5d5; font-family: Georgia, serif; color: #111111; font-size: 12px; word-spacing: 2px" class="Apple-style-span"></span></span><span style="line-height: 21px; background-color: #f5f5d5; font-family: Georgia, serif; color: #111111; font-size: 12px; word-spacing: 2px" class="Apple-style-span"></span></p>
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; border-left-style: none; text-decoration: none; padding-top: 0px" class="asset-body">
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">今天中午，我突然想搞清楚Unicode和UTF-8之间的关系，于是就开始在网上查资料。</p></div>
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; border-left-style: none; text-decoration: none; padding-top: 0px" id="more" class="asset-more">
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">结果，这个问题比我想象的复杂，从午饭后一直看到晚上9点，才算初步搞清楚。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">下面就是我的笔记，主要用来整理自己的思路。但是，我尽量试图写得通俗易懂，希望能对其他朋友有用。毕竟，字符编码是计算机技术的基石，想要熟练使用计算机，就必须懂得一点字符编码的知识。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><strong style="font-weight: 800">1. ASCII码</strong></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">我们知道，在计算机内部，所有的信息最终都表示为一个二进制的字符串。每一个二进制位（bit）有0和1两种状态，因此八个二进制位就可以组合出256种状态，这被称为一个字节（byte）。也就是说，一个字节一共可以用来表示256种不同的状态，每一个状态对应一个符号，就是256个符号，从0000000到11111111。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">上个世纪60年代，美国制定了一套字符编码，对英语字符与二进制位之间的关系，做了统一规定。这被称为ASCII码，一直沿用至今。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">ASCII码一共规定了128个字符的编码，比如空格&#8220;SPACE&#8221;是32（二进制00100000），大写的字母A是65（二进制01000001）。这128个符号（包括32个不能打印出来的控制符号），只占用了一个字节的后面7位，最前面的1位统一规定为0。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><strong style="font-weight: 800">2、非ASCII编码</strong></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">英语用128个符号编码就够了，但是用来表示其他语言，128个符号是不够的。比如，在法语中，字母上方有注音符号，它就无法用ASCII码表示。于是，一些欧洲国家就决定，利用字节中闲置的最高位编入新的符号。比如，法语中的&#233;的编码为130（二进制10000010）。这样一来，这些欧洲国家使用的编码体系，可以表示最多256个符号。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">但是，这里又出现了新的问题。不同的国家有不同的字母，因此，哪怕它们都使用256个符号的编码方式，代表的字母却不一样。比如，130在法语编码中代表了&#233;，在希伯来语编码中却代表了字母Gimel (ג)，在俄语编码中又会代表另一个符号。但是不管怎样，所有这些编码方式中，0&#8212;127表示的符号是一样的，不一样的只是128&#8212;255的这一段。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">至于亚洲国家的文字，使用的符号就更多了，汉字就多达10万左右。一个字节只能表示256种符号，肯定是不够的，就必须使用多个字节表达一个符号。比如，简体中文常见的编码方式是GB2312，使用两个字节表示一个汉字，所以理论上最多可以表示256x256=65536个符号。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">中文编码的问题需要专文讨论，这篇笔记不涉及。这里只指出，虽然都是用多个字节表示一个符号，但是GB类的汉字编码与后文的Unicode和UTF-8是毫无关系的。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><strong style="font-weight: 800">3.Unicode</strong></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">正如上一节所说，世界上存在着多种编码方式，同一个二进制数字可以被解释成不同的符号。因此，要想打开一个文本文件，就必须知道它的编码方式，否则用错误的编码方式解读，就会出现乱码。为什么电子邮件常常出现乱码？就是因为发信人和收信人使用的编码方式不一样。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">可以想象，如果有一种编码，将世界上所有的符号都纳入其中。每一个符号都给予一个独一无二的编码，那么乱码问题就会消失。这就是Unicode，就像它的名字都表示的，这是一种所有符号的编码。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">Unicode当然是一个很大的集合，现在的规模可以容纳100多万个符号。每个符号的编码都不一样，比如，U+0639表示阿拉伯字母Ain，U+0041表示英语的大写字母A，U+4E25表示汉字&#8220;严&#8221;。具体的符号对应表，可以查询<a style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #223472; border-left-style: none; text-decoration: underline; padding-top: 0px" href="http://www.unicode.org/" target="_blank">unicode.org</a>，或者专门的<a style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #223472; border-left-style: none; text-decoration: underline; padding-top: 0px" href="http://www.chi2ko.com/tool/CJK.htm" target="_blank">汉字对应表</a>。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><strong style="font-weight: 800">4. Unicode的问题</strong></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">需要注意的是，Unicode只是一个符号集，它只规定了符号的二进制代码，却没有规定这个二进制代码应该如何存储。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">比如，汉字&#8220;严&#8221;的unicode是十六进制数4E25，转换成二进制数足足有15位（100111000100101），也就是说这个符号的表示至少需要2个字节。表示其他更大的符号，可能需要3个字节或者4个字节，甚至更多。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">这里就有两个严重的问题，第一个问题是，如何才能区别unicode和ascii？计算机怎么知道三个字节表示一个符号，而不是分别表示三个符号呢？第二个问题是，我们已经知道，英文字母只用一个字节表示就够了，如果unicode统一规定，每个符号用三个或四个字节表示，那么每个英文字母前都必然有二到三个字节是0，这对于存储来说是极大的浪费，文本文件的大小会因此大出二三倍，这是无法接受的。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">它们造成的结果是：1）出现了unicode的多种存储方式，也就是说有许多种不同的二进制格式，可以用来表示unicode。2）unicode在很长一段时间内无法推广，直到互联网的出现。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><strong style="font-weight: 800">5.UTF-8</strong></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">互联网的普及，强烈要求出现一种统一的编码方式。UTF-8就是在互联网上使用最广的一种unicode的实现方式。其他实现方式还包括UTF-16和UTF-32，不过在互联网上基本不用。<span style="color: #ff0000"><strong style="font-weight: 800">重复一遍，这里的关系是，UTF-8是Unicode的实现方式之一。</strong></span></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">UTF-8最大的一个特点，就是它是一种变长的编码方式。它可以使用1~4个字节表示一个符号，根据不同的符号而变化字节长度。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">UTF-8的编码规则很简单，只有二条：</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">1）对于单字节的符号，字节的第一位设为0，后面7位为这个符号的unicode码。因此对于英语字母，UTF-8编码和ASCII码是相同的。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">2）对于n字节的符号（n&gt;1），第一个字节的前n位都设为1，第n+1位设为0，后面字节的前两位一律设为10。剩下的没有提及的二进制位，全部为这个符号的unicode码。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">下表总结了编码规则，字母x表示可用编码的位。</p>
<blockquote style="border-bottom-style: none; text-align: left; padding-bottom: 1em; border-right-style: none; background-color: #e0dfcc; list-style-type: none; font-style: normal; margin: 2em; padding-left: 1em; padding-right: 1em; border-top-style: none; color: #111111; border-left-style: none; text-decoration: none; padding-top: 1em; border-top-left-radius: 20px 20px; border-top-right-radius: 20px 20px; border-bottom-right-radius: 20px 20px; border-bottom-left-radius: 20px 20px">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; border-left-style: none; text-decoration: none; padding-top: 0px">
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">Unicode符号范围 | UTF-8编码方式<br />(十六进制) | （二进制）<br />--------------------+---------------------------------------------<br />0000 0000-0000 007F | 0xxxxxxx<br />0000 0080-0000 07FF | 110xxxxx 10xxxxxx<br />0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx<br />0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx</p></div></blockquote>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">下面，还是以汉字&#8220;严&#8221;为例，演示如何实现UTF-8编码。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">已知&#8220;严&#8221;的unicode是4E25（100111000100101），根据上表，可以发现4E25处在第三行的范围内（0000 0800-0000 FFFF），因此&#8220;严&#8221;的UTF-8编码需要三个字节，即格式是&#8220;1110xxxx 10xxxxxx 10xxxxxx&#8221;。然后，从&#8220;严&#8221;的最后一个二进制位开始，依次从后向前填入格式中的x，多出的位补0。这样就得到了，&#8220;严&#8221;的UTF-8编码是&#8220;11100100 10111000 10100101&#8221;，转换成十六进制就是E4B8A5。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><strong style="font-weight: 800">6. Unicode与UTF-8之间的转换</strong></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">通过上一节的例子，可以看到&#8220;严&#8221;的Unicode码是4E25，UTF-8编码是E4B8A5，两者是不一样的。它们之间的转换可以通过程序实现。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">在Windows平台下，有一个最简单的转化方法，就是使用内置的记事本小程序Notepad.exe。打开文件后，点击&#8220;文件&#8221;菜单中的&#8220;另存为&#8221;命令，会跳出一个对话框，在最底部有一个&#8220;编码&#8221;的下拉条。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><a style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #223472; border-left-style: none; text-decoration: underline; padding-top: 0px" href="http://www.ruanyifeng.com/blog/2007/10/bg2007102801.jpg" target="_blank"><img style="border-bottom-style: solid; text-align: left; border-left: 1px solid; padding-bottom: 0px; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; color: #111111; border-top: 1px solid; border-right: 1px solid; text-decoration: none; padding-top: 0px" alt="bg2007102801.jpg" src="http://www.ruanyifeng.com/blog/2007/10/bg2007102801-thumb.jpg" width="500" height="227" /></a></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">里面有四个选项：ANSI，Unicode，Unicode big endian 和 UTF-8。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">1）ANSI是默认的编码方式。对于英文文件是ASCII编码，对于简体中文文件是GB2312编码（只针对Windows简体中文版，如果是繁体中文版会采用Big5码）。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">2）Unicode编码指的是UCS-2编码方式，即直接用两个字节存入字符的Unicode码。这个选项用的little endian格式。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">3）Unicode big endian编码与上一个选项相对应。我在下一节会解释little endian和big endian的涵义。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">4）UTF-8编码，也就是上一节谈到的编码方法。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">选择完&#8221;编码方式&#8220;后，点击&#8221;保存&#8220;按钮，文件的编码方式就立刻转换好了。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><strong style="font-weight: 800">7. Little endian和Big endian</strong></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">上一节已经提到，Unicode码可以采用UCS-2格式直接存储。以汉字&#8221;严&#8220;为例，Unicode码是4E25，需要用两个字节存储，一个字节是4E，另一个字节是25。存储的时候，4E在前，25在后，就是Big endian方式；25在前，4E在后，就是Little endian方式。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">这两个古怪的名称来自英国作家斯威夫特的《格列佛游记》。在该书中，小人国里爆发了内战，战争起因是人们争论，吃鸡蛋时究竟是从大头(Big-Endian)敲开还是从小头(Little-Endian)敲开。为了这件事情，前后爆发了六次战争，一个皇帝送了命，另一个皇帝丢了王位。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">因此，第一个字节在前，就是&#8221;大头方式&#8220;（Big endian），第二个字节在前就是&#8221;小头方式&#8220;（Little endian）。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">那么很自然的，就会出现一个问题：计算机怎么知道某一个文件到底采用哪一种方式编码？</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">Unicode规范中定义，每一个文件的最前面分别加入一个表示编码顺序的字符，这个字符的名字叫做&#8221;零宽度非换行空格&#8220;（ZERO WIDTH NO-BREAK SPACE），用FEFF表示。这正好是两个字节，而且FF比FE大1。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">如果一个文本文件的头两个字节是FE FF，就表示该文件采用大头方式；如果头两个字节是FF FE，就表示该文件采用小头方式。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><strong style="font-weight: 800">8. 实例</strong></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">下面，举一个实例。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">打开&#8221;记事本&#8220;程序Notepad.exe，新建一个文本文件，内容就是一个&#8221;严&#8220;字，依次采用ANSI，Unicode，Unicode big endian 和 UTF-8编码方式保存。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">然后，用文本编辑软件<a style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #223472; border-left-style: none; text-decoration: underline; padding-top: 0px" href="http://www.google.cn/search?aq=t&amp;oq=UltraEdit&amp;complete=1&amp;hl=zh-CN&amp;newwindow=1&amp;rlz=1B3GGGL_zh-CNCN216CN216&amp;q=ultraedit+%E4%B8%8B%E8%BD%BD&amp;btnG=Google+%E6%90%9C%E7%B4%A2&amp;meta=" target="_blank">UltraEdit中</a>的&#8221;十六进制功能&#8220;，观察该文件的内部编码方式。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">1）ANSI：文件的编码就是两个字节&#8220;D1 CF&#8221;，这正是&#8220;严&#8221;的GB2312编码，这也暗示GB2312是采用大头方式存储的。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">2）Unicode：编码是四个字节&#8220;FF FE 25 4E&#8221;，其中&#8220;FF FE&#8221;表明是小头方式存储，真正的编码是4E25。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">3）Unicode big endian：编码是四个字节&#8220;FE FF 4E 25&#8221;，其中&#8220;FE FF&#8221;表明是大头方式存储。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">4）UTF-8：编码是六个字节&#8220;EF BB BF E4 B8 A5&#8221;，前三个字节&#8220;EF BB BF&#8221;表示这是UTF-8编码，后三个&#8220;E4B8A5&#8221;就是&#8220;严&#8221;的具体编码，它的存储顺序与编码顺序是一致的。</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px"><strong style="font-weight: 800">9. 延伸阅读</strong></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">*&nbsp;<a style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #223472; border-left-style: none; text-decoration: underline; padding-top: 0px" href="http://www.joelonsoftware.com/articles/Unicode.html" target="_blank">The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets</a>（关于字符集的最基本知识）</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">*&nbsp;<a style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #223472; border-left-style: none; text-decoration: underline; padding-top: 0px" href="http://www.pconline.com.cn/pcedu/empolder/gj/other/0505/616631.html" target="_blank">谈谈Unicode编码</a></p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">*&nbsp;<a style="border-bottom-style: none; text-align: left; padding-bottom: 0px; border-right-style: none; list-style-type: none; font-style: normal; margin: 0px; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #223472; border-left-style: none; text-decoration: underline; padding-top: 0px" href="http://www.ietf.org/rfc/rfc3629.txt" target="_blank">RFC3629：UTF-8, a transformation format of ISO 10646</a>（如果实现UTF-8的规定）</p>
<p style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 28px; border-right-style: none; list-style-type: none; font-style: normal; margin: 1em 0px 0px 0.8em; padding-left: 0px; padding-right: 0px; border-top-style: none; color: #111111; font-size: 1.6em; border-left-style: none; text-decoration: none; padding-top: 0px">（完）</p></div><br /><br />转自：<a href="http://www.cnblogs.com/chenwenbiao/archive/2011/08/11/2134503.html">http://www.cnblogs.com/chenwenbiao/archive/2011/08/11/2134503.html</a><img src ="http://www.cppblog.com/LIULIANG/aggbug/195326.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/LIULIANG/" target="_blank">BIG森林</a> 2012-11-18 21:00 <a href="http://www.cppblog.com/LIULIANG/archive/2012/11/18/195326.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>http请求方式</title><link>http://www.cppblog.com/LIULIANG/archive/2012/11/14/195202.html</link><dc:creator>BIG森林</dc:creator><author>BIG森林</author><pubDate>Wed, 14 Nov 2012 12:39:00 GMT</pubDate><guid>http://www.cppblog.com/LIULIANG/archive/2012/11/14/195202.html</guid><wfw:comment>http://www.cppblog.com/LIULIANG/comments/195202.html</wfw:comment><comments>http://www.cppblog.com/LIULIANG/archive/2012/11/14/195202.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/LIULIANG/comments/commentRss/195202.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/LIULIANG/services/trackbacks/195202.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: HTTP请求格式当浏览器向Web服务器发出请求时，它向服务器传递了一个数据块，也就是请求信息，HTTP请求信息由3部分组成：l&nbsp;&nbsp; 请求方法URI协议/版本l&nbsp;&nbsp; 请求头(Request Header)l&nbsp;&nbsp; 请求正文下面是一个HTTP请求的例子：GET/sample.jspHTTP/1.1&nbsp;...&nbsp;&nbsp;<a href='http://www.cppblog.com/LIULIANG/archive/2012/11/14/195202.html'>阅读全文</a><img src ="http://www.cppblog.com/LIULIANG/aggbug/195202.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/LIULIANG/" target="_blank">BIG森林</a> 2012-11-14 20:39 <a href="http://www.cppblog.com/LIULIANG/archive/2012/11/14/195202.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL注入攻击--初学</title><link>http://www.cppblog.com/LIULIANG/archive/2012/08/23/188055.html</link><dc:creator>BIG森林</dc:creator><author>BIG森林</author><pubDate>Thu, 23 Aug 2012 08:49:00 GMT</pubDate><guid>http://www.cppblog.com/LIULIANG/archive/2012/08/23/188055.html</guid><wfw:comment>http://www.cppblog.com/LIULIANG/comments/188055.html</wfw:comment><comments>http://www.cppblog.com/LIULIANG/archive/2012/08/23/188055.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/LIULIANG/comments/commentRss/188055.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/LIULIANG/services/trackbacks/188055.html</trackback:ping><description><![CDATA[<div>&nbsp;&nbsp;&nbsp; SQL注入攻击，虽然使用数据库已经有接两年了，也做过一个实际的项目，但是都没有注意到这个问题，可悲啊，现在回想起来上次做的系统，会不会也有这一类的完全隐患，不敢想啊，不过还没有交去改代码，就可能还没有大的问题，好了就说到这，今天在看web安全问题时，发现了SQL注入攻击，并且看到了一个关于SQL注入攻击的一个经典的例子，下面我们就演示一下吧，加强一下我的记忆，我也是刚接触SQL注入攻击，还希望熟悉SQL注入攻击人士给我指点指点。<br />&nbsp; 我们看一下这样一段代码（jsp页面）<br />&nbsp;&nbsp;&nbsp; Statement stmt=conn.createStatement();<br />&nbsp;&nbsp;&nbsp; String strCmd="select username from users where username="+" ' "+name+" 'and password=' "+pwd+" ' ";<br />&nbsp;&nbsp; ResultSet rs=stmt.executeQuery(strCmd);<br />&nbsp;&nbsp; if(rs.next()){<br />&nbsp;&nbsp;&nbsp;&nbsp; session.setAttribute("user" ,name);<br />&nbsp;&nbsp;&nbsp; response.sendRedirect("admin.jsp");<br />&nbsp;&nbsp;&nbsp; return;<br />&nbsp;&nbsp; }else{<br />&nbsp;&nbsp;&nbsp;&nbsp; response.sendRedirect("login.jsp");<br />&nbsp;&nbsp;&nbsp; return;<br />&nbsp;&nbsp;&nbsp;}<br />&nbsp; 这段代码就是判断登陆的用户是否为管理员，如果是，就显示管理员页面，否则就让用户重新登陆。<br />&nbsp;&nbsp;如果用户输入用户名zhangsan，密码1234<br />那么构造的SQL语句就是如下所示：<br />select username from users where username='zhangsan' and password='1234'<br />&nbsp;如果恶意的用户通过查看我们的网页源代码，知道了表单中输入的用户名的文本域和口领域的名字，直接在浏览器中地址栏中输入的地址如下<br />&nbsp; <a href="http://www.xxx.com/login.jsp?name=abc&amp;password=111'or'1'=1">http://www.xxx.com:80/login.jsp?name=abc&amp;password=111'or'1'=1</a><br />&nbsp;&nbsp;这样就可以上顺利的访问管理员页面，为什么随便输入一个用户名和密码就能直接访问管理员页面呢？我们通过构造出来的SQL语句明白了，构造出来的SQL语句如下：<br />&nbsp; select username from users where username='abc' and password='111'or'1'=1<br />这样我们就明白了为什么随便输入一个用户名和密码就能直接访问管理员页面吧，上面查询语句中最后一部分&#8220;or'1'=1&#8221;是个恒等式，这样就会将我们users表中的数据全部查询出来。我们可以使用存储过程来解决这个问题，关于怎样具体的去解决，这里就不说了。<br />这算是对SQL注入攻击的一个初识吧。</div><img src ="http://www.cppblog.com/LIULIANG/aggbug/188055.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/LIULIANG/" target="_blank">BIG森林</a> 2012-08-23 16:49 <a href="http://www.cppblog.com/LIULIANG/archive/2012/08/23/188055.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>怎样引用Commons-Fileupload 实现文件上传和下载</title><link>http://www.cppblog.com/LIULIANG/archive/2012/08/22/187933.html</link><dc:creator>BIG森林</dc:creator><author>BIG森林</author><pubDate>Wed, 22 Aug 2012 02:50:00 GMT</pubDate><guid>http://www.cppblog.com/LIULIANG/archive/2012/08/22/187933.html</guid><wfw:comment>http://www.cppblog.com/LIULIANG/comments/187933.html</wfw:comment><comments>http://www.cppblog.com/LIULIANG/archive/2012/08/22/187933.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/LIULIANG/comments/commentRss/187933.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/LIULIANG/services/trackbacks/187933.html</trackback:ping><description><![CDATA[<legend>一、准备：</legend><br />1、 下载 commons-fileupload 库，下载地址：<a href="http://commons.apache.org/fileupload/" target="_blank">http://commons.apache.org/fileupload/</a><br />2、 下载 commons-fileupload 依赖库 commons-io，下载地址：<a href="http://commons.apache.org/io/" target="_blank">http://commons.apache.org/io/</a><br /><br />推荐文章：<br /><a href="http://blog.csdn.net/hbcui1984/archive/2007/01/30/1498112.aspx" target="_blank">1、利用MultipartFile实现文件上传<br /></a><a href="http://blog.csdn.net/hbcui1984/archive/2007/05/25/1625754.aspx" target="_blank">2、利用Jakarta commons fileupload组件实现多文件上传</a><br />&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.blogjava.net/sitinspring/archive/2008/04/12/192408.html" target="_blank">使用commons-fileupload实现单个和多个文件上传 <br /></a><a href="http://blog.csdn.net/hbcui1984/archive/2007/05/29/1629151.aspx" target="_blank">3、对commons fileupload组件的简单封装</a> 
<p>4、Apache FileUpload文件上传组件API解析<br /><a href="http://commons.apache.org/fileupload/using.html" target="_blank">5、User Guide</a>&nbsp; &nbsp;&nbsp; <a href="http://dev.csdn.net/article/53/53657.shtm" target="_blank">Apache Jakarta Project: commons FileUpload用户指南</a><a href="http://commons.apache.org/fileupload/using.html" target="_blank"><br /></a></p>
<p>注：DiskFileUpload 在 javadoc 下被标记为过期的方法，建议用 ServletFileUpload 代替。</p><br />&nbsp;&nbsp;我们如果想通过commons-fileupload库来实现文件上传和下载功能，我们就必须在我们的web应用程序中引入以下两个jar包<br />commons-fileupload-1.2.2.jar<br />commons-io-2.4.jar<br />以上连个jar包分别位于commons-fileupload 库和commons-io库中，我们下载了commons-fileupload 和commons-io后，解压下载后的文件就能找到它们了，<br />接下来我们就可以使用它们来实现文件上传和下载功能。<br /><br />如果向看看怎样具体代码是怎样实现的，请参看<a href="http://www.cnblogs.com/kiant71/archive/2008/10/04/1752068.html">http://www.cnblogs.com/kiant71/archive/2008/10/04/1752068.html</a><br /><img src ="http://www.cppblog.com/LIULIANG/aggbug/187933.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/LIULIANG/" target="_blank">BIG森林</a> 2012-08-22 10:50 <a href="http://www.cppblog.com/LIULIANG/archive/2012/08/22/187933.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在eclipse中新建servlet</title><link>http://www.cppblog.com/LIULIANG/archive/2012/08/22/187932.html</link><dc:creator>BIG森林</dc:creator><author>BIG森林</author><pubDate>Wed, 22 Aug 2012 02:42:00 GMT</pubDate><guid>http://www.cppblog.com/LIULIANG/archive/2012/08/22/187932.html</guid><wfw:comment>http://www.cppblog.com/LIULIANG/comments/187932.html</wfw:comment><comments>http://www.cppblog.com/LIULIANG/archive/2012/08/22/187932.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/LIULIANG/comments/commentRss/187932.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/LIULIANG/services/trackbacks/187932.html</trackback:ping><description><![CDATA[<p>用Eclipse建立servlet工程<br />1.打开eclipse，选择【文件】|【新建】|【项目】</p>
<p>2.选择【Tomcat&nbsp;&nbsp; Project】后单击下一步，输入项目名【TestTomcat】，选择下一步，将【Can update context definition】打钩，点击完成。</p>
<p>3.创建servlet类：</p>
<p>在导航器中右击【TestTomcat】 工程，单击【新建】|【类】，这里包名写【test】，类的名称写【HelloWorld】，超类的名称写上 【javax.servlet.http.HttpServlet】，单击完成后在TestTomcat/Web-INF/src下出现新的包test， 包里面有一个刚刚建立的HelloWorld类。</p>
<p>4.编写servlet类的内容：</p>
<p>右击【HelloWorld.java】文件内容，在弹出的菜单中单击【源代码】|【覆盖/实现方法】后在对话框中选择【doGet()】函数前的复选框，点【确定】。</p>
<p>输入一下内容：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; PrintWriter out=arg1.getWriter();<br />&nbsp;&nbsp;&nbsp;&nbsp; out.print("HelloWorld");</p>
<p>右击&nbsp;&nbsp;&nbsp;&nbsp; PrintWriter,选择【源代码】|【组织导入】，然后右击【TestTomcat】工程，选择【属性】|【java构建路径】|【排序和导出】|【全部选中】|【确定】，得到HelloWorld.java源文件全部内容如下：</p>
<p>package test;</p>
<p>import java.io.IOException;<br />import java.io.PrintWriter;</p>
<p>import javax.servlet.ServletException;<br />import javax.servlet.http.HttpServlet;<br />import javax.servlet.http.HttpServletRequest;<br />import javax.servlet.http.HttpServletResponse;</p>
<p>public class HelloWorld extends HttpServlet {</p>
<p>@Override<br />protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {<br />&nbsp;&nbsp;&nbsp;&nbsp; PrintWriter out=arg1.getWriter();<br />&nbsp;&nbsp;&nbsp;&nbsp; out.print("HelloWorld");</p>
<p>}</p>
<p>}</p>
<p>5.创建该工程的部署文件（web.xml）：</p>
<p>右击/TestTomcat/Web-INF文件夹，选择建立【文件】，输入文件名【web.xml】后打开该文件，在文件中填写如下代码：</p>
<p>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;<br />&lt;web-app&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &lt;servlet&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;servlet-name&gt;Test&lt;/servlet-name&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;servlet-class&gt;test.HelloWorld&lt;/servlet-class&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;/servlet&gt;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; &lt;servlet-mapping&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;servlet-name&gt;Test&lt;/servlet-name&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;url-pattern&gt;/test/*&lt;/url-pattern&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;/servlet-mapping&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;session-config&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;session-timeout&gt;30&lt;/session-timeout&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;/session-config&gt;<br />&lt;/web-app&gt;</p>
<p>6.检查一下最终eclipse中TestTomcat工程中的文件结构为：</p>
<p>\---TestTomcat<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; .classpath<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; .cvsignore<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; .project<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; .tomcatplugin<br />&nbsp;&nbsp;&nbsp;&nbsp; |<br />&nbsp;&nbsp;&nbsp;&nbsp; +---WEB-INF<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; .cvsignore<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; web.xml<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; |<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; +---classes<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; \---test<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelloWorld.class<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; |<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; +---lib<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; \---src<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \---test<br />&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HelloWorld.java<br />&nbsp;&nbsp;&nbsp;&nbsp; |<br />&nbsp;&nbsp;&nbsp;&nbsp; \---work<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tldCache.ser</p>
<p>7.运行建立的servlet：</p>
<p>启动集成在eclipse里面的tomcat，打开IE,地址栏里面输入：</p>
<p><a href="http://localhost:8080/TestTomcat/test/HelloWorld">http://localhost:8080/TestTomcat/test/HelloWorld</a>，即可看到该servlet的运行结果：<br />HelloWorld<br /></p><img src ="http://www.cppblog.com/LIULIANG/aggbug/187932.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/LIULIANG/" target="_blank">BIG森林</a> 2012-08-22 10:42 <a href="http://www.cppblog.com/LIULIANG/archive/2012/08/22/187932.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>j2ee学习01----环境安装和配置（JDK、Tomcat、Eclipse） </title><link>http://www.cppblog.com/LIULIANG/archive/2012/08/20/187795.html</link><dc:creator>BIG森林</dc:creator><author>BIG森林</author><pubDate>Mon, 20 Aug 2012 14:01:00 GMT</pubDate><guid>http://www.cppblog.com/LIULIANG/archive/2012/08/20/187795.html</guid><wfw:comment>http://www.cppblog.com/LIULIANG/comments/187795.html</wfw:comment><comments>http://www.cppblog.com/LIULIANG/archive/2012/08/20/187795.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/LIULIANG/comments/commentRss/187795.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/LIULIANG/services/trackbacks/187795.html</trackback:ping><description><![CDATA[<p>1、安装JDK（JDK网上安装教程，大家一搜一大把的！呵呵，在此我就不详讲）。 </p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp; <span style="color: #ff0000">安装注意：XP和win7的环境变量配置好型有点不一样。XP下，需要把JAVA_HOME..全部填上，WIN7貌似不需要，只需要将path路径延伸到Bin路径下就OK！</span> </p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp; 测试：大家熟悉的HelloWorld程序呼之欲出！ </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>2、安装Tomcat </p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; 下载 Tomcat ，目前到7.X.我现在还是比较喜欢用6.X的。所有下载的是6.X的。建议到官网上下载。有安装版的和解压包的两种。</p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; <span style="color: #ff0000">环境变量配置：（本人从网上搜索出来很多，但是有的可能已经老了，请大家注意一下，6.X的没有那个common文件夹了。）好像安装版的和非安装版的都不需要再配什么环境变量了！</span> </p>
<p>&nbsp;</p>
<p>&nbsp;&nbsp;&nbsp; 测试：DOS进入（C:\apache-tomcat-6.0.32\bin）tomcat安装路径的bin文件夹下。输入startup 则会显示你启动服务器。然后输入经典的：<a href="http://localhost:8080/">http://localhost:8080/</a> （在配置中可以修改端口</p>
<p>&nbsp;&nbsp; C:\apache-tomcat-7.0.14\apache-tomcat-7.0.14\conf\server.xml&nbsp; 找到自己的server.xml路径）</p>
<p>&nbsp;&nbsp;&nbsp; 出现经典的tomcat首页</p>
<p>&nbsp;</p>
<p>&nbsp; 测试二：在tomcat安装的路径下，找到webapps文件夹。在里面建立一个自己的文件夹（myweb）,在该文件夹下建立两个文件。一个WEB.XML文件和1.jsp文件</p>
<p>&nbsp; <img height="118" alt="" src="http://dl.iteye.com/upload/attachment/480606/de919c28-672a-358f-8e42-34261778c415.jpg" width="528" /></p>
<p>&nbsp;</p>
<p>代码分别为：</p>
<p><span style="color: #003366"><br /></span></p>
<p><span style="color: #003366">&lt;?xml version="1.0" encoding="utf-8"?&gt;<br /><br />&lt;!DOCTYPE web-app<br />PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"<br />"http://java.sun.com/dtd/web-app_2_3.dtd"&gt;<br /><br />&lt;web-app&gt;<br />&lt;display-name&gt;My Web Application&lt;/display-name&gt;<br />&lt;description&gt;<br />&nbsp;&nbsp;&nbsp; A application for test.<br />&lt;/description&gt;<br />&lt;/web-app&gt; </span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>1.jsp</p>
<p>&nbsp;</p>
<p><span style="color: #003366">&lt;html&gt;<br />&lt;body&gt;<br />&lt;center&gt;<br />&nbsp;&nbsp;&nbsp; Now time is: &lt;%=new java.util.Date()%&gt;<br />&lt;/center&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</span> </p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>在浏览器输入<a href="http://localhost:8080/myweb/1.jsp">http://localhost:8080/myweb/1.jsp</a> </p>
<p>&nbsp;</p>
<p>如果正常显示时间，则为OK!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;3、eclipse安装（copy别人的。呵呵！）</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><strong><span style="font-size: small">前言</span></strong><span style="font-size: 10pt; color: #555555"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 10pt; color: #0000ff">Eclipse</span>是最流行的功能强大的<span style="font-size: 10pt; color: #0000ff">java IDE</span>，有丰富的插件，配合插件可以作为<span style="font-size: 10pt; color: #0000ff">j2ee</span>、<span style="font-size: 10pt; color: #0000ff">c</span>、<span style="font-size: 10pt; color: #0000ff">c++</span>、<span style="font-size: 10pt; color: #0000ff">.net</span>等开发工具。需要安装插件才能支持<span style="font-size: 10pt; color: #0000ff">Web</span>开发和其他应用的开发，这是<span style="font-size: 10pt; color: #0000ff">eclipse</span>的优点，也是<span style="font-size: 10pt; color: #0000ff">eclipse</span>的缺点，优点在于灵活，缺点在于麻烦。在此主要介绍<span style="font-size: 10pt; color: #0000ff">windows</span>环境下<span style="font-size: 10pt; color: #0000ff">Eclipse</span>如何安装配置插件一般方法，如何优化，并就常见的问题给以解答，并给出<span style="font-size: 10pt; color: #0000ff">Eclipse</span>作为<span style="font-size: 10pt; color: #0000ff">J2EE</span>开发工具的插件方案。再说明一点，<span style="font-size: 10pt; color: #0000ff">Eclipse</span>是一个<span style="font-size: 10pt; color: #0000ff">Java</span>开发的<span style="font-size: 10pt; color: #0000ff">IDE</span>工具，需要有<span style="font-size: 10pt; color: #0000ff">Java</span>运行环境的支持，最新的<span style="font-size: 10pt; color: #0000ff">eclipse3.2.2</span>需要<span style="font-size: 10pt; color: #0000ff">1.4</span>以上版本的<span style="font-size: 10pt; color: #0000ff">jdk</span>。<span style="font-size: 10pt; color: #555555"><br /><br /></span><strong><span style="font-size: small">一、下载安装<span style="color: #ff0000">Eclipse</span></span></strong><span style="font-size: 10pt; color: #555555"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000">打开<span style="font-size: 10pt; color: #555555">[url]www.eclipse.org[/url]</span>，在首页上找下载栏目，下载最新的<span style="font-size: 10pt; color: #555555">eclipse-SDK-3.2.2-win32.zip</span>和中文语言包<span style="font-size: 10pt; color: #555555">NLpack1-eclipse-SDK-3.2.1-win32.zip</span>；</span><span style="font-size: 10pt; color: #555555"><br /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: #000000">解压缩<span style="font-size: 10pt; color: #555555">eclipse-SDK-3.2.2-win32.zip</span>到一个目录，假如解压缩到<span style="font-size: 10pt; color: #555555">F:\</span>下面，则会生成一个<span style="font-size: 10pt; color: #555555">F:\eclipse</span>文件夹，这个是<span style="font-size: 10pt; color: #555555">eclipse</span>的文件夹；解压缩<span style="font-size: 10pt; color: #555555">NLpack1-eclipse-SDK-3.2.1-win32.zip</span>到一个目录，复制其中<span style="font-size: 10pt; color: #555555">plugins</span>目录下的所有文件和文件夹到<span style="font-size: 10pt; color: #555555">F:\eclipse\plugins</span>，复制其中<span style="font-size: 10pt; color: #555555">features</span>目录下的所有文件和文件夹到<span style="font-size: 10pt; color: #555555">F:\eclipse\features</span>；</span><span style="font-size: 10pt; color: #555555"><br /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: #000000">运行<span style="font-size: 10pt; color: #555555">F:\eclipse\eclipse.exe</span>即可启动一个中文版的<span style="font-size: 10pt; color: #555555">Eclipse</span>。</span><span style="font-size: 10pt; color: #555555"><br /><br /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="color: #000000">这个是<span style="font-size: 10pt; color: #555555">eclipse</span>最基本的安装配置方法，如果你不要安装中文版，那么你直接解压缩<span style="font-size: 10pt; color: #555555">eclipse-SDK-3.2.2-win32.zip</span>到任意一个目录，然后运行<span style="font-size: 10pt; color: #555555">eclipse.exe</span>即可。这里的语言包<span style="font-size: 10pt; color: #555555">NLpack1-eclipse-SDK-3.2.1-win32.zip</span>实际上一个<span style="font-size: 10pt; color: #555555">eclipse</span>插件！</span><span style="font-size: 10pt; color: #555555"><br /><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eclipse</span></span><span style="color: #000000">的插件实际上都有一个目录规范<span style="font-size: 10pt; color: #555555">eclipse</span>、<span style="font-size: 10pt; color: #555555">eclipse\features</span>、<span style="font-size: 10pt; color: #555555">eclipse\plugins</span>，安装的时候也很简单，上面介绍的方法就是其中一种，在此我称之为&#8220;侵入式安装插件方法&#8221;。从上面插件安装过程可以看出&#8220;侵入式安装插件方法&#8221;就是简单的将插件中<span style="font-size: 10pt; color: #555555">eclipse\features</span>、<span style="font-size: 10pt; color: #555555">eclipse\plugins</span>复制到<span style="font-size: 10pt; color: #555555">eclipse</span>安装目录中的<span style="font-size: 10pt; color: #555555">eclipse\features</span>、<span style="font-size: 10pt; color: #555555">eclipse\plugins</span>下面即可，这种安装方式有个严重缺陷，就是安装后，实际上是不可以卸载，安装过程不可逆转，无法灵活配置管理所安装的插件。</span><span style="font-size: 10pt; color: #555555"><br /><br /></span><span style="font-size: small"><strong>二、非侵入式安装插件方法（<span style="color: #ff0000">links</span></strong><strong>安装方法）</strong></span><span style="font-size: 10pt; color: #555555"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>既然有侵入式的安装，言下之意，还有个&#8220;非侵入式安装&#8221;，也有人成为<span style="font-size: 10pt; color: #555555">links</span>安装方法，下面看究竟是如何安装的：<span style="font-size: 10pt; color: #555555">).<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>非侵入式安装也分两种，一种是绝对路径安装方法，一种是相对路径的安装方法。首先看绝对路径的安装的方法。<span style="font-size: 10pt; color: #555555"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>在上面安装过程中，我们将中文语言包<span style="font-size: 10pt; color: #555555">NLpack1-eclipse-SDK-3.2.1-win32.zip</span>插件解压缩到一个地方假设为<span style="font-size: 10pt; color: #555555">F:\myplugins</span>目录文件夹的目录结构如下：<span style="font-size: 10pt; color: #555555"><br /></span><span style="font-size: 10pt; color: #ff1493">&nbsp;&nbsp; &nbsp;NLpack1-eclipse-SDK-3.2.1-win32<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;eclipse<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;features<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;plugins</span><span style="font-size: 10pt; color: #555555"><br /></span>然后在<span style="font-size: 10pt; color: #555555">eclipse</span>的安装目录下新建一个文件夹<span style="font-size: 10pt; color: #555555">links,</span>在新建一个文本文档（后缀名可以是<span style="font-size: 10pt; color: #555555">.aaa</span>、<span style="font-size: 10pt; color: #555555">.zz</span>而不一定是<span style="font-size: 10pt; color: #555555">.txt</span>）<span style="font-size: 10pt; color: #555555">NLpack1-eclipse-SDK-3.2.1-win32.txt</span>，内容如下：<span style="font-size: 10pt; color: #555555">path=F:/myplugins/NLpack1-eclipse-SDK-3.2.1-win32</span>，路径的间隔符为&#8220;<span style="font-size: 10pt; color: #555555"> /</span>&#8221;或&#8220;<span style="font-size: 10pt; color: #555555">\\</span>&#8221;。这样这个插件就安装好了。<span style="font-size: 10pt; color: #555555"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>上面这个是&#8220;非侵入式绝对路径插件安装&#8221;方法，下面看如何变绝对为相对，使<span style="font-size: 10pt; color: #555555">eclipse</span>的运行不再依赖绝对路径，这正是相对路径安装的优点。<span style="font-size: 10pt; color: #555555"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>在上绝对路径安装过程中，我们在<span style="font-size: 10pt; color: #555555">eclipe</span>安装目录<span style="font-size: 10pt; color: #555555">F:\eclipse</span>下面新建一个<span style="font-size: 10pt; color: #555555">links</span>和<span style="font-size: 10pt; color: #555555">myplugins</span>文件夹，将中文语言包插件<span style="font-size: 10pt; color: #555555">NLpack1-eclipse-SDK-3.2.1-win32.zip</span>解压缩到<span style="font-size: 10pt; color: #555555">F:\eclipse\myplugins</span>下面，目录结构不变。然后在<span style="font-size: 10pt; color: #555555">links</span>目录中修改新建一个文件<span style="font-size: 10pt; color: #555555">NLpack1-eclipse-SDK-3.2.1-win32.txt</span>，内容如下：<span style="font-size: 10pt; color: #555555">path=myplugins/NLpack1-eclipse-SDK-3.2.1-win32</span>，这样就可以了。<span style="font-size: 10pt; color: #555555"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>相对路径安装需要注意一点就是插件的目录<span style="font-size: 10pt; color: #555555">myplugins</span>一定要建在<span style="font-size: 10pt; color: #555555">eclipse</span>的安装目录下面，可任意命名，所有的插件最好都放到这个目录（方便管理），每个插件对应一个<span style="font-size: 10pt; color: #555555">links</span>目录里的一个文本配置文件。<span style="font-size: 10pt; color: #555555">links</span>目录的名字只能是命名为<span style="font-size: 10pt; color: #555555">links</span>。<span style="font-size: 10pt; color: #555555"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>这个安装过程很清楚，我就不做安装过程总结了，另外，还有一些插件是在线安装的，这就另当别论了，不过我还是强烈建议你用<span style="font-size: 10pt; color: #555555">links</span>安装方法。<span style="font-size: 10pt; color: #555555"><br /><br /></span><span style="font-size: small"><strong>三、扩展<span style="color: #ff0000">Eclipe</span></strong><strong>为<span style="color: #ff0000">J2EE IDE</span></strong></span><span style="font-size: 10pt; color: #555555"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Eclipse</span>是个<span style="font-size: 10pt; color: #555555">Java IDE</span>，要作为<span style="font-size: 10pt; color: #555555">J2EE</span>开发工具，需要安装插件，这一类插件也比较多，为了节省你我宝贵的时间，我就介绍一下最好用，最流行，最容易获得的一个插件<span style="font-size: 10pt; color: #555555">--WTP</span>，<span style="font-size: 10pt; color: #555555">WTP</span>是一个拥有广大用户基础和开发者的开源插件，<span style="font-size: 10pt; color: #555555">WTP</span>的出现改写<span style="font-size: 10pt; color: #555555">Java IDE</span>的发展史，更准确的说，<span style="font-size: 10pt; color: #555555">WTP</span>是从<span style="font-size: 10pt; color: #555555">06</span>年初开始火起来！到现在也就一个年头多一点。<span style="font-size: 10pt; color: #555555"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>下面看如何获取和安装配置。打开<span style="font-size: 10pt; color: #555555">[url]www.eclipse.org[/url]</span>的<span style="font-size: 10pt; color: #555555">downloads</span>栏目，在页面上有一个显示热点插件的下载排行，<span style="font-size: 10pt; color: #555555">WTP</span>不负众望，总是排在<span style="font-size: 10pt; color: #555555">No1</span>，呵呵，好找吧。为了以后开发方便，我们一步到位，下载个完整版的<span style="font-size: 10pt; color: #555555">wtp</span>插件<span style="font-size: 10pt; color: #555555">wtp-wst-sdk-R-1.5.3.zip</span>或者<span style="font-size: 10pt; color: #555555">wtp-wst-R-1.5.3.zip</span>，这两个的差别在于<span style="font-size: 10pt; color: #555555">sdk</span>的带源码，别的没什么差别！不带源码的运行速度稍微快一点（理论上），但是我感觉不到，呵呵。如果你需要中文包，在下个<span style="font-size: 10pt; color: #555555">NLpack1-wtp-sdk-R-1.5.1-200609230508a.zip</span>或者<span style="font-size: 10pt; color: #555555">NLpack1-wtp-R-1.5.1-200609230508a.zip</span>，下载的地址很多，这么弱弱的问题我不说了，然后按照上面介绍的方法安装就可以了。<span style="font-size: 10pt; color: #555555"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>如果你是做<span style="font-size: 10pt; color: #555555">J2EE</span>或者<span style="font-size: 10pt; color: #555555">java web</span>开发的，那么你就直接下载一个集成了<span style="font-size: 10pt; color: #555555">eclipse</span>的<span style="font-size: 10pt; color: #555555">wtp</span>：<span style="font-size: 10pt; color: #555555">wtp-all-in-one-sdk-R-1.5.3-win32.zip</span>，这样会更好，你最多需要安装两个语言包，这样就更省事了，呵呵。<span style="font-size: 10pt; color: #555555"><br /><br /></span><strong><span style="font-size: small">四、优化</span></strong><span style="font-size: 10pt; color: #555555"><br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>优化的目的是为了让<span style="font-size: 10pt; color: #555555">eclipse</span>运行更稳定更流畅更快！<span style="font-size: 10pt; color: #555555"><br /></span>首先：内存优化<span style="font-size: 10pt; color: #555555"><br />eclipse</span>安装后，在安装目录有个<span style="font-size: 10pt; color: #555555">eclipse.ini</span>文件，内容如下：<span style="font-size: 10pt; color: #555555"><br /></span><span style="font-size: 10pt; color: #ff1493">-vmargs<br />-Xms40m<br />-Xmx256m</span><span style="font-size: 10pt; color: #555555"><br /></span>这个文件用来配置<span style="font-size: 10pt; color: #555555">eclipse</span>启动时候的内存分配方案，<span style="font-size: 10pt; color: #555555">Xms</span>是初始化内存大小，<span style="font-size: 10pt; color: #555555">Xmx</span>是最大可使用内存大小，这个默认的配置是<span style="font-size: 10pt; color: #555555">eclipse</span>资源消耗最小化的配置。如果你的项目比较大，这个配置必须改，一般适当调整为<span style="font-size: 10pt; color: #555555">128</span>，<span style="font-size: 10pt; color: #555555">384</span>即可，若项目更大一些则调整的再大一些，根据实际情况决定。这个参数配置的大小很关键，太小，<span style="font-size: 10pt; color: #555555">eclipse</span>垃圾回收会过于频繁导致很慢，或者内存堆栈溢出而崩溃。太大，<span style="font-size: 10pt; color: #555555">eclipse</span>会吃掉大量内存，垃圾回收周期变长，但每次回收会很慢，影响使用。所以你在配置的时候需要权衡，尝试！<span style="font-size: 10pt; color: #555555"><br /></span>其次：插件优化<span style="font-size: 10pt; color: #555555"><br /></span>当你安装了多个插件的时候，会消耗很大的内存资源，为此你只需要将不用的插件配置文件从<span style="font-size: 10pt; color: #555555">links</span>目录移除，注意了，不是删除，你可以在<span style="font-size: 10pt; color: #555555">links</span>目录里面新建一个<span style="font-size: 10pt; color: #555555">_useless</span>，将不用的配置文件移放到其中，用的时候再移放回来。<span style="font-size: 10pt; color: #555555"><br /><br /></span><strong><span style="font-size: small">五、常见问题解决</span></strong><span style="font-size: 10pt; color: #555555"><br /><br />1</span>、<span style="font-size: 10pt; color: #555555">eclipse</span>语言包或者其他插件没有安装上<span style="font-size: 10pt; color: #555555"><br /></span>原<span style="font-size: 10pt; color: #555555">&nbsp;&nbsp;&nbsp; </span>因：是你可能运行过了英文版的<span style="font-size: 10pt; color: #555555">eclipse</span>之后才装语言包的。<span style="font-size: 10pt; color: #555555"><br /></span>解决办法：删掉<span style="font-size: 10pt; color: #555555">configuration</span>中除了<span style="font-size: 10pt; color: #555555">config.ini</span>以外的所有文件和文件夹，确保插件安装配置正确。<span style="font-size: 10pt; color: #555555"><br /><br />2</span>、<span style="font-size: 10pt; color: #555555">eclipse</span>启动不了<span style="font-size: 10pt; color: #555555"><br /></span>原<span style="font-size: 10pt; color: #555555">&nbsp;&nbsp;&nbsp; </span>因：没有正确安装<span style="font-size: 10pt; color: #555555">jdk</span>，或者没有配置<span style="font-size: 10pt; color: #555555">jdk</span>，一般情况下安装<span style="font-size: 10pt; color: #555555">jdk</span>后需要配置，但当你装过多次<span style="font-size: 10pt; color: #555555">jdk</span>或者用以前系统中遗留下载的已经安装过的<span style="font-size: 10pt; color: #555555">jdk</span>的时候，需要配置<span style="font-size: 10pt; color: #555555">jdk</span>，同时还要注意<span style="font-size: 10pt; color: #555555">eclipse</span>对<span style="font-size: 10pt; color: #555555">jdk</span>的版本的要求。<span style="font-size: 10pt; color: #555555"><br /></span>解决办法：配置<span style="font-size: 10pt; color: #555555">JDK</span>。也就是配置系统变量<span style="font-size: 10pt; color: #555555">JAVA_HOME</span>、<span style="font-size: 10pt; color: #555555">CLASSPATH</span>、<span style="font-size: 10pt; color: #555555">PATH</span>，必要时候还要重装<span style="font-size: 10pt; color: #555555">jdk</span>。如果还不能解决，也许就是你的<span style="font-size: 10pt; color: #555555">eclipse</span>文件有损坏或丢失，或者你的硬盘有坏道了，怎么办就很清楚了，呵呵。<span style="font-size: 10pt; color: #555555"><br /><br />3</span>、想要重新配置工作空间<span style="font-size: 10pt; color: #555555"><br /></span>原<span style="font-size: 10pt; color: #555555">&nbsp;&nbsp;&nbsp; </span>因：你默认了工作空间，很郁闷，每次都是那个。<span style="font-size: 10pt; color: #555555"><br /></span>解决办法：删掉<span style="font-size: 10pt; color: #555555">configuration</span>中除了<span style="font-size: 10pt; color: #555555">config.ini</span>以外的所有文件和文件夹，确保插件安装配置正确。<span style="font-size: 10pt; color: #555555"><br /><br />4</span>、无法编译打包<span style="font-size: 10pt; color: #555555"><br /></span>原<span style="font-size: 10pt; color: #555555">&nbsp;&nbsp;&nbsp; </span>因：排除上面的问题外，应该是你程序所依赖包找不到。<span style="font-size: 10pt; color: #555555"><br /></span>解决办法：在构建路径中添加所需要的包。</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="font-size: x-large; color: #000080">&nbsp;Eclipse插件安装</span></p>
<p>&nbsp;</p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">做为当下最流行的开源IDE之一，Eclipse的一大优势就在于其无数优秀的插件。一个好的插件可以大大的提高我们的工作效率，学习如何安装Eclipse插件自然也是必修课了。下面介绍Eclipse插件的安装方法。</span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">Eclipse插件的安装方法大体有以下三种： </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small"><strong>第一种：直接复制法</strong></span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">假设你的Eclipse的在（C:\eclipse), 解压你下载的 eclipse 插件或者安装eclipse 插件到指定目录AA(c:\AA)文件夹，打开AA 文件夹，在AA文件夹里分别包含两个文件夹features和plugins ，然后把两个文件夹里的文件分别复制到eclipse下所对应的文件夹下的features 和plugins 下，一般的把插件文件直接复制 到eclipse目录里是最直接也是最愚蠢的一种方法！因为日后想要删除这些插件会非常的困难！强列的不推荐使用！！ </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">注意：直接将 插件包解压到plugins文件夹下之后，重启eclipse，可能不会加载新的插件。 </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">解决方法是：</span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">1、打开命令行，到当前<span>eclipse的目录下，输入eclipse -clean，重新启动eclipse，这样eclipse就会加上新的插件了。 </span></span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">2、如果插件不能升效，则请将<span>eclipse\configuration\org.eclipse.update目录删除后再启动eclipse:) </span></span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">你可以在eclipse的菜单"Help"--&gt;"About Eclipse SDK"--&gt;"Feature Details" 和"Plug-in Details"中看到新安装的插件。 </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small"><strong>第二种：使用<span>link文件法</span></strong></span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">a.假设你的<span>Eclipse的在（C:\eclipse),在该文件夹下，新建这样的目录结构（C:\eclipse\PluginsEclipse\jode\eclipse),</span></span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">b.解压你下载的<span>eclipse 插件或者安装eclipse 插件到指定目录BB（C:\BB）文件夹，打开BB 文件夹，然后把 BB文件夹里的两个文件夹features和plugins 复制到刚刚新建好的eclipse （C:\eclipse\PluginsEclipse\jode\eclipse,这样eclipse中就有了二个插件目录features and plugins)下. </span></span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">c.在<span>eclipse（C:\eclipse)目录中新建links(C:\eclipse\links)目录,在links目录中建立一个以link为扩展名的文本文件如jode.link，内容如下path=C:/eclipse/PluginsEclipse/jode 或者 path=C:\\eclipse\\PluginsEclipse\\jode 插件的目录） </span></span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">重启eclipse插件就会安装完成。 </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">注意：link文件中path=插件目录的path路径分隔要用\\或是/ </span></p>
<p><span style="font-size: 9pt; color: black">1.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">/eclipse/&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">2.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;links/&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">3.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jode.link&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">4.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;webtools.link&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">5.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateManager.link&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">6.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">7.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...&nbsp; &nbsp;</span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">可以在eclipse的菜单"Help"--&gt;"About Eclipse SDK"--&gt;"Feature Details" 和"Plug-in Details"中看到新安装的插件。 </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small"><strong>第三种：使用<span>eclipse自带的图形界面的插件安装方法</span></strong></span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">选择</span><span style="font-size: small">Help &gt; Software Updates &gt; Manager Configuration <br />在选择Add &gt; Extension Location 找到你要安装插件的目录就可以了。使用eclipse的help-&gt;SoftwareUpdates -&gt; </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">Find and install... search for new features... 输入软件安装地址进行安装强烈推荐这种方法，优点很多比如可以方 </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">便的添加删除，也不用自己写link文件！ </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">备注：Eclipse插件的目录结构 </span></p>
<p><span style="font-size: 9pt; color: black">8.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">/eclipse-plugins/&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">9.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;eclipse/&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">10.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.eclipseextension&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">11.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;features/&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">12.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;plugins/&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">13.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>&nbsp;</p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">第2.3种方法所指向的目录都指的是"eclipse"目录， </span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">如果用第3种方法，在eclipse这个目录下必须有文件.eclipseextension，如果你下的插件没有这个文件，</span><span style="font-size: small"> <br />那就随便eclipse安装目录下的那个文件靠过去就行了！只有有这么个文件就可以了，内容没什么用，主要是一些版本信息！例如： </span></p>
<p><span style="font-size: 9pt; color: black">14.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">id=org.eclipse.platform&nbsp;name=Eclipse&nbsp;Platform&nbsp; &nbsp;</span></p>
<p><span style="font-size: 9pt; color: black">15.<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 9pt; color: black">version=</span><span style="font-size: 9pt; color: black">3.1<span style="padding-right: 0cm; padding-left: 0cm; padding-bottom: 0cm; padding-top: 0cm">.</span>1<span style="padding-right: 0cm; padding-left: 0cm; padding-bottom: 0cm; padding-top: 0cm">&nbsp; &nbsp;</span></span></p>
<p style="margin: 7.5pt 0cm; text-indent: 21pt; line-height: 19.5pt"><span style="font-size: small">以上就介绍了三种Eclipse插件的安装方法。</span></p>
<p>&nbsp;</p>
<p>&nbsp;转自：<a href="http://zhao-weigang.iteye.com/blog/1041466">http://zhao-weigang.iteye.com/blog/1041466</a></p>
<p>&nbsp;</p><img src ="http://www.cppblog.com/LIULIANG/aggbug/187795.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/LIULIANG/" target="_blank">BIG森林</a> 2012-08-20 22:01 <a href="http://www.cppblog.com/LIULIANG/archive/2012/08/20/187795.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Attribute value is quoted with " which must be escaped when used within the value 问题解决 </title><link>http://www.cppblog.com/LIULIANG/archive/2012/08/15/187241.html</link><dc:creator>BIG森林</dc:creator><author>BIG森林</author><pubDate>Wed, 15 Aug 2012 00:41:00 GMT</pubDate><guid>http://www.cppblog.com/LIULIANG/archive/2012/08/15/187241.html</guid><wfw:comment>http://www.cppblog.com/LIULIANG/comments/187241.html</wfw:comment><comments>http://www.cppblog.com/LIULIANG/archive/2012/08/15/187241.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/LIULIANG/comments/commentRss/187241.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/LIULIANG/services/trackbacks/187241.html</trackback:ping><description><![CDATA[访问JSP时，报错：Attribute value is quoted with " which must be escaped when used within the value&nbsp;。相信很多人都遇到过，以下结合本人查资料与亲自实践得到的结论。 
<p>有不对的地方还请指教。</p>
<p>&nbsp;</p>
<p>1）：错误常发生的位置 value=<span style="color: #ff0000">"</span>&lt;%=""+request.getAttribute("name")%&gt;<span style="color: #ff0000">"&nbsp;</span>&nbsp; </p>
<p>2）：错误产生的原因，是因为tomcat版本升级后（6.0以后），对双引号的处理机制引起的，如果出现双引号包含双引号的情况，就可能会出现这个错误。</p>
<p>3）：解决办法有好多种，大多数网上的意见是改为value=<span style="color: #ff0000">&#8216;</span>&lt;%=""+request.getAttribute("name")%&gt;<span style="color: #ff6666">&#8217;&nbsp; </span><span style="color: #000000">这样确实可以解决这个报错，可能无法完全解决问题，比如项目中有很多地方以前都用的是双引号，修改起来会非常麻烦，还容易出错。</span></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 查看tomact文档有一段话这样描述的&#8220;If <code>false</code> the requirements for escaping quotes in JSP attributes will be relaxed so that an unescaped quote will not cause an error.</p>
<p>If not specified, the specification compliant default of <code>true</code> will be used.&#8221;&nbsp;&nbsp;&nbsp; 这个描述针对的是tomact的<code>org.apache.jasper.compiler. Parser.STRICT_QUOTE_ESCAPING</code>属性。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如此一来，我们知道只要在tomcat启动时将这个属性设为false就可以解决这个问题。</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;那么怎么将这个属性设置到tomcat的system属性中呢，有至少两个办法：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 一种是利用tomcat启动的执行脚本，在执行过程中调用setenv.sh，在其中设置环境变量，如：JAVA_OPTS=%JAVA_OPTS%: -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp; 另一种是找到conf/catalina.properties文件，在最后添加org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false 即可。</p>
<p>&nbsp;转自：<a href="http://blog.csdn.net/eagleking012/article/details/6666860">http://blog.csdn.net/eagleking012/article/details/6666860</a></p><img src ="http://www.cppblog.com/LIULIANG/aggbug/187241.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/LIULIANG/" target="_blank">BIG森林</a> 2012-08-15 08:41 <a href="http://www.cppblog.com/LIULIANG/archive/2012/08/15/187241.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在web.xml文件中配置信息，未起作用问题解决 </title><link>http://www.cppblog.com/LIULIANG/archive/2012/08/10/186848.html</link><dc:creator>BIG森林</dc:creator><author>BIG森林</author><pubDate>Fri, 10 Aug 2012 12:53:00 GMT</pubDate><guid>http://www.cppblog.com/LIULIANG/archive/2012/08/10/186848.html</guid><wfw:comment>http://www.cppblog.com/LIULIANG/comments/186848.html</wfw:comment><comments>http://www.cppblog.com/LIULIANG/archive/2012/08/10/186848.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/LIULIANG/comments/commentRss/186848.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/LIULIANG/services/trackbacks/186848.html</trackback:ping><description><![CDATA[<p>转载至：<a href="http://jsf.javaeye.com/blog/141949">http://jsf.javaeye.com/blog/141949</a></p>
<p><a href="http://hi.baidu.com/piaochen/blog/item/ac6f1124936a8a21d4074291.html">http://hi.baidu.com/piaochen/blog/item/ac6f1124936a8a21d4074291.html</a></p>
<p>&nbsp;</p>
<div class="tit">MyFaces下web.xml配置error_page 500错误转发无效的解决方案（综合编译）</div>
<div class="date">2009-09-22 10:54</div>
<p>
<table style="table-layout: fixed; width: 100%" border="0">
<tbody>
<tr>
<td>
<div class="cnt" id="blog_text">
<p>网上目前的解决方案如下：</p>
<p>1, <span class="hilite3"><span style="background-color: #aaffaa">IE</span></span>设定&nbsp;&nbsp; 工具--&gt;Internet选项--&gt;高级---&gt;显示http友好错误信息(取消选择) , 这样就可以了<br />2, 设置指定错误页页状态为正常,来告诉<span class="hilite3"><span style="background-color: #aaffaa">IE</span></span>这不是一个服务器错误, 从而不显示<span class="hilite3"><span style="background-color: #aaffaa">IE</span></span>的自定义错误页 <br />&lt;%<br />&nbsp;&nbsp;&nbsp; response.setStatus(200); // 200 = HttpServletResponse.SC_OK<br />%&gt;<br />3, 把错误页做大一点,弄个几百K 就可以显示错误页面 (加一个div块,display设为none就可以了),这个问题比较奇怪.</p>
<p>&nbsp;</p>
<p>对于3，说明下，应该是因为MS的程序员写<span class="hilite3"><span style="background-color: #aaffaa">IE</span></span>的时候，如果自己设置了错误代码页面的跳转，<span class="hilite3"><span style="background-color: #aaffaa">IE</span></span>会判断跳转页面的大小，如果小于其设置的值，则不会跳转到你定义的页面，而是跳转到<span class="hilite3"><span style="background-color: #aaffaa">IE</span></span>默认的错误代码页面。</p>
<p>一下是一些错误代码和其对应的页面最小值：</p>
<p>错误码 <span class="hilite3"><span style="background-color: #aaffaa">ie</span></span>需要的页面最小值（字节数）</p>
<p>400 512<br />403 256<br />404 512<br />405 256<br />406 512<br />408 512<br />409 512<br />410 256<br />500 512<br />501 512<br />505 512 <br />可见，如果你定义的404错误页面大小&lt;512 则<span class="hilite3"><span style="background-color: #aaffaa">ie</span></span>会返回自己默认的404错误页面。</p>
<p>郁闷吧。</p>
<p>如果想加大页面的大小，可以像3说的那样写一个div display=none 也可以写一段话，然后注释掉，关键是注释的问题，不能采用&lt;%-- --%&gt;注释，只能用&lt;-- --&gt;注释，否则一样没用。</p>
<p>在MyFaces环境下一一实验后，发现无效。还是无法转发。实验N次后，<br />在<a href="http://wiki.apache.org/myfaces/Handling_Server_Errors">http://wiki.apache.org/myfaces/Handling_Server_Errors</a>中发现了解决方案。原来MyFaces自己有一套处理Error的机制。我们要跳转到自己的页面，得把MyFaces的Error处理机制给停掉。这样才能使Web.xml的500错误的配置起作用。<br />方案如下：<br />在web.xml文件中加入：<br />&lt;!-- if you want to disable the behaviour completely --&gt;<br />&lt;context-param&gt;<br />&nbsp;&nbsp;&nbsp; &lt;param-name&gt;org.apache.myfaces.ERROR_HANDLING&lt;/param-name&gt;<br />&nbsp;&nbsp;&nbsp; &lt;param-value&gt;false&lt;/param-value&gt;<br />&lt;/context-param&gt;<br />&lt;!-- if you are using myfaces + facelets don't forget to do this --&gt;<br />&lt;context-param&gt;<br />&nbsp;&nbsp;&nbsp; &lt;param-name&gt;facelets.DEVELOPMENT&lt;/param-name&gt;<br />&nbsp;&nbsp;&nbsp; &lt;param-value&gt;false&lt;/param-value&gt;<br />&lt;/context-param&gt;<br /><br />&lt;!-- if you want to use a different resource template file than <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "META-INF/rsc/myfaces-dev-error.xml" this param let you configure<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; it. (since 1.2.4-SNAPSHOT and 1.1.6-SNAPSHOT)--&gt;<br />&lt;context-param&gt;<br />&nbsp;&nbsp;&nbsp; &lt;param-name&gt;org.apache.myfaces.ERROR_TEMPLATE_RESOURCE&lt;/param-name&gt;<br />&nbsp;&nbsp;&nbsp; &lt;param-value&gt;META-INF/rsc/custom-dev-error.xml&lt;/param-value&gt;<br />&lt;/context-param&gt;<br /><br />&lt;!-- if you want to choose a different class for handling the exception - the error-handler needs to include a method handleException(FacesContext fc, Exception ex)--&gt;<br />&lt;context-param&gt;<br />&nbsp;&nbsp;&nbsp; &lt;param-name&gt;org.apache.myfaces.ERROR_HANDLER&lt;/param-name&gt;<br />&nbsp;&nbsp;&nbsp; &lt;param-value&gt;my.project.ErrorHandler&lt;/param-value&gt;<br />&lt;/context-param&gt; <br />这样再设置<br />&lt;error-page&gt;<br />&lt;error-code&gt;500&lt;/error-code&gt;<br />&lt;location&gt;/500error.jsp&lt;/location&gt;<br />&lt;/error-page&gt;<br />就可以了。<br />这样配置完了以后，在FireFox下是可以转发的，但是在IE下就不行了。修改IE的配置肯定不可行，将500error.jsp增大到几百k，性能上说不过去。那只能采取在500error.jsp中加入<br />&lt;%<br />&nbsp;&nbsp;&nbsp; response.setStatus(200); // 200 = HttpServletResponse.SC_OK<br />%&gt;<br />的方案。<br />试验后，发现可行。<br />（本文引用了<a href="http://javeye.javaeye.com/blog/441513">http://javeye.javaeye.com/blog/441513</a>和<a href="http://jsf.javaeye.com/blog/141949">http://jsf.javaeye.com/blog/141949</a>的资料。）</p></div></td></tr></tbody></table></p>  <img src ="http://www.cppblog.com/LIULIANG/aggbug/186848.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/LIULIANG/" target="_blank">BIG森林</a> 2012-08-10 20:53 <a href="http://www.cppblog.com/LIULIANG/archive/2012/08/10/186848.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>