﻿<?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>博客园-goody9807</title><link>http://www.cnblogs.com/goody9807/</link><description>避风的港湾-云之宇~~~寻找.Net的精华

一个不错的P2P软件,里面肯定有你要的资源
</description><language>zh-cn</language><lastBuildDate>Wed, 09 Jul 2008 05:43:10 GMT</lastBuildDate><pubDate>Wed, 09 Jul 2008 05:43:10 GMT</pubDate><ttl>60</ttl><item><title>log4net的各种Appender配置示例</title><link>http://www.cnblogs.com/goody9807/archive/2008/07/04/1235776.html</link><dc:creator>PointNet</dc:creator><author>PointNet</author><pubDate>Fri, 04 Jul 2008 08:20:00 GMT</pubDate><guid>http://www.cnblogs.com/goody9807/archive/2008/07/04/1235776.html</guid><wfw:comment>http://www.cnblogs.com/goody9807/comments/1235776.html</wfw:comment><comments>http://www.cnblogs.com/goody9807/archive/2008/07/04/1235776.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/goody9807/comments/commentRss/1235776.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/goody9807/services/trackbacks/1235776.html</trackback:ping><description><![CDATA[摘要: 在log4net的配置中，appender是最重要的部分，一般来说，每一种appender都表示一种日志的输出介质，如日志文件、EvengLog、数据库、控制台、邮件、ASP.NET页面等。本文对各种内置的appender的配置提供了示例，但却远称不上详尽。要想了解每一种appender的参数和选项的说明，请参看该appender的SDK文档。 以下示例都是.NET 2.0下进行的, log4ne&nbsp;&nbsp;<a href='http://www.cnblogs.com/goody9807/archive/2008/07/04/1235776.html'>阅读全文</a><img src ="http://www.cnblogs.com/goody9807/aggbug/1235776.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37596/" target="_blank">[新闻]Joost借道TOM在线 将正式进军中国</a>]]></description></item><item><title>log4net的四方常用方式</title><link>http://www.cnblogs.com/goody9807/archive/2008/07/04/1235473.html</link><dc:creator>PointNet</dc:creator><author>PointNet</author><pubDate>Fri, 04 Jul 2008 04:22:00 GMT</pubDate><guid>http://www.cnblogs.com/goody9807/archive/2008/07/04/1235473.html</guid><wfw:comment>http://www.cnblogs.com/goody9807/comments/1235473.html</wfw:comment><comments>http://www.cnblogs.com/goody9807/archive/2008/07/04/1235473.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/goody9807/comments/commentRss/1235473.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/goody9807/services/trackbacks/1235473.html</trackback:ping><description><![CDATA[摘要: 新年第一篇文章，希望大家喜欢。四种常用方式：1.控制台2.文件3.数据库4.remoting&lt;log4net&gt;&lt;root&gt;&lt;levelvalue="ALL"/&gt;&lt;appender-refref="consoleApp"/&gt;&lt;appender-refref="RemotingAppender"/&gt;&lt;/root&gt;&lt;appen&nbsp;&nbsp;<a href='http://www.cnblogs.com/goody9807/archive/2008/07/04/1235473.html'>阅读全文</a><img src ="http://www.cnblogs.com/goody9807/aggbug/1235473.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37596/" target="_blank">[新闻]Joost借道TOM在线 将正式进军中国</a>]]></description></item><item><title>[zt]一、NVelocity介绍</title><link>http://www.cnblogs.com/goody9807/archive/2008/07/03/1234728.html</link><dc:creator>PointNet</dc:creator><author>PointNet</author><pubDate>Thu, 03 Jul 2008 05:50:00 GMT</pubDate><guid>http://www.cnblogs.com/goody9807/archive/2008/07/03/1234728.html</guid><wfw:comment>http://www.cnblogs.com/goody9807/comments/1234728.html</wfw:comment><comments>http://www.cnblogs.com/goody9807/archive/2008/07/03/1234728.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/goody9807/comments/commentRss/1234728.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/goody9807/services/trackbacks/1234728.html</trackback:ping><description><![CDATA[<h2 style="margin: 6pt 0cm 6pt 28.8pt"><a target="_blank" name="_Toc8028255"><font face="Times New Roman"><span style="font-weight: normal">1.1 </span><span style="font-weight: normal">&nbsp;</span></font></a><span style="font-weight: normal"><font face="Times New Roman">Velocity</font></span><span style="font-weight: normal; font-family: 黑体">是什么</span></h2>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">是一个基于</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">的模板引擎（</span><font face="Times New Roman">template engine</font><span style="font-family: 宋体">）。它允许任何人仅仅简单的使用模板语言（</span><font face="Times New Roman">template language</font><span style="font-family: 宋体">）来引用由</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">代码定义的对象。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">当</span><font face="Times New Roman">nVelocity </font><span style="font-family: 宋体">应用于</span><font face="Times New Roman">web</font><span style="font-family: 宋体">开发时，界面设计人员可以和</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">程序开发人员同步开发一个遵循</span><font face="Times New Roman">MVC</font><span style="font-family: 宋体">架构的</span><font face="Times New Roman">web</font><span style="font-family: 宋体">站点，也就是说，页面设计人员可以只关注页面的显示效果，而由</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">程序开发人员关注业务逻辑编码。</span><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">将</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">代码从</span><font face="Times New Roman">web</font><span style="font-family: 宋体">页面中分离出来，这样为</span><font face="Times New Roman">web</font><span style="font-family: 宋体">站点的长期维护提供了便利，同时也为我们在</span><font face="Times New Roman">aspx</font><span style="font-family: 宋体">之外又提供了一种可选的方案。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">的能力远不止</span><font face="Times New Roman">web</font><span style="font-family: 宋体">站点开发这个领域，例如，它可以从模板（</span><font face="Times New Roman">template</font><span style="font-family: 宋体">）产生</span><font face="Times New Roman">SQL</font><span style="font-family: 宋体">和</span><font face="Times New Roman">PostScript</font><span style="font-family: 宋体">、</span><font face="Times New Roman">XML</font><span style="font-family: 宋体">，它也可以被当作一个独立工具来产生源代码和报告，或者作为其他系统的集成组件使用。</span><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">也可以为很多</span><font face="Times New Roman">web</font><span style="font-family: 宋体">开发架构提供模板服务（</span><font face="Times New Roman">template service</font><span style="font-family: 宋体">）。我们的系统就提供一个模板服务的方式允许一个</span><font face="Times New Roman">web</font><span style="font-family: 宋体">应用以一个真正的</span><font face="Times New Roman">MVC</font><span style="font-family: 宋体">模型进行开发。</span></p>
<h2 style="margin: 6pt 0cm 6pt 28.8pt"><font face="Times New Roman"><span style="font-weight: normal">1.2 </span><span style="font-weight: normal">nVelocity</span></font><span style="font-weight: normal; font-family: 黑体">能为我们作什么？</span></h2>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">假设你是一家专门出售</span><font face="Times New Roman">Mud</font><span style="font-family: 宋体">的在线商店的页面设计人员，让我们暂且称它为&#8220;在线</span><font face="Times New Roman">MUD</font><span style="font-family: 宋体">商店&#8221;。你们的业务很旺，客户下了各种类型和数量的</span><font face="Times New Roman">Mud</font><span style="font-family: 宋体">订单。他们都是通过输入用户名和密码后才登陆到你的网站，登陆后就允许他们查看订单并购买更多的</span><font face="Times New Roman">Mud</font><span style="font-family: 宋体">。现在，一种非常流行的</span><font face="Times New Roman">mud</font><span style="font-family: 宋体">正在打折销售。另外有一些客户规律性的购买另外一种也打折但不是很流行的</span><font face="Times New Roman">Bright Red Mud</font><span style="font-family: 宋体">，由于购买的人并不多所以它被安置在页面的边缘。所有用户的信息都是被跟踪并存放于数据库中的，所以某天有一个问题可能会冒出来：为什么不使用</span><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">来使用户更好的浏览他们感兴趣的商品呢？</span><font face="Times New Roman">&nbsp; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">使得</span><font face="Times New Roman">web</font><span style="font-family: 宋体">页面的客户化工作非常容易。作为一个站点的设计人员，你希望每个用户登陆时都拥有自己的页面。</span><font face="Times New Roman">&nbsp; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">你会见了一些公司内的软件工程师，你发现他们每个人都同意客户应该拥有具有个性化的信息。那让我们把软件工程师应该作的事情放在一边，看一看你应该作些什么吧。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">你可能在页面内嵌套如下的</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">（</span><font face="Times New Roman">nVelocity template language</font><span style="font-family: 宋体">）声明：</span><font face="Times New Roman"> <br />
</font></p>
<div style="border-right: rgb(204,204,204) 1px solid; padding-right: 5px; border-top: rgb(204,204,204) 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: rgb(204,204,204) 1px solid; width: 98%; padding-top: 4px; border-bottom: rgb(204,204,204) 1px solid; background-color: rgb(238,238,238)"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(128,0,0)">html</span><span style="color: rgb(0,0,255)">&gt;</span><span style="color: rgb(0,0,0)"><br />
<br />
</span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(128,0,0)">body</span><span style="color: rgb(0,0,255)">&gt;</span><span style="color: rgb(0,0,0)"><br />
<br />
Hello&nbsp;$customer.Name!<br />
<br />
</span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(128,0,0)">table</span><span style="color: rgb(0,0,255)">&gt;</span><span style="color: rgb(0,0,0)"><br />
<br />
#foreach(&nbsp;$mud&nbsp;in&nbsp;$nudsOnSpecial&nbsp;)<br />
<br />
#if&nbsp;(&nbsp;$customer.hasPurchased(&nbsp;$mud&nbsp;)&nbsp;)<br />
<br />
</span><span style="color: rgb(0,0,255)">&lt;</span><span style="color: rgb(128,0,0)">tr</span><span style="color: rgb(0,0,255)">&gt;&lt;</span><span style="color: rgb(128,0,0)">td</span><span style="color: rgb(0,0,255)">&gt;</span><span style="color: rgb(0,0,0)">$flogger.getPromo(&nbsp;$mud&nbsp;)</span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(128,0,0)">td</span><span style="color: rgb(0,0,255)">&gt;&lt;/</span><span style="color: rgb(128,0,0)">tr</span><span style="color: rgb(0,0,255)">&gt;</span><span style="color: rgb(0,0,0)"><br />
<br />
#end<br />
<br />
#end<br />
<br />
</span><span style="color: rgb(0,0,255)">&lt;/</span><span style="color: rgb(128,0,0)">table</span><span style="color: rgb(0,0,255)">&gt;<br />
</span></div>
<br />
<h2 style="margin: 6pt 0cm 6pt 28.8pt"><a target="_blank" name="_Toc90698661"><font face="Times New Roman"><span style="font-weight: normal">1.1 <span style="font-weight: normal">VTL (</span>nVelocity </span></font></a><font face="Times New Roman"><span style="font-weight: normal">template language</span><span style="font-weight: normal">)</span></font></h2>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">VTL</font><span style="font-family: 宋体">意味着提供最简单、最容易并且最整洁的方式合并页面动态内容。</span><font face="Times New Roman"> VTL </font><span style="font-family: 宋体">使用</span><font face="Times New Roman">references</font><span style="font-family: 宋体">来在站点内嵌套动态内容，一个变量就是一种类型的</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">。变量是某种类型的</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">，它可以指向</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">代码中的定义，或者从当前页面内定义的</span><font face="Times New Roman">VTL statement</font><span style="font-family: 宋体">得到值。下面是一个</span><font face="Times New Roman">VTL statement</font><span style="font-family: 宋体">的例子，它可以被嵌套到</span><font face="Times New Roman"> HTML</font><span style="font-family: 宋体">代码中：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $a = &#8220;Velocity&#8221; ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">和所有的</span><font face="Times New Roman">VTL statement</font><span style="font-family: 宋体">一样，这个</span><font face="Times New Roman">statement</font><span style="font-family: 宋体">以＃字符开始并且包含一个</span><font face="Times New Roman">directive</font><span style="font-family: 宋体">：</span><font face="Times New Roman">set</font><span style="font-family: 宋体">。当一个在线用户请求你的页面时，</span><font face="Times New Roman">nVelocity Template Engine</font><span style="font-family: 宋体">将查询整个页面以便发现所有＃字符，然后确定哪些是</span><font face="Times New Roman">VTL statement</font><span style="font-family: 宋体">，哪些不需要</span><font face="Times New Roman">VTL </font><span style="font-family: 宋体">作任何事情。</span><font face="Times New Roman">&nbsp; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">＃字符后紧跟一个</span><font face="Times New Roman">directive</font><span style="font-family: 宋体">：</span><font face="Times New Roman">set</font><span style="font-family: 宋体">时，这个</span><font face="Times New Roman">set directive</font><span style="font-family: 宋体">使用一个表达式（使用括号封闭）将一个值设置给变量。变量被列在左边，而它的值被列在右边，最后他们之间使用＝号分割。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">在上面的例子中，变量是</span><font face="Times New Roman">$a</font><span style="font-family: 宋体">，而它的值是</span><font face="Times New Roman">Velocity</font><span style="font-family: 宋体">。和其他的</span><font face="Times New Roman">references</font><span style="font-family: 宋体">一样以</span><font face="Times New Roman">$</font><span style="font-family: 宋体">字符开始，而值总是以双引号封闭。</span><font face="Times New Roman">Velocity</font><span style="font-family: 宋体">中仅有</span><font face="Times New Roman">String</font><span style="font-family: 宋体">可以被赋值给变量。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">记住以下的规则：</span><font face="Times New Roman">&nbsp; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">使用</span><font face="Times New Roman">$</font><span style="font-family: 宋体">字符开始的</span><font face="Times New Roman">references</font><span style="font-family: 宋体">用于得到什么；使用</span><font face="Times New Roman">#</font><span style="font-family: 宋体">字符开始的</span><font face="Times New Roman">directives</font><span style="font-family: 宋体">用于作些什么。</span></p>
<h2 style="margin: 6pt 0cm 6pt 28.8pt"><font face="Times New Roman"><span style="font-weight: normal">1.2 </span>Hello nVelocity World</font></h2>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">一旦某个变量被分配了一个值，那么你就可以在</span><font face="Times New Roman">HTML</font><span style="font-family: 宋体">文件的任何地方引用它。在下面的例子中，一个值被分配给</span><font face="Times New Roman">$foo</font><span style="font-family: 宋体">变量，并在其后被引用。</span><font face="Times New Roman">&nbsp; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;html&gt;&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;body&gt;&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $foo = &#8220;nVelocity&#8221; )&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">Hello $foo World!&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;/body&gt;&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;/html&gt;&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">上面的实现结果是在页面上打印&#8220;</span><font face="Times New Roman">Hello nVelocity World</font><span style="font-family: 宋体">！&#8221;</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">为了使包含</span><font face="Times New Roman">VTL directives</font><span style="font-family: 宋体">的</span><font face="Times New Roman">statement</font><span style="font-family: 宋体">更具有可读性，我们鼓励你在新行开始一个</span><font face="Times New Roman">VTL statement</font><span style="font-family: 宋体">，尽管你不是必须这么作。</span><font face="Times New Roman">Set directive</font><span style="font-family: 宋体">将在后面详细描述。</span></p>
<br />
<h2 style="margin: 6pt 0cm 6pt 28.8pt"><span style="font-weight: normal"><font face="Times New Roman">1.1 </font></span><span style="font-family: 黑体">注释</span></h2>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">单行注释：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;## This is a single line comment.</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">多行注释：</span><font face="Times New Roman">&nbsp; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;#*&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;&nbsp; Thus begins a multi-line comment. Online visitors won&#8217;t</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;&nbsp; see this text because the Velocity Template Engine will ignore it.</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;*#&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">文档格式：</span><font face="Times New Roman">&nbsp; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;#**&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;&nbsp; This is a VTL comment block and&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;&nbsp; may be used to store such information as the document author </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 42pt"><font face="Times New Roman">and versioning information:&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;&nbsp; @version 5&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;&nbsp; @author&nbsp;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&nbsp;*#&nbsp;</font></p>
<h2 style="margin: 6pt 0cm 6pt 28.8pt"><font face="Times New Roman"><span style="font-weight: normal">1.2 </span>References</font></h2>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">在</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">中有三种类型的</span><font face="Times New Roman">references</font><span style="font-family: 宋体">：变量</span><font face="Times New Roman">(variables)</font><span style="font-family: 宋体">、属性</span><font face="Times New Roman">(properties)</font><span style="font-family: 宋体">、方法</span><font face="Times New Roman"> (methods)</font><span style="font-family: 宋体">。作为一个使用</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">的页面设计者，你和你的工程师必须就</span><font face="Times New Roman">references</font><span style="font-family: 宋体">的名称达成共识，以便你可以在你的</span><font face="Times New Roman">template</font><span style="font-family: 宋体">中使用它们。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">VTL</font><span style="font-family: 宋体">中一切</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">可以作为一个</span><font face="Times New Roman">String</font><span style="font-family: 宋体">对象处理。如果有一个对象</span><font face="Times New Roman">$foo</font><span style="font-family: 宋体">是一个</span><font face="Times New Roman">Integer</font><span style="font-family: 宋体">对象，那么</span><font face="Times New Roman">Velocity</font><span style="font-family: 宋体">将调用它的</span><font face="Times New Roman">toString()</font><span style="font-family: 宋体">方法将这个对象转型为</span><font face="Times New Roman">String</font><span style="font-family: 宋体">类型。</span></p>
<h3 style="margin: 7pt 0cm 0pt; text-indent: 0cm"><font size="5"><span style="font-weight: normal"><font face="Times New Roman">1.2.1 </font></span><span style="font-family: 黑体">变量</span></font></h3>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">格式要求同</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">。</span></p>
<h3 style="margin: 7pt 0cm 0pt; text-indent: 0cm"><font size="5"><span style="font-weight: normal"><font face="Times New Roman">1.1.1 </font></span><span style="font-family: 黑体">属性</span></font></h3>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">例子：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$customer.Address</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$purchase.Total</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$customer.Address</font><span style="font-family: 宋体">有两种含义。它可以表示：查找</span><font face="Times New Roman">hashtable</font><span style="font-family: 宋体">对象</span><font face="Times New Roman">customer</font><span style="font-family: 宋体">中以</span><font face="Times New Roman">Address</font><span style="font-family: 宋体">为关键字的值；也可以表示调用</span><font face="Times New Roman">customer</font><span style="font-family: 宋体">对象的</span><font face="Times New Roman"> getAddress()</font><span style="font-family: 宋体">方法。当你的页面被请求时，</span><font face="Times New Roman">Velocity</font><span style="font-family: 宋体">将确定以上两种方式选用那种，然后返回适当的值。</span></p>
<h3 style="margin: 7pt 0cm 0pt; text-indent: 0cm"><font size="5"><span style="font-weight: normal"><font face="Times New Roman">1.1.2 </font></span><span style="font-family: 黑体">方法</span></font></h3>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">一个方法就是被定义在</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">中的一段代码，并且它有完成某些有用工作的能力，例如一个执行计算和判断条件是否成立、满足等。方法是一个由</span><font face="Times New Roman">$</font><span style="font-family: 宋体">开始并跟随</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">标识符组成的</span><font face="Times New Roman">References</font><span style="font-family: 宋体">，一般还包括一个</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">方法体。例如：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$customer.getAddress()</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$purchase.getTotal()</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$page.setTitle( &#8220;My Home Page&#8221; )</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$person.setAttributes( [&#8220;Strange&#8221;, &#8220;Weird&#8221;, &#8220;Excited&#8221;] )</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">前两个例子</span><font face="Times New Roman">$customer.getAddress()</font><span style="font-family: 宋体">和</span><font face="Times New Roman">$purchase.getTotal()</font><span style="font-family: 宋体">看起来挺想上面的属性</span><font face="Times New Roman">$customer.Address </font><span style="font-family: 宋体">和</span><font face="Times New Roman"> $purchase.Total</font><span style="font-family: 宋体">。如果你觉得他们之间有某种联系的话，那你是正确的。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">VTL</font><span style="font-family: 宋体">属性可以作为</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">方法的缩写。</span><font face="Times New Roman">$customer.Address</font><span style="font-family: 宋体">属性和使用</span><font face="Times New Roman">$customer.getAddress()</font><span style="font-family: 宋体">方法具有相同的效果。如果可能的话使用属性的方式是比较合理的。属性和方法的不同点在于你能够给一个方法指定一个参数列表。</span></p>
<h3 style="margin: 7pt 0cm 0pt; text-indent: 0cm"><font size="5"><span style="font-weight: normal"><font face="Times New Roman">1.1.1 </font></span><span style="font-family: 黑体">正式</span><span style="font-family: 宋体">reference</span><span style="font-family: 黑体">标记</span></font></h3>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">re</span><font face="Times New Roman">ference</font><span style="font-family: 宋体">的</span><span style="font-family: 宋体">正式</span><span style="font-family: 宋体">格式如下：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">${mudSlinger}</font><span style="font-family: 宋体">变量</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">${customer.Address}</font><span style="font-family: 宋体">属性</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">${purchase.getTotal()}</font><span style="font-family: 宋体">方法</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">非</span><span style="font-family: 宋体">正式</span><span style="font-family: 宋体">格式更见常用，但是有时还是使用正是格式比较适合。例如：你希望通过一个变量</span><font face="Times New Roman">$vice</font><span style="font-family: 宋体">来动态的组织一个字符串。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">Jack is a $vicemaniac. </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">本来变量是</span><font face="Times New Roman">$vice</font><span style="font-family: 宋体">现在却变成了</span><font face="Times New Roman">$vicemaniac</font><span style="font-family: 宋体">，这样</span><font face="Times New Roman">Veloctiy</font><span style="font-family: 宋体">就不知道您到底要什么了。所以，应该使用正是格式书写</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">Jack is a ${vice}maniac </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">现在</span><font face="Times New Roman">Velocity</font><span style="font-family: 宋体">知道变量是</span><font face="Times New Roman">$vice</font><span style="font-family: 宋体">而不是</span><font face="Times New Roman">$vicemania</font><span style="font-family: 宋体">c</span><span style="font-family: 宋体">。</span></p>
<h3 style="margin: 7pt 0cm 0pt; text-indent: 0cm"><font size="5"><span style="font-weight: normal"><font face="Times New Roman">1.1.2 </font></span><span style="font-family: 宋体">Quiet reference notation</span></font></h3>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">例</span><span style="font-family: 宋体">如：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;input type=&#8221;text&#8221; name=&#8221;email&#8221; value=&#8221;$email&#8221; /&gt;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">当页面的</span><font face="Times New Roman">form</font><span style="font-family: 宋体">被初始加载时，变量</span><font face="Times New Roman">$email</font><span style="font-family: 宋体">还没有值，这时你肯定是希望它能够显示一个空白来代替输出</span><font face="Times New Roman">&#8221;$email&#8221;</font><span style="font-family: 宋体">这样的字段。那么使用</span><font face="Times New Roman">quiet reference notation</font><span style="font-family: 宋体">就比较合适。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;input type=&#8221;text&#8221; name=&#8221;email&#8221; value=&#8221;$!email&#8221;/&gt;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">这样文本框的初始值就不会是</span><font face="Times New Roman">email</font><span style="font-family: 宋体">而是空值了。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">正式和</span><font face="Times New Roman">quiet</font><span style="font-family: 宋体">格式的</span><font face="Times New Roman">reference notation</font><span style="font-family: 宋体">也可一同使用，像下面这样：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;input type=&#8221;text&#8221; name=&#8221;email&#8221; value=&#8221;$!{email}&#8221;/&gt;</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><br />
</p>
<div id="textstyle_22444" style="margin-top: 20px; font-size: 9pt; min-height: 150px; text-indent: 24px; line-height: 22px">
<h3 style="margin: 7pt 0cm 0pt; text-indent: 0cm"><font size="5"><font face="Times New Roman"><span style="font-weight: normal">1.1.1 </span>Getting literal</font></font></h3>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">使用特殊字符</span><font face="Times New Roman">$</font><span style="font-family: 宋体">和</span><font face="Times New Roman">#</font><span style="font-family: 宋体">来帮助它工作，所以如果要在</span><font face="Times New Roman">template</font><span style="font-family: 宋体">里使用这些特殊字符要格外小心。本节将讨论</span><font face="Times New Roman">$</font><span style="font-family: 宋体">字符。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">在</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">中使用</span><font face="Times New Roman">$2.5</font><span style="font-family: 宋体">这样的货币标识是没有问题得的，</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">不会将它错认为是一个</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">，因为</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">中的</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">总是以一个大写或者小写的字母开始。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">VTL</font><span style="font-family: 宋体">中使用</span><font face="Times New Roman">&#8220;"&#8221;</font><span style="font-family: 宋体">作为转义字符。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">例如：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set( $email = &#8220;foo&#8221; ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">"$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">""$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">"""$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">将输出为：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">foo </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">"foo </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">""$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">如果</span><font face="Times New Roman">email</font><span style="font-family: 宋体">变量没有被定义则</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">"$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">""$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">"""$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">将被输出为：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">"$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">""$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">"""$email </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">注意：</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">中未被定义的变量将被认为是一个字符串，所以以下例子：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set( $foo = &#8220;gibbous&#8221; ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$moon = $foo </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">的输出结果是：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$moon = gibbous </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">现在你已经对</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">比较熟悉了，你可以将他们高效的应用于你的</span><font face="Times New Roman">template</font><span style="font-family: 宋体">了。</span><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">利用了很多</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">规范以方便了设计人员的使用。例如：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$foo</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$foo.getBar()</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">##</font><span style="font-family: 宋体">与下面这句相同</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$foo.Bar</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$data.getUser(&#8220;john&#8221;)</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">##</font><span style="font-family: 宋体">与下面这句相同</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$data.User(&#8220;john&#8221;)</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$data.getRequest().getServerName() </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#</font><span style="font-family: 宋体">与下面这句相同</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$data.Request.ServerName </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">##</font><span style="font-family: 宋体">与下面这句相同</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">${data.Request.ServerName} </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">但是，注意</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">中不会将</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">解释为对象的实例变量。例如：</span><font face="Times New Roman">$foo.Name</font><span style="font-family: 宋体">将被解释为</span><font face="Times New Roman">Foo</font><span style="font-family: 宋体">对象的</span><font face="Times New Roman">getName</font><span style="font-family: 宋体">（）方法，而不是</span><font face="Times New Roman">Foo</font><span style="font-family: 宋体">对象的</span><font face="Times New Roman">Name</font><span style="font-family: 宋体">实例变量。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><br />
</p>
<h2 style="margin: 6pt 0cm 6pt 28.8pt"><font face="Times New Roman"><span style="font-weight: normal">1.1 </span>Directives</font></h2>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">Reference</font><span style="font-family: 宋体">允许设计者使用动态的内容，而</span><font face="Times New Roman">directive</font><span style="font-family: 宋体">使得你可以应用</span><font face="Times New Roman">.NET</font><span style="font-family: 宋体">代码来控制你的显示逻辑，从而达到你所期望的显示效果。</span></p>
<h3 style="margin: 7pt 0cm 0pt; text-indent: 0cm"><font size="5"><span style="font-weight: normal"><font face="Times New Roman">1.1.1 </font></span><span style="font-family: 黑体">赋值</span><font face="Times New Roman">#set</font></font></h3>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set directive</font><span style="font-family: 宋体">被用于设置一个</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">的值。例如：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $primate = &#8220;monkey&#8221; ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $customer.Behavior = $primate ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">赋值左侧的（</span><font face="Times New Roman">LHS</font><span style="font-family: 宋体">）必须是一个变量或者属性</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">。右侧（</span><font face="Times New Roman">RHS</font><span style="font-family: 宋体">）可以是以下类型中一种：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">变量</span><font face="Times New Roman">reference</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">字符串</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">属性</span><font face="Times New Roman">reference</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">方法</span><font face="Times New Roman">reference</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">数字</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">ArrayList</span></p>
<div id="textstyle_22446" style="margin-top: 20px; font-size: 9pt; min-height: 150px; text-indent: 24px; line-height: 22px">
<p style="margin: 0cm 0cm 0pt; text-align: left" align="left"><span style="font-family: 宋体">下面是应用各种类型的RHS的例子：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">＃</span><font face="Times New Roman">set ( $monkey = $bill ) ##</font><span style="font-family: 宋体">变量</span><font face="Times New Roman">reference </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">＃</span><font face="Times New Roman">set ( $monkey.Friend = &#8220;monica&#8221; ) ##</font><span style="font-family: 宋体">字符串</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">＃</span><font face="Times New Roman">set ( $monkey.Blame = $whitehouse.Leak ) ##</font><span style="font-family: 宋体">属性</span><font face="Times New Roman">reference </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">＃</span><font face="Times New Roman">set ( $monkey.Plan = $spindoctor.weave($web) ) ##</font><span style="font-family: 宋体">方法</span><font face="Times New Roman">reference </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">＃</span><font face="Times New Roman">set ( $monkey.Number = 123 ) ##</font><span style="font-family: 宋体">数字</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">＃</span><font face="Times New Roman">set ( $monkey.Say = [&#8220;Not&#8221;, $my, &#8220;fault&#8221;] ) ##ArrayList </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">注意：最后一个例子的取值方法为：</span><font face="Times New Roman">$monkey.Say.get(0) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">RHS</font><span style="font-family: 宋体">也可以是一个简单的算术表达式：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $value = $foo + 1 ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $value = $bar -1 ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $value = $foo * $bar ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $value = $foo / $bar ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">如果你的</span><font face="Times New Roman">RHS</font><span style="font-family: 宋体">是一个</span><font face="Times New Roman">null</font><span style="font-family: 宋体">，</span><font face="Times New Roman">VTL</font><span style="font-family: 宋体">的处理将比较特殊：它将指向一个已经存在的</span><font face="Times New Roman">reference</font><span style="font-family: 宋体">，这对初学者来讲可能是比较费解的。例如：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $resut = $query.criteria(&#8220;name&#8221;) ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">结果是</span><font face="Times New Roman">$result </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $resut = $query.criteria(&#8220;address&#8221;) ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">结果是</span><font face="Times New Roman">$result </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">如果</span><font face="Times New Roman">$query.criteria(&#8220;name&#8221;)</font><span style="font-family: 宋体">返回一个</span><font face="Times New Roman">&#8220;bill&#8221;</font><span style="font-family: 宋体">，而</span><font face="Times New Roman">$query.criteria(&#8220;address&#8221;)</font><span style="font-family: 宋体">返回的是</span><font face="Times New Roman">null</font><span style="font-family: 宋体">，则显示的结果如下：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">结果是</span><font face="Times New Roman">bill </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">结果是</span><font face="Times New Roman">bill </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">看看下面的例子：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set( $criteria = ["name", "address"] ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#foreach( $criterion in $criteria ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set( $result = $query.criteria($criterion) ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#if( $result ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">Query was successful </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#end </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#end </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">在上面的例子中，程序将不能智能的根据</span><font face="Times New Roman">$result</font><span style="font-family: 宋体">的值决定查询是否成功。在</span><font face="Times New Roman">$result</font><span style="font-family: 宋体">被</span><font face="Times New Roman">#set</font><span style="font-family: 宋体">后（</span><font face="Times New Roman">added to the context</font><span style="font-family: 宋体">），它不能被设置回</span><font face="Times New Roman">null</font><span style="font-family: 宋体">（</span><font face="Times New Roman">removed from the context</font><span style="font-family: 宋体">）。打印的结果将显示两次查询结果都成功了，但是实际上有一个查询是失败的。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">为了解决以上问题我们可以通过预先定义的方式：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set( $criteria = [&#8220;name&#8221;, &#8220;address&#8221;] ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#foreach( $criterion in $criteria ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set( $result = false ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set( $result = $query.criteria( $criterion ) ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#if( $result ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">Query was successful </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#end </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#end</font></p>
<h3 style="margin: 7pt 0cm 0pt; text-indent: 0cm"><font size="5"><span style="font-weight: normal"><font face="Times New Roman">1.1.1 </font></span><span style="font-weight: normal; font-family: 黑体">字符串</span></font></h3>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">当你使用</span><font face="Times New Roman">#set directive</font><span style="font-family: 宋体">，字符串封闭在一对双引号内。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $directoryRoot = &#8220;www&#8221; ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $templateName = &#8220;index.vm&#8221; ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $template = &#8220;$directoryRoot/$tempateName&#8221; ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$template </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">上面这段代码的输出结果为：</span><font face="Times New Roman">www/index.vm</font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">但是，当字符串被封装在单引号内时，它将不被解析：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $foo = &#8220;bar&#8221; ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$foo </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#set ( $blargh = &#8216;$foo' ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">结果：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">bar </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$foo </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">上面这个特性可以通过修改</span><font face="Times New Roman">Views</font><span style="font-family: 宋体">目录下的</span><font face="Times New Roman">nvelocity.properties</font><span style="font-family: 宋体">文件的</span><font face="Times New Roman">stringliterals.interpolate = false</font><span style="font-family: 宋体">的值来改变上面的特性是否有效。</span></p>
<h3 style="margin: 7pt 0cm 0pt; text-indent: 0cm"><font size="5"><span style="font-weight: normal"><font face="Times New Roman">1.1.2 </font></span><span style="font-family: 黑体">条件语句</span></font></h3>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">if/elseif/else </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">当一个</span><font face="Times New Roman">web</font><span style="font-family: 宋体">页面被生成时使用</span><font face="Times New Roman">Velocity</font><span style="font-family: 宋体">的</span><font face="Times New Roman">#if directrive</font><span style="font-family: 宋体">，如果条件成立的话可以在页面内嵌入文字。例如：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#if ( $foo ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;strong&gt;nVelocity!&lt;/strong&gt; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#end </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">上例中的条件语句将在以下两种条件下成立：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$foo</font><span style="font-family: 宋体">是一个</span><font face="Times New Roman">boolean</font><span style="font-family: 宋体">型的变量，且它的值为</span><font face="Times New Roman">true </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">$foo</font><span style="font-family: 宋体">变量的值不为</span><font face="Times New Roman">null </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">这里需要注意一点：</span><font face="Times New Roman">Velocity context</font><span style="font-family: 宋体">仅仅能够包含对象，所以当我们说</span><font face="Times New Roman">&#8220;boolean&#8221;</font><span style="font-family: 宋体">时实际上代表的时一个</span><font face="Times New Roman">Boolean</font><span style="font-family: 宋体">对象。即便某个方法返回的是一个</span><font face="Times New Roman">boolean</font><span style="font-family: 宋体">值，</span><font face="Times New Roman">Velocity</font><span style="font-family: 宋体">也会利用内省机制将它转换为一个</span><font face="Times New Roman">Boolean</font><span style="font-family: 宋体">的相同值。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">如果条件成立，那么</span><font face="Times New Roman">#if</font><span style="font-family: 宋体">和</span><font face="Times New Roman">#end</font><span style="font-family: 宋体">之间的内容将被显示。</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#elseif</font><span style="font-family: 宋体">和</span><font face="Times New Roman">#else</font><span style="font-family: 宋体">元素可以同</span><font face="Times New Roman">#if</font><span style="font-family: 宋体">一同使用。例如：</span></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#if( $foo &lt; 10 ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;strong&gt; Go North &lt;/strong&gt; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#elseif( $foo == 10 ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;strong&gt; Go East &lt;/strong&gt; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#elseif( $foo == 6 ) </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;strong&gt; Go South &lt;/strong&gt; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#else </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">&lt;strong&gt; Go West &lt;/strong&gt; </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><font face="Times New Roman">#end </font></p>
<p style="margin: 0cm 0cm 0pt; text-indent: 24pt"><span style="font-family: 宋体">注意这里的</span><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">的数字是作为</span><font face="Times New Roman">Integer</font><span style="font-family: 宋体">来比较的</span><font face="Times New Roman">――</font><span style="font-family: 宋体">其他类型的对象将使得条件为</span><font face="Times New Roman">false</font><span style="font-family: 宋体">，它使用</span><font face="Times New Roman">&#8220;</font><span style="font-family: 宋体">＝＝</span><font face="Times New Roman">&#8221;</font><span style="font-family: 宋体">来比较两个值，而且</span><font face="Times New Roman">nVelocity</font><span style="font-family: 宋体">要求等号两边的值类型相同。</span></p>
</div>
</div>
<img src ="http://www.cnblogs.com/goody9807/aggbug/1234728.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37595/" target="_blank">[新闻]微软副总裁公开承认Vista存在问题</a>]]></description></item><item><title>HTML/text/JavaSript Escaping/Encoding Script</title><link>http://www.cnblogs.com/goody9807/archive/2008/07/02/1233866.html</link><dc:creator>PointNet</dc:creator><author>PointNet</author><pubDate>Wed, 02 Jul 2008 04:04:00 GMT</pubDate><guid>http://www.cnblogs.com/goody9807/archive/2008/07/02/1233866.html</guid><wfw:comment>http://www.cnblogs.com/goody9807/comments/1233866.html</wfw:comment><comments>http://www.cnblogs.com/goody9807/archive/2008/07/02/1233866.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/goody9807/comments/commentRss/1233866.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/goody9807/services/trackbacks/1233866.html</trackback:ping><description><![CDATA[These scripts are intended to explain how to "hide" HTML and/or javascript from other people who view your page's source code. It is not foolproof, but it does make it more difficult to read and understand the source code. Due to the nature of how these scripts work, the explanation may seem complicated and drawn out, but be patient and it should make sense once you gain a little experience with them. You don't really <em>have</em> to know the ins-and-outs of these scripts, but it does help you understand how and why they work. So, take a seat and I'll do my best to make this seem as un-complicated as possible.<br />
<br />
By the way, my stolen "popup" script at <span class="code">popovergenerator.com</span> uses a similar method of doing this to hide their thievery. Check out <a href="http://scriptasylum.com/tutorials/encdec/theft.html">this</a> page for proof...<br />
<br />
<hr />
<h3>Escape/Unescape</h3>
The first section of this page explains how to "escape" any text, HTML, or Javascript to make it generally unreadable to the common user. URL Escape Codes are two-character Hexadecimal (8-bit) values preceeded by a % sign. This is used primarily in browser URLs or for use when making cookies for characters that otherwise would not work, usually because they are reserved characters (like spaces and the like).<br />
<br />
For example, if you had an HTML filename of <span class="code">page one</span>, the escaped URL code would look like <span class="code">page%20one</span>. The <span class="code">%20</span> is the escaped value for a space. Normally, you would only escape special characters (generally any character other than a-z, A-Z, and 0-9), but the script below actually escapes <em>all</em> the text simply by replacing all characters with their escaped equivalents. So, if you were to <strong>fully</strong> escape the words <span class="code">page one</span>, it would look like: <span class="code">%70%61%67%65%20%6F%6E%65</span>. Now, none of the text is easily decipherable even though most of it was made up of normal characters.<br />
<br />
Since the browser can inherently handle escape codes, this can be used pretty easily without having to add any more script to decipher them. So, if you want the browser to write that escaped text to the page, you could do something like:<br />
<br />
<div class="code" style="border-right: #aaaaaa 1px solid; border-top: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; border-bottom: #aaaaaa 1px solid">&lt;script language="javascript"&gt;<br />
<div class="highlight">document.write( unescape( '%70%61%67%65%20%6F%6E%65' ) );</div>
&lt;/script&gt; </div>
<br />
All I'm doing here is putting the escaped string in a set of quotes (important!), wrapping that inside the built-in <span class="code">unescape()</span> method, and then wrapping that in a <span class="code">document.write()</span> method. This might seem a little worthless, but you could hide an email address this way to prevent web crawlers from snagging your e-mail address from your webpage to use in mass spam e-mailings, yet allowing visitors to read it fine... Unless, of course, you actually <em>like</em> getting Viagra solicitations. :)<br />
For instance, my fully escaped e-mail address would look like this to a web crawler:<br />
<br />
<div class="code" style="border-right: #aaaaaa 1px solid; border-top: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; border-bottom: #aaaaaa 1px solid">&lt;script language="javascript"&gt;<br />
<div class="highlight">document.write( unescape( '%73%63%72%69%70%74%61%73%79%6C%75%6D%40%68%6F%74%6D%61%69%6C%2E%63%6F%6D' ) );</div>
&lt;/script&gt; </div>
<br />
... but would look like this to a visitor:<br />
<br />
<span class="code">scriptasylum@hotmail.com</span><br />
<br />
The two textboxes below will let you fully escape and unescape any text you want. Just type whatever text/HTML/JavaScript you want in the left box and click the <span class="codeB">--&gt;</span> button to fully escape it. Likewise, click the <span class="codeB">&lt;--</span> button to convert it back to normal text to verify that it is the same as the original. You can copy &amp; paste the escaped code into your page (don't forget to use the <span class="code">unescape()</span> and <span class="code">document.write()</span> methods).<br />
<br />
<center>
<form name="fA">
    <table cellspacing="0" cellpadding="5" width="700" border="0">
        <tbody>
            <tr valign="top" align="center">
                <td class="tblc" width="350">Normal Text/HTML/JavaScript &nbsp; (<a href="javascript:document.forms['fA'].f1.focus();document.forms['fA'].f1.select();">Select all...</a>) <br />
                <br />
                <textarea id="f1" rows="10" wrap="off" cols="50">六年&#8220;深&#8221;发展 把握潮流再"腾&#8221;飞 </textarea> </td>
                <td><br />
                <br />
                <br />
                <br />
                <input onclick="document.fA.c1.value=escapeTxt(document.fA.f1.value)" type="button" value="  -- />  "><br />
                <br />
                <input onclick="document.fA.f1.value=unescapeTxt(document.fA.c1.value)" type="button" value="  <--  " /> </td>
                <td class="tblc" width="350">Escaped Text/HTML/JavaScript &nbsp; (<a href="javascript:document.forms['fA'].c1.focus();document.forms['fA'].c1.select();">Select all...</a>) <br />
                <br />
                <textarea id="c1" rows="10" cols="50">六年&#8220;深&#8221;发展%20把握潮流再%22腾&#8221;飞%20</textarea> </td>
            </tr>
        </tbody>
    </table>
</form>
</center>
<hr />
<br />
<h3>Encoding/Decoding</h3>
Now, you probably have figured out that you <em>could</em> hide an entire HTML page using the above method; but there are two disadvantages to doing that: Size and ease of "cracking" your code.<br />
<br />
When you fully escape an entire page, every single character becomes 3 characters. This will triple the size of your page. Not a big deal if the page is only about 1-5 KBytes in size; but when you have a fairly large page (&gt;10 KBytes), the filesize increases rapidly. This would slow the load time for the dial-up connection surfers out there.<br />
<br />
Also, if someone were to look at your source code, it would be pretty easy to figure out what you are doing. Then they can simply copy &amp; paste the code and make a small script to display the normal content. There is no absolute foolproof way (client-side) to foil someone from viewing your source if they are determined enough; the best you can hope for is to make it as inconvenient as possible.<br />
<br />
So, to address both concerns you could encode/decode the text. Again, it won't be foolproof to keep people from stealing your source content if they really want it. I am really using the terms "encode" and "decode" loosely here; what the following script does is not considered actual encoding, but it's easier to say it that way. The encoded output will be a bit longer than the original text, but a lot less than if you had simply escaped it all.<br />
<br />
The above section just escapes the text. The section below actually <em>shifts</em> the Unicode values so the result looks like gibberish. Give it a try and you'll see; don't forget to try different <span class="code">Code Key</span> values from the drop-down box.
<center><br />
<br />
<form name="fB">
    <table cellspacing="0" cellpadding="5" width="700" border="0">
        <tbody>
            <tr valign="top" align="center">
                <td class="tblc" width="350">Normal Text/HTML/JavaScript &nbsp; (<a href="javascript:document.forms['fB'].f2.focus();document.forms['fB'].f2.select();">Select all...</a>) <br />
                <br />
                <textarea id="f2" rows="10" wrap="off" cols="50">六年&#8220;深&#8221;发展 把握潮流再"腾&#8221;飞</textarea> </td>
                <td><br />
                <br />
                <input onclick="document.fB.c2.value=encodeTxt(document.fB.f2.value)" type="button" value="  -- />  "><br />
                <br />
                <input onclick="document.fB.f2.value=decodeTxt(document.fB.c2.value)" type="button" value="  <--  " /><br />
                <br />
                Code Key:<br />
                <select onchange="encN=this.selectedIndex+1" name="et">
                <option>1
                <option selected>2
                <option>3
                <option>4
                <option>5</option>
                </select> </td>
                <td class="tblc" width="350">Encoded Text/HTML/JavaScript &nbsp; (<a href="javascript:document.forms['fB'].c2.focus();document.forms['fB'].c2.select();">Select all...</a>) <br />
                <br />
                <textarea id="c2" rows="10" cols="50">%27w738F%27w7G96%27w423E%27w8FH3%27w423F%27w75F3%27w7E77%2742%27w84%3AC%27w85G3%27w8H8G%27w8F63%27w73%3AF%2744%27w%3A39G%27w423F%27w%3B%3AFG2</textarea> </td>
            </tr>
        </tbody>
    </table>
</form>
</center><br />
The following steps are what the script does to accomplish this effect when you click the <span class="codeB">--&gt;</span> (encode) button:
<ol>
    <li>First, all the text is escaped.
    <li>Then the script finds the Unicode values for each character in the string.
    <li>Then the script adds whatever the <span class="code">Code Key</span> drop-down box value is to each character's Unicode value.
    <li>Then the script derives characters based on the shifted Unicode values.
    <li>The <span class="code">Code Key</span> value is also embedded in the decoded text so the script knows how to properly decode the string again.
    <li>Finally, it escapes the result one more time to remove any special characters. Now, the output looks totally foreign to someone who cannot <em>un-shift</em> Unicode values in their head. :) </li>
</ol>
The decode step <span class="codeB">&lt;--</span> simply reverses the process.<br />
<br />
Unfortunately, the browser does not have any built-in ability to handle the decoding, so we have to use a function for that. So, you have to <em>escape</em> the function that handles the decoding to hide that part, and have the browser write it to the document. You don't really <em>have</em> to escape the decoding function, but it will make it that much harder for someone to figure out what's going on. Then, the decoding function can be used to decode the rest of whatever content you have encoded. I'll outline the steps below one-by-one to make this less confusing.
<ol>
    <li>Escape the decoding function. Before this function is escaped, it looks like this:<br />
    <br />
    <div class="code" style="border-right: #aaaaaa 1px solid; border-top: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; border-bottom: #aaaaaa 1px solid">&lt;script language="javascript"&gt;<br />
    function dF(s){<br />
    var s1=unescape(s.substr(0,s.length-1)); var t='';<br />
    for(i=0;i&lt;s1.length;i++)t+=String.fromCharCode(s1.charCodeAt(i)-s.substr(s.length-1,1));<br />
    document.write(unescape(t));<br />
    }<br />
    &lt;/script&gt;</div>
    <br />
    Once escaped, the function looks like this:<br />
    <br />
    <div class="code" style="border-right: #aaaaaa 1px solid; border-top: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; border-bottom: #aaaaaa 1px solid">%3C%73%63%72%69%70%74%20%6C%61%6E%67%75%61%67%65%3D%22%6A%61%76%61%73%63%72%69%70%74%22%3E%0D%0A%66%75%6E%63%74%69%6F%6E%20%64%46%28%73%29%7B%0D%0A%76%61%72%20%73%31%3D%75%6E%65%73%63%61%70%65%28%73%2E%73%75%62%73%74%72%28%30%2C%73%2E%6C%65%6E%67%74%68%2D%31%29%29%3B%20%76%61%72%20%74%3D%27%27%3B%0D%0A%66%6F%72%28%69%3D%30%3B%69%3C%73%31%2E%6C%65%6E%67%74%68%3B%69%2B%2B%29%74%2B%3D%53%74%72%69%6E%67%2E%66%72%6F%6D%43%68%61%72%43%6F%64%65%28%73%31%2E%63%68%61%72%43%6F%64%65%41%74%28%69%29%2D%73%2E%73%75%62%73%74%72%28%73%2E%6C%65%6E%67%74%68%2D%31%2C%31%29%29%3B%0D%0A%64%6F%63%75%6D%65%6E%74%2E%77%72%69%74%65%28%75%6E%65%73%63%61%70%65%28%74%29%29%3B%0D%0A%7D%0D%0A%3C%2F%73%63%72%69%70%74%3E</div>
    <br />
    Neat huh? :)<br />
    Anyway, now you have to make the browser write that part of the script to the page by wrapping it in the <span class="code">document.write()</span> and <span class="code">unescape()</span> methods like this:<br />
    <br />
    <div class="code" style="border-right: #aaaaaa 1px solid; border-top: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; border-bottom: #aaaaaa 1px solid">&lt;script language="javascript"&gt;<br />
    document.write( unescape( '%3C%73%63%72%69%70%74%20%6C%61%6E%67%75%61%67%65%3D%22%6A%61%76%61%73%63%72%69%70%74%22%3E%0D%0A%66%75%6E%63%74%69%6F%6E%20%64%46%28%73%29%7B%0D%0A%76%61%72%20%73%31%3D%75%6E%65%73%63%61%70%65%28%73%2E%73%75%62%73%74%72%28%30%2C%73%2E%6C%65%6E%67%74%68%2D%31%29%29%3B%20%76%61%72%20%74%3D%27%27%3B%0D%0A%66%6F%72%28%69%3D%30%3B%69%3C%73%31%2E%6C%65%6E%67%74%68%3B%69%2B%2B%29%74%2B%3D%53%74%72%69%6E%67%2E%66%72%6F%6D%43%68%61%72%43%6F%64%65%28%73%31%2E%63%68%61%72%43%6F%64%65%41%74%28%69%29%2D%73%2E%73%75%62%73%74%72%28%73%2E%6C%65%6E%67%74%68%2D%31%2C%31%29%29%3B%0D%0A%64%6F%63%75%6D%65%6E%74%2E%77%72%69%74%65%28%75%6E%65%73%63%61%70%65%28%74%29%29%3B%0D%0A%7D%0D%0A%3C%2F%73%63%72%69%70%74%3E' ))<br />
    &lt;/script&gt;</div>
    <br />
    <li>Now that you have the decoding function on the page, you can call it to decode whatever content you have encoded. Let's say you had a script you wanted to protect; something like an image preloading script like this:<br />
    <br />
    <div class="code" style="border-right: #aaaaaa 1px solid; border-top: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; border-bottom: #aaaaaa 1px solid">&lt;script language="javascript"&gt;<br />
    function preloadImages(){<br />
    var iA=new Array();<br />
    for(i=0;i&lt;arguments.length;i++){<br />
    iA[i]=new Image();<br />
    iA[i].src=arguments[i];<br />
    }}<br />
    <br />
    preloadImages('img1.gif','img2.gif','img3.gif');<br />
    &lt;/script&gt;<br />
    </div>
    <br />
    Once the script above is encoded using "code key" number 1, it looks like this:<br />
    <br />
    <div class="code" style="border-right: #aaaaaa 1px solid; border-top: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; border-bottom: #aaaaaa 1px solid">%264Dtdsjqu%2631mbohvbhf%264E%2633kbwbtdsjqu%2633%264F%261E%261Bgvodujpo%2631qsfmpbeJnbhft%2639%263%3A%268C%261E%261Bwbs%2631jB%264Eofx%2631Bssbz%2639%263%3A%264C%261E%261Bgps%2639j%264E1%264Cj%264Dbshvnfout/mfohui%264Cj%2C%2C%263%3A%268C%261E%261BjB%266Cj%266E%264Eofx%2631Jnbhf%2639%263%3A%264C%261E%261BjB%266Cj%266E/tsd%264Ebshvnfout%266Cj%266E%264C%261E%261B%268E%268E%261E%261B%261E%261BqsfmpbeJnbhft%2639%2638jnh2/hjg%2638%263D%2638jnh3/hjg%2638%263D%2638jnh4/hjg%2638%263%3A%264C%261E%261B%264D0tdsjqu%264F1 </div>
    <br />
    Then, you decode the string and write it to the page by calling the <span class="code">dF()</span> function (which was just unescaped and written to the page in the previous step) passing the string above like this:<br />
    <br />
    <div class="code" style="border-right: #aaaaaa 1px solid; border-top: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; border-bottom: #aaaaaa 1px solid">dF('%264Dtdsjqu%2631mbohvbhf%264E%2633kbwbtdsjqu%2633%264F%261E%261Bgvodujpo%2631qsfmpbeJnbhft%2639%263%3A%268C%261E%261Bwbs%2631jB%264Eofx%2631Bssbz%2639%263%3A%264C%261E%261Bgps%2639j%264E1%264Cj%264Dbshvnfout/mfohui%264Cj%2C%2C%263%3A%268C%261E%261BjB%266Cj%266E%264Eofx%2631Jnbhf%2639%263%3A%264C%261E%261BjB%266Cj%266E/tsd%264Ebshvnfout%266Cj%266E%264C%261E%261B%268E%268E%261E%261B%261E%261BqsfmpbeJnbhft%2639%2638jnh2/hjg%2638%263D%2638jnh3/hjg%2638%263D%2638jnh4/hjg%2638%263%3A%264C%261E%261B%264D0tdsjqu%264F1');</div>
    </li>
</ol>
So, to bring all this together, the following is what you would paste into your page:<br />
<br />
<div class="code" style="border-right: #aaaaaa 1px solid; border-top: #aaaaaa 1px solid; border-left: #aaaaaa 1px solid; border-bottom: #aaaaaa 1px solid">&lt;script language="javascript"&gt;<br />
<span style="background-color: #fffed1">document.write(unescape('%3C%73%63%72%69%70%74%20%6C%61%6E%67%75%61%67%65%3D%22%6A%61%76%61%73%63%72%69%70%74%22%3E%0D%0A%66%75%6E%63%74%69%6F%6E%20%64%46%28%73%29%7B%0D%0A%76%61%72%20%73%31%3D%75%6E%65%73%63%61%70%65%28%73%2E%73%75%62%73%74%72%28%30%2C%73%2E%6C%65%6E%67%74%68%2D%31%29%29%3B%20%76%61%72%20%74%3D%27%27%3B%0D%0A%66%6F%72%28%69%3D%30%3B%69%3C%73%31%2E%6C%65%6E%67%74%68%3B%69%2B%2B%29%74%2B%3D%53%74%72%69%6E%67%2E%66%72%6F%6D%43%68%61%72%43%6F%64%65%28%73%31%2E%63%68%61%72%43%6F%64%65%41%74%28%69%29%2D%73%2E%73%75%62%73%74%72%28%73%2E%6C%65%6E%67%74%68%2D%31%2C%31%29%29%3B%0D%0A%64%6F%63%75%6D%65%6E%74%2E%77%72%69%74%65%28%75%6E%65%73%63%61%70%65%28%74%29%29%3B%0D%0A%7D%0D%0A%3C%2F%73%63%72%69%70%74%3E'));</span><span style="background-color: #d1e3ff">dF('%264Dtdsjqu%2631mbohvbhf%264E%2633kbwbtdsjqu%2633%264F%261E%261Bgvodujpo%2631qsfmpbeJnbhft%2639%263%3A%268C%261E%261Bwbs%2631jB%264Eofx%2631Bssbz%2639%263%3A%264C%261E%261Bgps%2639j%264E1%264Cj%264Dbshvnfout/mfohui%264Cj%2C%2C%263%3A%268C%261E%261BjB%266Cj%266E%264Eofx%2631Jnbhf%2639%263%3A%264C%261E%261BjB%266Cj%266E/tsd%264Ebshvnfout%266Cj%266E%264C%261E%261B%268E%268E%261E%261B%261E%261BqsfmpbeJnbhft%2639%2638jnh2/hjg%2638%263D%2638jnh3/hjg%2638%263D%2638jnh4/hjg%2638%263%3A%264C%261E%261B%264D0tdsjqu%264F1');</span><br />
&lt;/script&gt; </div>
<br />
I've highlighted the part that unescapes the decoder function in light yellow, and the part that decodes the preloading script and writes it to the page in light blue. You would just paste the whole section above into your page and the script would function perfectly just like it would if it were plain old English. Yes, it looks confusing, but that's the point isn't it? Oh, and one more thing: the whole string should appear on <strong>one line</strong>; you can <u>not</u> add forced line breaks.<br />
<br />
The same thing is done if you want to encode a whole HTML page, except the encoded part of the string (light blue) could potentially be <strong>HUGE</strong>. The escaped function (light yellow) would <strong>not</strong> change however.<br />
<br />
I've made a couple of wizards you can use for different purposes. You can achieve the same thing by using the escape/un-escape &amp; encoder/decoder functions above, but these are specialized to take out some of the guesswork. Each of the links below will open a new window.
<ul>
    <li><a href="http://scriptasylum.com/tutorials/encdec/javascript_encoder.html" target="_blank">Javascript Encoder</a> - Designed to encode Javascript <strong>only</strong>. Useful to only encode and install a script in an already created HTML page.
    <li><a href="http://scriptasylum.com/tutorials/encdec/html_encoder.html" target="_blank">HTML Page Encoder</a> - Designed to encode your whole HTML page. You just enter your HTML sourcecode into one box, select the encoding scheme, and press the "encode" button. The output can be pasted directly into a blank page and saved as an HTML file. </li>
</ul>
The method this script uses to shift the Unicode values may be different from other similar encoding scripts you may find elsewhere on the net. My version simply adds the "Code Key" value to the Unicode value. Others may subtract, multiply, divide, square, etc a number to scramble the original text. No matter what, the method is very similar.<br />
<br />
You can find a complete chart of all the UniCode values using the MS Windows <span class="code">charmap</span> application. 
<img src ="http://www.cnblogs.com/goody9807/aggbug/1233866.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37594/" target="_blank">[新闻]互联网DNS存在重大漏洞 黑客可能控制网络流量</a>]]></description></item><item><title>自己修改的一个WebRequest+代理+POST登录</title><link>http://www.cnblogs.com/goody9807/archive/2008/07/01/1107512.html</link><dc:creator>PointNet</dc:creator><author>PointNet</author><pubDate>Tue, 01 Jul 2008 06:02:00 GMT</pubDate><guid>http://www.cnblogs.com/goody9807/archive/2008/07/01/1107512.html</guid><wfw:comment>http://www.cnblogs.com/goody9807/comments/1107512.html</wfw:comment><comments>http://www.cnblogs.com/goody9807/archive/2008/07/01/1107512.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/goody9807/comments/commentRss/1107512.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/goody9807/services/trackbacks/1107512.html</trackback:ping><description><![CDATA[<div class="cnt" id="blog_text">
<p>public static void ProxySetting(WebRequest request)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WebProxy proxy = WebProxy.GetDefaultProxy();//获取IE缺省设置<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //如果缺省设置为空，则有可能是根本不需要代理服务器，如果此时配置文件中也未配置则认为不需Proxy<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (proxy.Address == null)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; proxy.Address = new Uri("&#215;&#215;&#215;&#215;&#215;&#215;:8080");//按配置文件创建Proxy 地置<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (proxy.Address != null)//如果地址为空，则不需要代理服务器<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; proxy.Credentials = new NetworkCredential("test123","123456");//从配置封装参数中创建<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; request.Proxy = proxy;//赋予 request.Proxy <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static string GetHtmlOne(string url)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; url = url.Replace("&amp;amp;", "&amp;");<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string indata = "userid=name&amp;passwd=password&amp;SESSION_TIMEOUT=40";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string outdata = "";</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CookieContainer myCookieContainer = new CookieContainer();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //新建一个CookieContainer来存放Cookie集合 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpWebRequest myHttpWebRequest;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http:// www.12355.com/logincheck.aspx");<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //新建一个HttpWebRequest <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebRequest.ContentLength = indata.Length;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebRequest.Method = "POST";<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ProxySetting(myHttpWebRequest);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebRequest.CookieContainer = myCookieContainer;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainer <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Stream myRequestStream = myHttpWebRequest.GetRequestStream();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myStreamWriter.Write(indata);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //把数据写入HttpWebRequest的Request流 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myStreamWriter.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myRequestStream.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //关闭打开对象 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //新建一个HttpWebResponse <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //获取一个包含url的Cookie集合的CookieCollection <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Stream myResponseStream = myHttpWebResponse.GetResponseStream();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outdata = myStreamReader.ReadToEnd();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //把数据从HttpWebResponse的Response流中读出 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myStreamReader.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myResponseStream.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //显示"登录" </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //拿到了Cookie，再进行请求就能直接读取到登录后的内容了 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ProxySetting(myHttpWebRequest);//设置代理访问的权限。<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebRequest.CookieContainer = myCookieContainer;//* <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myResponseStream = myHttpWebResponse.GetResponseStream();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; outdata = myStreamReader.ReadToEnd();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myStreamReader.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; myResponseStream.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return outdata;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //再次显示"登录" <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //如果把*行注释调，就显示"没有登录" </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p>
</div>
 <img src ="http://www.cnblogs.com/goody9807/aggbug/1107512.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37593/" target="_blank">[新闻]Opera提出网络标准课程 发布标准教育倡议</a>]]></description></item><item><title>如果向某网址Post信息，并得到CookieContainer以便以后直接通过验证</title><link>http://www.cnblogs.com/goody9807/archive/2008/06/26/1107560.html</link><dc:creator>PointNet</dc:creator><author>PointNet</author><pubDate>Thu, 26 Jun 2008 03:49:00 GMT</pubDate><guid>http://www.cnblogs.com/goody9807/archive/2008/06/26/1107560.html</guid><wfw:comment>http://www.cnblogs.com/goody9807/comments/1107560.html</wfw:comment><comments>http://www.cnblogs.com/goody9807/archive/2008/06/26/1107560.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/goody9807/comments/commentRss/1107560.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/goody9807/services/trackbacks/1107560.html</trackback:ping><description><![CDATA[<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee"><span style="color: #000000">&nbsp;&nbsp;<br />
</span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;system;<br />
</span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;system.net;<br />
</span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;system.io;<br />
</span><span style="color: #0000ff">using</span><span style="color: #000000">&nbsp;system.text;<br />
[stathread]<br />
</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;main(</span><span style="color: #0000ff">string</span><span style="color: #000000">[]&nbsp;args)<br />
{<br />
</span><span style="color: #008000">//</span><span style="color: #008000"><br />
</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;todo:&nbsp;在此处添加代码以启动应用程序<br />
</span><span style="color: #008000">//<br />
</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;url</span><span style="color: #000000">=</span><span style="color: #800000">"</span><span style="color: #800000">http://localhost/csdn2/1.asp</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;</span><span style="color: #008000"><br />
</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;indata</span><span style="color: #000000">=</span><span style="color: #800000">"</span><span style="color: #800000">aa=zhuye</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;outdata</span><span style="color: #000000">=</span><span style="color: #800000">""</span><span style="color: #000000">;<br />
cookiecontainer&nbsp;mycookiecontainer</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;cookiecontainer();<br />
</span><span style="color: #008000">//</span><span style="color: #008000">新建一个cookiecontainer来存放cookie集合</span><span style="color: #008000"><br />
</span><span style="color: #000000">httpwebrequest&nbsp;myhttpwebrequest</span><span style="color: #000000">=</span><span style="color: #000000">(httpwebrequest)webrequest.create(url);<br />
</span><span style="color: #008000">//</span><span style="color: #008000">新建一个httpwebrequest</span><span style="color: #008000"><br />
</span><span style="color: #000000">myhttpwebrequest.contenttype</span><span style="color: #000000">=</span><span style="color: #800000">"</span><span style="color: #800000">application/x-www-form-urlencoded</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
myhttpwebrequest.contentlength</span><span style="color: #000000">=</span><span style="color: #000000">indata.length;<br />
myhttpwebrequest.method</span><span style="color: #000000">=</span><span style="color: #800000">"</span><span style="color: #800000">post</span><span style="color: #800000">"</span><span style="color: #000000">;<br />
myhttpwebrequest.cookiecontainer</span><span style="color: #000000">=</span><span style="color: #000000">mycookiecontainer;<br />
</span><span style="color: #008000">//</span><span style="color: #008000">设置httpwebrequest的cookiecontainer为刚才建立的那个mycookiecontainer</span><span style="color: #008000"><br />
</span><span style="color: #000000">stream&nbsp;myrequeststream</span><span style="color: #000000">=</span><span style="color: #000000">myhttpwebrequest.getrequeststream();<br />
streamwriter&nbsp;mystreamwriter</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;streamwriter(myrequeststream,encoding.getencoding(</span><span style="color: #800000">"</span><span style="color: #800000">gb2312</span><span style="color: #800000">"</span><span style="color: #000000">));&nbsp;<br />
mystreamwriter.write(indata);<br />
</span><span style="color: #008000">//</span><span style="color: #008000">把数据写入httpwebrequest的request流</span><span style="color: #008000"><br />
</span><span style="color: #000000">mystreamwriter.close();<br />
myrequeststream.close();<br />
</span><span style="color: #008000">//</span><span style="color: #008000">关闭打开对象</span><span style="color: #008000"><br />
</span><span style="color: #000000">httpwebresponse&nbsp;myhttpwebresponse</span><span style="color: #000000">=</span><span style="color: #000000">(httpwebresponse)myhttpwebrequest.getresponse();<br />
</span><span style="color: #008000">//</span><span style="color: #008000">新建一个httpwebresponse</span><span style="color: #008000"><br />
</span><span style="color: #000000">myhttpwebresponse.cookies</span><span style="color: #000000">=</span><span style="color: #000000">mycookiecontainer.getcookies(myhttpwebrequest.requesturi);<br />
</span><span style="color: #008000">//</span><span style="color: #008000">获取一个包含url的cookie集合的cookiecollection</span><span style="color: #008000"><br />
</span><span style="color: #000000">stream&nbsp;myresponsestream</span><span style="color: #000000">=</span><span style="color: #000000">myhttpwebresponse.getresponsestream();<br />
streamreader&nbsp;mystreamreader</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;streamreader(myresponsestream,encoding.getencoding(</span><span style="color: #800000">"</span><span style="color: #800000">gb2312</span><span style="color: #800000">"</span><span style="color: #000000">));<br />
outdata</span><span style="color: #000000">=</span><span style="color: #000000">mystreamreader.readtoend();<br />
</span><span style="color: #008000">//</span><span style="color: #008000">把数据从httpwebresponse的response流中读出</span><span style="color: #008000"><br />
</span><span style="color: #000000">mystreamreader.close();<br />
myresponsestream.close();<br />
console.writeline(outdata);<br />
</span><span style="color: #008000">//</span><span style="color: #008000">显示"登录"<br />
<br />
</span><span style="color: #008000">//</span><span style="color: #008000">拿到了cookie，再进行请求就能直接读取到登录后的内容了</span><span style="color: #008000"><br />
</span><span style="color: #000000">myhttpwebrequest</span><span style="color: #000000">=</span><span style="color: #000000">(httpwebrequest)webrequest.create(url);<br />
myhttpwebrequest.cookiecontainer</span><span style="color: #000000">=</span><span style="color: #000000">mycookiecontainer;</span><span style="color: #008000">//</span><span style="color: #008000">*<br />
</span><span style="color: #008000">//</span><span style="color: #008000">刚才那个cookiecontainer已经存有了cookie,把它附加到httpwebrequest中则能直接通过验证</span><span style="color: #008000"><br />
</span><span style="color: #000000">myhttpwebresponse</span><span style="color: #000000">=</span><span style="color: #000000">(httpwebresponse)myhttpwebrequest.getresponse();<br />
myhttpwebresponse.cookies</span><span style="color: #000000">=</span><span style="color: #000000">mycookiecontainer.getcookies(myhttpwebrequest.requesturi);&nbsp;<br />
myresponsestream</span><span style="color: #000000">=</span><span style="color: #000000">myhttpwebresponse.getresponsestream();<br />
mystreamreader</span><span style="color: #000000">=</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;streamreader(myresponsestream,encoding.getencoding(</span><span style="color: #800000">"</span><span style="color: #800000">gb2312</span><span style="color: #800000">"</span><span style="color: #000000">));<br />
outdata</span><span style="color: #000000">=</span><span style="color: #000000">mystreamreader.readtoend();<br />
mystreamreader.close();<br />
myresponsestream.close();<br />
console.writeline(outdata);&nbsp;<br />
</span><span style="color: #008000">//</span><span style="color: #008000">再次显示"登录"<br />
</span><span style="color: #008000">//</span><span style="color: #008000">如果把*行注释调，就显示"没有登录"</span><span style="color: #008000"><br />
</span><span style="color: #000000">}<br />
<br />
</span></div>
 <img src ="http://www.cnblogs.com/goody9807/aggbug/1107560.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37592/" target="_blank">[新闻]SubSonic 2.1 版本发布</a>]]></description></item><item><title>[原创]如何设置Mysql数据库默认的字符集编码为GBK</title><link>http://www.cnblogs.com/goody9807/archive/2008/06/25/1229733.html</link><dc:creator>PointNet</dc:creator><author>PointNet</author><pubDate>Wed, 25 Jun 2008 08:01:00 GMT</pubDate><guid>http://www.cnblogs.com/goody9807/archive/2008/06/25/1229733.html</guid><wfw:comment>http://www.cnblogs.com/goody9807/comments/1229733.html</wfw:comment><comments>http://www.cnblogs.com/goody9807/archive/2008/06/25/1229733.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/goody9807/comments/commentRss/1229733.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/goody9807/services/trackbacks/1229733.html</trackback:ping><description><![CDATA[最近一直在搞discuz论坛，使用mysql+php<br />
<br />
由于mysql默认的字符集编码为latin&nbsp; ，而我们一般使用的是gbk 或者 gb2312编码<br />
所以不改过来容易造成乱码<br />
<br />
我用的是mysql 5.0&nbsp;&nbsp; 安装程序安装的 ，安装目录在<font face="Verdana">C:\Program Files\MySQL\MySQL Server 5.0</font><br />
请到这个目录下面找到 my。ini文件<br />
<br />
修改<font face="Verdana">default-character-set=latin1&nbsp; 为 <font face="Verdana">default-character-set=gbk</font><br />
<br />
记住有两个地方啊 都要改<br />
<br />
最重要的一点就是修改文件前，先停止mysql服务 ，等修改后再重新启动<br />
使用dos命令&nbsp; ：net stop mysql&nbsp; 来停止服务&nbsp;&nbsp; net&nbsp; start mysql&nbsp; 来启动<br />
<br />
然后在执行你的mysql脚本 ，一切ok！ 这里你可以用discuz的sql做为例子运行！</font>
<img src ="http://www.cnblogs.com/goody9807/aggbug/1229733.html?type=1" width = "1" height = "1" /><br><br><a href="http://news.cnblogs.com/n/37590/" target="_blank">[新闻]语义搜索领跑后google搜索引擎</a>]]></description></item><item><title>mysql中文乱码，phpmyadmin乱码，php乱码 产生原因及其解决方法</title><link>http://www.cnblogs.com/goody9807/archive/2008/06/24/1229097.html</link><dc:creator>PointNet</dc:creator><author>PointNet</author><pubDate>Tue, 24 Jun 2008 09:34:00 GMT</pubDate><guid>http://www.cnblogs.com/goody9807/archive/2008/06/24/1229097.html</guid><wfw:comment>http://www.cnblogs.com/goody9807/comments/1229097.html</wfw:comment><comments>http://www.cnblogs.com/goody9807/archive/2008/06/24/1229097.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnblogs.com/goody9807/comments/commentRss/1229097.html</wfw:commentRss><trackback:ping>http://www.cnblogs.com/goody9807/services/trackbacks/1229097.html</trackback:ping><description><![CDATA[<p><strong><font color="red"><font size="6">乱码产生原因 </font></font></strong><br />
<br />
mysql字符编码是版本4.1引入的,支持多国语言,而且一些特性已经超过了其他的数据库系统。<br />
<br />
我们可以在MySQL Command Line Client 下输入如下命令查看mysql的字符集<br />
<br />
mysql&gt; SHOW CHARACTER SET;<br />
+----------+-----------------------------+---------------------+--------+<br />
| Charset&nbsp;&nbsp;| Description&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| Default collation&nbsp; &nbsp;| Maxlen |<br />
+----------+-----------------------------+---------------------+--------+<br />
| big5&nbsp; &nbsp;&nbsp;&nbsp;| Big5 Traditional Chinese&nbsp; &nbsp; | big5_chinese_ci&nbsp; &nbsp;&nbsp;&nbsp;| 2&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| dec8&nbsp; &nbsp;&nbsp;&nbsp;| DEC West European&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| dec8_swedish_ci&nbsp; &nbsp;&nbsp;&nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| cp850&nbsp; &nbsp; | DOS West European&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| cp850_general_ci&nbsp; &nbsp; | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| hp8&nbsp; &nbsp;&nbsp; &nbsp;| HP West European&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| hp8_english_ci&nbsp; &nbsp;&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| koi8r&nbsp; &nbsp; | KOI8-R Relcom Russian&nbsp; &nbsp;&nbsp; &nbsp; | koi8r_general_ci&nbsp; &nbsp; | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| latin1&nbsp; &nbsp;| cp1252 West European&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| latin1_swedish_ci&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| latin2&nbsp; &nbsp;| ISO 8859-2 Central European | latin2_general_ci&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| swe7&nbsp; &nbsp;&nbsp;&nbsp;| 7bit Swedish&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; | swe7_swedish_ci&nbsp; &nbsp;&nbsp;&nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| ascii&nbsp; &nbsp; | US ASCII&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| ascii_general_ci&nbsp; &nbsp; | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| ujis&nbsp; &nbsp;&nbsp;&nbsp;| EUC-JP Japanese&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; | ujis_japanese_ci&nbsp; &nbsp; | 3&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| sjis&nbsp; &nbsp;&nbsp;&nbsp;| Shift-JIS Japanese&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; | sjis_japanese_ci&nbsp; &nbsp; | 2&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| hebrew&nbsp; &nbsp;| ISO 8859-8 Hebrew&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| hebrew_general_ci&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| tis620&nbsp; &nbsp;| TIS620 Thai&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| tis620_thai_ci&nbsp; &nbsp;&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| euckr&nbsp; &nbsp; | EUC-KR Korean&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| euckr_korean_ci&nbsp; &nbsp;&nbsp;&nbsp;| 2&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| koi8u&nbsp; &nbsp; | KOI8-U Ukrainian&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| koi8u_general_ci&nbsp; &nbsp; | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| gb2312&nbsp; &nbsp;| GB2312 Simplified Chinese&nbsp; &nbsp;| gb2312_chinese_ci&nbsp; &nbsp;| 2&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| greek&nbsp; &nbsp; | ISO 8859-7 Greek&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| greek_general_ci&nbsp; &nbsp; | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| cp1250&nbsp; &nbsp;| Windows Central European&nbsp; &nbsp; | cp1250_general_ci&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| gbk&nbsp; &nbsp;&nbsp; &nbsp;| GBK Simplified Chinese&nbsp; &nbsp;&nbsp; &nbsp;| gbk_chinese_ci&nbsp; &nbsp;&nbsp; &nbsp;| 2&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| latin5&nbsp; &nbsp;| ISO 8859-9 Turkish&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; | latin5_turkish_ci&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| armscii8 | ARMSCII-8 Armenian&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; | armscii8_general_ci | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| utf8&nbsp; &nbsp;&nbsp;&nbsp;| UTF-8 Unicode&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| utf8_general_ci&nbsp; &nbsp;&nbsp;&nbsp;| 3&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| ucs2&nbsp; &nbsp;&nbsp;&nbsp;| UCS-2 Unicode&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| ucs2_general_ci&nbsp; &nbsp;&nbsp;&nbsp;| 2&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| cp866&nbsp; &nbsp; | DOS Russian&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| cp866_general_ci&nbsp; &nbsp; | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| keybcs2&nbsp;&nbsp;| DOS Kamenicky Czech-Slovak&nbsp;&nbsp;| keybcs2_general_ci&nbsp;&nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| macce&nbsp; &nbsp; | Mac Central European&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| macce_general_ci&nbsp; &nbsp; | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| macroman | Mac West European&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| macroman_general_ci | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| cp852&nbsp; &nbsp; | DOS Central European&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| cp852_general_ci&nbsp; &nbsp; | 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| latin7&nbsp; &nbsp;| ISO 8859-13 Baltic&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; | latin7_general_ci&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| cp1251&nbsp; &nbsp;| Windows Cyrillic&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| cp1251_general_ci&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| cp1256&nbsp; &nbsp;| Windows Arabic&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| cp1256_general_ci&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| cp1257&nbsp; &nbsp;| Windows Baltic&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| cp1257_general_ci&nbsp; &nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| binary&nbsp; &nbsp;| Binary pseudo charset&nbsp; &nbsp;&nbsp; &nbsp; | binary&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| geostd8&nbsp;&nbsp;| GEOSTD8 Georgian&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| geostd8_general_ci&nbsp;&nbsp;| 1&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| cp932&nbsp; &nbsp; | SJIS for Windows Japanese&nbsp; &nbsp;| cp932_japanese_ci&nbsp; &nbsp;| 2&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| eucjpms&nbsp;&nbsp;| UJIS for Windows Japanese&nbsp; &nbsp;| eucjpms_japanese_ci | 3&nbsp; &nbsp;&nbsp; &nbsp;|<br />
+----------+-----------------------------+---------------------+--------+<br />
36 rows in set (0.02 sec)<br />
<br />
<br />
MySQL 4.1的字符集支持(Character Set Support)有两个方面：字符集(Character set)和排序方式(Collation)。对于字符集的支持细化到四个层次: 服务器(server)，数据库(database)，数据表(table)和连接(connection)。<br />
查看系统的字符集和排序方式的设定可以通过下面的两条命令：<br />
<br />
mysql&gt; SHOW VARIABLES LIKE 'character_set_%';<br />
+--------------------------+-------------------------------------------+<br />
| Variable_name&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| Value&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; |<br />
+--------------------------+-------------------------------------------+<br />
| character_set_client&nbsp; &nbsp;&nbsp;&nbsp;| latin1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| character_set_connection | latin1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| character_set_database&nbsp; &nbsp;| latin1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| character_set_filesystem | binary&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| character_set_results&nbsp; &nbsp; | latin1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| character_set_server&nbsp; &nbsp;&nbsp;&nbsp;| latin1&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;|<br />
| character_set_system&nbsp; &nbsp;&nbsp;&nbsp;| utf8&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;|<br />
| character_sets_dir&nbsp; &nbsp;&nbsp; &nbsp; | D:\MySQL\MySQL Server 5.0\share\charsets\ |<br />
+--------------------------+-------------------------------------------+<br />
8 rows in set (0.06 sec)<br />
<br />
mysql&gt; SHOW VARIABLES LIKE 'collation_%';<br />
+----------------------+-------------------+<br />
| Variable_name&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;| Value&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; |<br />
+----------------------+-------------------+<br />
| collation_connection | latin1_swedish_ci |<br />
| collation_database&nbsp; &nbsp;| latin1_swedish_ci |<br />
| collation_server&nbsp; &nbsp;&nbsp;&nbsp;| latin1_swedish_ci |<br />
+----------------------+-------------------+<br />
3 rows in set (0.02 sec)<br />
<br />
上面列出的值就是系统的默认值。latin1默认校对规则是latin1_swedish_ci，默认是latin1的瑞典语排序方式.<br />
为什么呢默认会是latin1_swedish_ci呢,追溯一下mysql历史很容易发现<br />
<br />
1979年，一家瑞典公司Tcx欲开发一个快速的多线程、多用户数据库系统。Tcx 公司起初想利用mSQL和他们自己的快速低级例程 (Indexed Sequential Access Method，ISAM)去连接数据库表，然而，在一些测试以后得出结论：mSQL对其需求来说不够快速和灵活。这就产生了一个连接器数据库的新SQL接口，它使用几乎和mSQL一样的API接口。这个API被设计成可以使那些由mSQL而写的第三方代码更容易地移植到MySQL。 <br />
<br />
相信如果mysql是中国开发的，那么汉语也是默认编码了<br />
<br />
当然我们也可以自己需要修改mysql的默认字符集<br />
在mysql配置文档my.ini，找到如下两句：<br />
<br />
[mysql]<br />
<br />
default-character-set=latin1<br />
<br />
和<br />
<br />
# created and no character set is defined<br />
default-character-set=latin1<br />
<br />
修改后面的值就可以。<br />
<br />
这里不建议改，仍保留默认值<br />
也就是说启动 mysql时，如果没指定指定一个默认的的字符集，这个值继承自配置文件中的； <br />
此时 character_set_server 被设定为这个默认的字符集； 当创建一个新的数据库时，<br />
除非明确指定，这个数据库的字符集被缺省设定为 character_set_server； 当选定了一个数据库时，<br />
character_set_database 被设定为这个数据库默认的字符集； 在这个数据库里创建一张表时，<br />
表默认的字符集被设定为 character_set_database，也就是这个数据库默认的字符集； <br />
当在表内设置一栏时，除非明确指定，否则此栏缺省的字符集就是表默认的字符集。<br />
<br />
这样问题就随之而来了，假如一数据库是gbk编码。如果访问数据库时没指定其的字符集是gbk。<br />
那么这个值将继承系统的latin1，这样就做成mysql中文乱码。<br />
<br />
<strong><font size="6"><font color="red">乱码解决方法</font></font></strong><br />
<br />
要解决乱码问题，首先必须弄清楚自己数据库用什么编码。如果没有指明，将是默认的latin1。<br />
我们用得最多的应该是这3种字符集 gb2312，gbk，utf8。<br />
<br />
那么我们如何去指定数据库的字符集呢？下面也gbk为例<br />
<br />
<font size="4">【在MySQL Command Line Client创建数据库 】</font><br />
<br />
mysql&gt; CREATE TABLE `mysqlcode` (<br />
&nbsp; &nbsp; -&gt; `id` TINYINT( 255 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,<br />
&nbsp; &nbsp; -&gt; `content` VARCHAR( 255 ) NOT NULL<br />
&nbsp; &nbsp; -&gt; ) TYPE = MYISAM CHARACTER SET gbk COLLATE gbk_chinese_ci;<br />
Query OK, 0 rows affected, 1 warning (0.03 sec)<br />
<br />
mysql&gt; desc mysqlcode;<br />
+---------+-----------------------+------+-----+---------+----------------+<br />
| Field&nbsp; &nbsp;| Type&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| Null | Key | Default | Extra&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; |<br />
+---------+-----------------------+------+-----+---------+----------------+<br />
| id&nbsp; &nbsp;&nbsp; &nbsp;| tinyint(255) unsigned | NO&nbsp; &nbsp;| PRI |&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;| auto_increment |<br />
| content | varchar(255)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; | NO&nbsp; &nbsp;|&nbsp; &nbsp;&nbsp;&nbsp;|&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;|&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; |<br />
+---------+-----------------------+------+-----+---------+----------------+<br />
2 rows in set (0.02 sec)<br />
<br />
其中后面的TYPE = MYISAM CHARACTER SET gbk COLLATE gbk_chinese_ci;<br />
就是指定数据库的字符集，COLLATE (校勘)，让mysql同时支持多种编码的数据库。<br />
<br />
当然我们也可以通过如下指令修改数据库的字符集<br />
alter database da_name default character set 'charset'.<br />
<br />
客户端以 gbk格式发送 ，可以采用下述配置:<br />
<br />
SET character_set_client='gbk'<br />
SET character_set_connection='gbk'<br />
SET character_set_results='gbk'<br />
<br />
这个配置就等价于 SET NAMES 'gbk'。<br />
<br />
现在对刚才创建的数据库操作<br />
<br />
mysql&gt; use test;<br />
Database changed<br />
<br />
mysql&gt; insert into mysqlcode values(null,'php爱好者');<br />
ERROR 1406 (22001): Data too long for column 'content' at row 1<br />
<br />
没有指定字符集为gbk，插入时出错<br />
<br />
mysql&gt; set names 'gbk';<br />
Query OK, 0 rows affected (0.02 sec)<br />
<br />
指定字符集为 gbk<br />
<br />
mysql&gt; insert into mysqlcode values(null,'php爱好者');<br />
Query OK, 1 row affected (0.00 sec)<br />
<br />
插入成功<br />
</p>
<div class="content">
<div class="adgg"><iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-4234177103003112&amp;dt=1214299400406&amp;lmt=1214299400&amp;prev_slotnames=0351698883&amp;output=html&amp;slotname=1613388755&amp;correlator=1214299400218&amp;url=http%3A%2F%2Fwww.souzz.net%2Fhtml%2Fedu%2Fphp%2Fphp3%2F21652_2.html&amp;ref=http%3A%2F%2Fwww.souzz.net%2Fhtml%2Fedu%2Fphp%2Fphp3%2F21652.html&amp;frm=0&amp;cc=100&amp;ga_vid=735870206908519400.1214299400&amp;ga_sid=1214299400&amp;ga_hid=628939378&amp;flash=9.0.124.0&amp;u_h=1024&amp;u_w=1280&amp;u_ah=994&amp;u_aw=1280&amp;u_cd=32&amp;u_tz=480&amp;u_his=1&amp;u_java=true" frameborder="0" width="300" scrolling="no" height="250" allowTransparency></iframe></div>
<p>&nbsp;</p>
<p><br />
mysql&gt; select * from mysqlcode;<br />
+----+-----------+<br />
| id | content&nbsp; &nbsp;|<br />
+----+-----------+<br />
| 1&nbsp;&nbsp;| php爱好着 |<br />
+----+-----------+<br />
1 row in set (0.00 sec)<br />
<br />
在没有指定字符集gbk时读取也会出现乱码，如下<br />
<br />
mysql&gt; select * from mysqlcode;<br />
+----+---------+<br />
| id | content |<br />
+----+---------+<br />
| 1&nbsp;&nbsp;| php???&nbsp;&nbsp;|<br />
+----+---------+<br />
1 row in set (0.00 sec)<br />
<br />
<br />
<font size="4">【在phpmyadmin创建数据库,并指定字符集】</font><br />
<br />
<img onmousewheel="return imgzoom(this);" onmouseover="if(this.width  alt="" />screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/ddimg/uploadimg/20061129/1018560.jpg');}" alt="" src="http://www.souzz.net/ddimg/uploadimg/20061129/1018560.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0><br />
<br />
表类型根据自己需要选，这里选MyISAM(支持全文检索);<br />
整理选择 gbk_chinese_ci 也就是gbk字符集<br />
gbk_bin 简体中文, 二进制。gbk_chinese_ci 简体中文, 不区分大小写。<br />
<br />
在刚才创建的数据库插入数据库<br />
<br />
<img onmousewheel="return imgzoom(this);" onmouseover="if(this.width  alt="" />screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/ddimg/uploadimg/20061129/1018561.jpg');}" alt="" src="http://www.souzz.net/ddimg/uploadimg/20061129/1018561.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0><br />
<br />
再浏览时发现是乱码<br />
<img onmousewheel="return imgzoom(this);" onmouseover="if(this.width  alt="" />screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/ddimg/uploadimg/20061129/1018562.jpg');}" alt="" src="http://www.souzz.net/ddimg/uploadimg/20061129/1018562.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0><br />
<br />
为什么呢？是因为数据库为gbk字符集，而我们操作时没有指定为gbk<br />
回到数据库首页<br />
<img onmousewheel="return imgzoom(this);" onmouseover="if(this.width  alt="" />screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/ddimg/uploadimg/20061129/1018563.jpg');}" alt="" src="http://www.souzz.net/ddimg/uploadimg/20061129/1018563.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0><br />
<br />
可以看到 mysql 连接校对默认的latin1_bin。我们将其改为gbk_chinese_ci<br />
<img onmousewheel="return imgzoom(this);" onmouseover="if(this.width  alt="" />screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/ddimg/uploadimg/20061129/1018564.jpg');}" alt="" src="http://www.souzz.net/ddimg/uploadimg/20061129/1018564.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0><br />
<br />
再插入一条数据。看，这条已经正常了<br />
<img onmousewheel="return imgzoom(this);" onmouseover="if(this.width  alt="" />screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/ddimg/uploadimg/20061129/1018565.jpg');}" alt="" src="http://www.souzz.net/ddimg/uploadimg/20061129/1018565.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0><br />
<br />
更多phpmyadmin乱码问题请参考本论坛的<br />
<a href="http://www.phpfans.net/bbs/viewthread.php?tid=146&amp;extra=page%3D1" target="_blank">http://www.phpfans.net/bbs/viewthread.php?tid=146&amp;extra=page%3D1</a><br />
php爱好者站 <a href="http://www.phpfans.net/" target="_blank">http://www.phpfans.net/</a><br />
<br />
<font size="4">【解决php读取数据库乱码】</font><br />
<br />
仍以数据库mysqlcode为例<br />
</p>
<div class="smalltxt" style="font-weight: bold; margin-left: 2em; margin-right: 2em">
<div style="float: left">CODE:</div>
<div style="float: right; text-align: right"><a class="smalltxt" onclick="copycode(findobj('phpcode0'));" href="http://www.phpfans.net/bbs/viewthread.php?tid=417&amp;extra=page%3D1#">[Copy to clipboard]</a></div>
</div>
<div id="phpcode0" style="clear: both; border-right: #f1f1f1 1px solid; padding-right: 10px; border-top: #f1f1f1 1px solid; padding-left: 10px; background: #f1f1f1; padding-bottom: 10px; margin: 3px 2em 2em; border-left: #f1f1f1 1px solid; word-break: break-all; padding-top: 5px; border-bottom: #f1f1f1 1px solid"><code><font color="#000000"><font color="#0000bb"></font><font face="新宋体" color="#007700">&lt;?</font><font face="新宋体"><font color="#0000bb">php&nbsp; <br />
$conn&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000bb">mysql_connect</font><font color="#007700">(</font><font color="#dd0000">"localhost"</font><font color="#007700">,</font><font color="#dd0000">"root"</font><font color="#007700">,</font><font color="#dd0000">""</font></font><font face="新宋体"><font color="#007700">); <br />
</font><font color="#0000bb">mysql_query</font><font color="#007700">(</font><font color="#dd0000">"set&nbsp;names&nbsp;'gbk'"</font><font color="#007700">);</font></font><font face="新宋体"><font color="#ff8000">//这就是指定数据库字符集，一般放在连接数据库后面就系了 <br />
</font><font color="#0000bb">mysql_select_db</font><font color="#007700">(</font><font color="#dd0000">"test"</font></font><font face="新宋体"><font color="#007700">); <br />
<br />
</font><font color="#0000bb">$sql&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#dd0000">"select&nbsp;*&nbsp;from&nbsp;mysqlcode"</font></font><font face="新宋体"><font color="#007700">; <br />
</font><font color="#0000bb">$result&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000bb">mysql_query</font><font color="#007700">(</font><font color="#0000bb">$sql</font><font color="#007700">,</font><font color="#0000bb">$conn</font></font><font face="新宋体"><font color="#007700">); <br />
<br />
?&gt; <br />
&lt;</font><font color="#0000bb">head</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&lt;</font><font color="#0000bb">meta&nbsp;http</font><font color="#007700">-</font><font color="#0000bb">equiv</font><font color="#007700">=</font><font color="#dd0000">"Content-Type"&nbsp;</font><font color="#0000bb">content</font><font color="#007700">=</font><font color="#dd0000">"text/html;&nbsp;charset=gb2312"&nbsp;</font></font><font face="新宋体"><font color="#007700">/&gt; <br />
&lt;</font><font color="#0000bb">title</font><font color="#007700">&gt;</font><font color="#0000bb">mysql&nbsp;字符编码</font><font color="#007700">&lt;/</font><font color="#0000bb">title</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&lt;/</font><font color="#0000bb">head</font></font><font face="新宋体"><font color="#007700">&gt; <br />
<br />
&lt;</font><font color="#0000bb">body</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&lt;</font><font color="#0000bb">table&nbsp;width</font><font color="#007700">=</font><font color="#dd0000">"300"&nbsp;</font><font color="#0000bb">height</font><font color="#007700">=</font><font color="#dd0000">"32"&nbsp;</font><font color="#0000bb">border</font><font color="#007700">=</font><font color="#dd0000">"1"&nbsp;</font><font color="#0000bb">align</font><font color="#007700">=</font><font color="#dd0000">"center"&nbsp;</font><font color="#0000bb">cellpadding</font><font color="#007700">=</font><font color="#dd0000">"0"&nbsp;</font><font color="#0000bb">cellspacing</font><font color="#007700">=</font><font color="#dd0000">"0"</font></font><font face="新宋体"><font color="#007700">&gt;&nbsp; <br />
&nbsp;&nbsp;&lt;</font><font color="#0000bb">tr</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;</font><font color="#0000bb">td&nbsp;width</font><font color="#007700">=</font><font color="#dd0000">"71"&nbsp;</font><font color="#0000bb">align</font><font color="#007700">=</font><font color="#dd0000">"center"</font><font color="#007700">&gt;</font><font color="#0000bb">id</font><font color="#007700">&lt;/</font><font color="#0000bb">td</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;</font><font color="#0000bb">td&nbsp;width</font><font color="#007700">=</font><font color="#dd0000">"229"&nbsp;</font><font color="#0000bb">align</font><font color="#007700">=</font><font color="#dd0000">"center"</font><font color="#007700">&gt;</font><font color="#0000bb">内容</font><font color="#007700">&lt;/</font><font color="#0000bb">td</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&nbsp;&nbsp;&lt;/</font><font color="#0000bb">tr</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&nbsp;&lt;?</font><font color="#0000bb">php&nbsp;</font><font color="#007700">while(</font><font color="#0000bb">$row&nbsp;</font><font color="#007700">=&nbsp;</font><font color="#0000bb">mysql_fetch_assoc</font><font color="#007700">(</font><font color="#0000bb">$result</font></font><font face="新宋体" color="#007700">)){ <br />
&nbsp;echo&nbsp;</font><font face="新宋体"><font color="#dd0000">"&nbsp;&nbsp; <br />
&nbsp;&lt;tr&gt; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&nbsp;align=\"center\"&gt;"</font><font color="#007700">.</font><font color="#0000bb">$row</font><font color="#007700">[</font><font color="#dd0000">'id'</font><font color="#007700">].</font></font><font face="新宋体"><font color="#dd0000">"&lt;/td&gt; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;td&gt;"</font><font color="#007700">.</font><font color="#0000bb">$row</font><font color="#007700">[</font><font color="#dd0000">'content'</font><font color="#007700">].</font></font><font face="新宋体" color="#dd0000">"&lt;/td&gt; <br />
&nbsp;&nbsp;&lt;/tr&gt;"</font><font face="新宋体"><font color="#007700">; <br />
}?&gt;&nbsp;&nbsp; <br />
&lt;/</font><font color="#0000bb">table</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&lt;/</font><font color="#0000bb">body</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&lt;/</font><font color="#0000bb">html</font></font><font face="新宋体"><font color="#007700">&gt; <br />
&lt;?</font><font color="#0000bb">php&nbsp;mysql_free_result</font><font color="#007700">(</font><font color="#0000bb">$result</font><font color="#007700">);?&gt;&nbsp;</font><br />
</font></font></code></div>
如果我们将mysql_query("set names 'gbk'");注释掉，肯定时乱码<br />
<img onmousewheel="return imgzoom(this);" onmouseover="if(this.width  alt="" />screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/ddimg/uploadimg/20061129/1018566.jpg');}" alt="" src="http://www.souzz.net/ddimg/uploadimg/20061129/1018566.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0><br />
<br />
加上那句又正常了<br />
<img onmousewheel="return imgzoom(this);" onmouseover="if(this.width  alt="" />screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('/ddimg/uploadimg/20061129/1018567.jpg');}" alt="" src="http://www.souzz.net/ddimg/uploadimg/20061129/1018567.jpg" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" border=0><br />
<br />
一句话<br />
<font color="red">你数据库用什么编码，在对数据库操作之前就set names '你的编码';<