﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Free mind-随笔分类-3. Web</title><link>http://www.blogjava.net/morphis/category/20817.html</link><description>Be fresh and eager every morning, and tired and satisfied every night.</description><language>zh-cn</language><lastBuildDate>Wed, 31 Oct 2007 10:42:36 GMT</lastBuildDate><pubDate>Wed, 31 Oct 2007 10:42:36 GMT</pubDate><ttl>60</ttl><item><title>[转] Usefull Sql</title><link>http://www.blogjava.net/morphis/archive/2007/10/30/156998.html</link><dc:creator>morphis</dc:creator><author>morphis</author><pubDate>Tue, 30 Oct 2007 09:40:00 GMT</pubDate><guid>http://www.blogjava.net/morphis/archive/2007/10/30/156998.html</guid><wfw:comment>http://www.blogjava.net/morphis/comments/156998.html</wfw:comment><comments>http://www.blogjava.net/morphis/archive/2007/10/30/156998.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/morphis/comments/commentRss/156998.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/morphis/services/trackbacks/156998.html</trackback:ping><description><![CDATA[<p>SQL语句先前写的时候，很容易把一些特殊的用法忘记，我特此整理了一下SQL语句操作。<br />
一、基础<br />
1、说明：创建数据库<br />
CREATE DATABASE database-name <br />
2、说明：删除数据库<br />
drop database dbname<br />
3、说明：备份sql server<br />
--- 创建 备份数据的 device<br />
USE master<br />
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'<br />
--- 开始 备份<br />
BACKUP DATABASE pubs TO testBack <br />
4、说明：创建新表<br />
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)<br />
根据已有的表创建新表： <br />
A：create table tab_new like tab_old (使用旧表创建新表)<br />
B：create table tab_new as select col1,col2... from tab_old definition only<br />
5、说明：删除新表<br />
drop table tabname <br />
6、说明：增加一个列<br />
Alter table tabname add column col type<br />
注：列增加后将不能删除。DB2中列加上后数据类型也不能改变，唯一能改变的是增加varchar类型的长度。<br />
7、说明：添加主键： Alter table tabname add primary key(col) <br />
说明：删除主键： Alter table tabname drop primary key(col) <br />
8、说明：创建索引：create [unique] index idxname on tabname(col....) <br />
删除索引：drop index idxname<br />
注：索引是不可更改的，想更改必须删除重新建。<br />
9、说明：创建视图：create view viewname as select statement <br />
删除视图：drop view viewname<br />
10、说明：几个简单的基本的sql语句<br />
选择：select * from table1 where 范围<br />
插入：insert into table1(field1,field2) values(value1,value2)<br />
删除：delete from table1 where 范围<br />
更新：update table1 set field1=value1 where 范围<br />
查找：select * from table1 where field1 like '%value1%' ---like的语法很精妙，查资料!<br />
排序：select * from table1 order by field1,field2 [desc]<br />
总数：select count as totalcount from table1<br />
求和：select sum(field1) as sumvalue from table1<br />
平均：select avg(field1) as avgvalue from table1<br />
最大：select max(field1) as maxvalue from table1<br />
最小：select min(field1) as minvalue from table1<br />
11、说明：几个高级查询运算词<br />
A： UNION 运算符 <br />
UNION 运算符通过组合其他两个结果表（例如 TABLE1 和 TABLE2）并消去表中任何重复行而派生出一个结果表。当 ALL 随 UNION 一起使用时（即 UNION ALL），不消除重复行。两种情况下，派生表的每一行不是来自 TABLE1 就是来自 TABLE2。 <br />
B： EXCEPT 运算符 <br />
EXCEPT 运算符通过包括所有在 TABLE1 中但不在 TABLE2 中的行并消除所有重复行而派生出一个结果表。当 ALL 随 EXCEPT 一起使用时 (EXCEPT ALL)，不消除重复行。 <br />
C： INTERSECT 运算符<br />
INTERSECT 运算符通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表。当 ALL 随 INTERSECT 一起使用时 (INTERSECT ALL)，不消除重复行。 <br />
注：使用运算词的几个查询结果行必须是一致的。 <br />
12、说明：使用外连接 <br />
A、left outer join： <br />
左外连接（左连接）：结果集几包括连接表的匹配行，也包括左连接表的所有行。 <br />
SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c<br />
B：right outer join: <br />
右外连接(右连接)：结果集既包括连接表的匹配连接行，也包括右连接表的所有行。 <br />
C：full outer join： <br />
全外连接：不仅包括符号连接表的匹配行，还包括两个连接表中的所有记录。<br />
二、提升<br />
1、说明：复制表(只复制结构,源表名：a 新表名：b) (Access可用)<br />
法一：select * into b from a where 1&lt;&gt;1<br />
法二：select top 0 * into b from a<br />
2、说明：拷贝表(拷贝数据,源表名：a 目标表名：b) (Access可用)<br />
insert into b(a, b, c) select d,e,f from b;<br />
3、说明：跨数据库之间表的拷贝(具体数据使用绝对路径) (Access可用)<br />
insert into b(a, b, c) select d,e,f from b in '具体数据库' where 条件<br />
例子：..from b in '"&amp;Server.MapPath(".")&amp;"\data.mdb" &amp;"' where..<br />
4、说明：子查询(表名1：a 表名2：b)<br />
select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a where a IN (1,2,3)<br />
5、说明：显示文章、提交人和最后回复时间<br />
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b<br />
6、说明：外连接查询(表名1：a 表名2：b)<br />
select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c<br />
7、说明：在线视图查询(表名1：a )<br />
select * from (SELECT a,b,c FROM a) T where t.a &gt; 1;<br />
8、说明：between的用法,between限制查询数据范围时包括了边界值,not between不包括<br />
select * from table1 where time between time1 and time2<br />
select a,b,c, from table1 where a not between 数值1 and 数值2<br />
9、说明：in 的使用方法<br />
select * from table1 where a [not] in ('值1','值2','值4','值6')<br />
10、说明：两张关联表，删除主表中已经在副表中没有的信息 <br />
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )<br />
11、说明：四表联查问题：<br />
select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....<br />
12、说明：日程安排提前五分钟提醒 <br />
SQL: select * from 日程安排 where datediff('minute',f开始时间,getdate())&gt;5<br />
13、说明：一条sql 语句搞定数据库分页<br />
select top 10 b.* from (select top 20 主键字段,排序字段 from 表名 order by 排序字段 desc) a,表名 b where b.主键字段 = a.主键字段 order by a.排序字段<br />
14、说明：前10条记录<br />
select top 10 * form table1 where 范围<br />
15、说明：选择在每一组b值相同的数据中对应的a最大的记录的所有信息(类似这样的用法可以用于论坛每月排行榜,每月热销产品分析,按科目成绩排名,等等.)<br />
select a,b,c from tablename ta where a=(select max(a) from tablename tb where tb.b=ta.b)<br />
16、说明：包括所有在 TableA 中但不在 TableB和TableC 中的行并消除所有重复行而派生出一个结果表<br />
(select a from tableA ) except (select a from tableB) except (select a from tableC)<br />
17、说明：随机取出10条数据<br />
select top 10 * from tablename order by newid()<br />
18、说明：随机选择记录<br />
select newid()<br />
19、说明：删除重复记录<br />
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)<br />
20、说明：列出数据库里所有的表名<br />
select name from sysobjects where type='U' <br />
21、说明：列出表里的所有的<br />
select name from syscolumns where id=object_id('TableName')<br />
22、说明：列示type、vender、pcs字段，以type字段排列，case可以方便地实现多重选择，类似select 中的case。<br />
select type,sum(case vender when 'A' then pcs else 0 end),sum(case vender when 'C' then pcs else 0 end),sum(case vender when 'B' then pcs else 0 end) FROM tablename group by type<br />
显示结果：<br />
type vender pcs<br />
电脑 A 1<br />
电脑 A 1<br />
光盘 B 2<br />
光盘 A 2<br />
手机 B 3<br />
手机 C 3<br />
23、说明：初始化表table1<br />
TRUNCATE TABLE table1<br />
24、说明：选择从10到15的记录<br />
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc<br />
三、技巧<br />
1、1=1，1=2的使用，在SQL语句组合时用的较多<br />
"where 1=1" 是表示选择全部&nbsp;&nbsp; "where 1=2"全部不选，<br />
如：<br />
if @strWhere !='' <br />
begin<br />
set @strSQL = 'select count(*) as Total from [' + @tblName + '] where ' + @strWhere <br />
end<br />
else <br />
begin<br />
set @strSQL = 'select count(*) as Total from [' + @tblName + ']' <br />
end <br />
我们可以直接写成<br />
set @strSQL = 'select count(*) as Total from [' + @tblName + '] where 1=1 安定 '+ @strWhere <br />
2、收缩数据库<br />
--重建索引<br />
DBCC REINDEX<br />
DBCC INDEXDEFRAG<br />
--收缩数据和日志<br />
DBCC SHRINKDB<br />
DBCC SHRINKFILE<br />
3、压缩数据库<br />
dbcc shrinkdatabase(dbname)<br />
4、转移数据库给新用户以已存在用户权限<br />
exec sp_change_users_login 'update_one','newname','oldname'<br />
go<br />
5、检查备份集<br />
RESTORE VERIFYONLY from disk='E:\dvbbs.bak'<br />
6、修复数据库<br />
ALTER DATABASE [dvbbs] SET SINGLE_USER<br />
GO<br />
DBCC CHECKDB('dvbbs',repair_allow_data_loss) WITH TABLOCK<br />
GO<br />
ALTER DATABASE [dvbbs] SET MULTI_USER<br />
GO<br />
7、日志清除<br />
SET NOCOUNT ON<br />
DECLARE @LogicalFileName sysname,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @MaxMinutes INT,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @NewSize INT</p>
<p>USE&nbsp;&nbsp;&nbsp;&nbsp; tablename&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- 要操作的数据库名<br />
SELECT&nbsp; @LogicalFileName = 'tablename_log',&nbsp; -- 日志文件名<br />
@MaxMinutes = 10,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- Limit on time allowed to wrap log.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @NewSize = 1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- 你想设定的日志文件的大小(M)<br />
-- Setup / initialize<br />
DECLARE @OriginalSize int<br />
SELECT @OriginalSize = size <br />
&nbsp; FROM sysfiles<br />
&nbsp; WHERE name = @LogicalFileName<br />
SELECT 'Original Size of ' + db_name() + ' LOG is ' + <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CONVERT(VARCHAR(30),@OriginalSize) + ' 8K pages or ' + <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CONVERT(VARCHAR(30),(@OriginalSize*8/1024)) + 'MB'<br />
&nbsp; FROM sysfiles<br />
&nbsp; WHERE name = @LogicalFileName<br />
CREATE TABLE DummyTrans<br />
&nbsp; (DummyColumn char (8000) not null)</p>
<p>DECLARE @Counter&nbsp;&nbsp; INT,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @StartTime DATETIME,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @TruncLog&nbsp; VARCHAR(255)<br />
SELECT&nbsp; @StartTime = GETDATE(),<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; @TruncLog = 'BACKUP LOG ' + db_name() + ' WITH TRUNCATE_ONLY'<br />
DBCC SHRINKFILE (@LogicalFileName, @NewSize)<br />
EXEC (@TruncLog)<br />
-- Wrap the log if necessary.<br />
WHILE&nbsp;&nbsp;&nbsp;&nbsp; @MaxMinutes &gt; DATEDIFF (mi, @StartTime, GETDATE()) -- time has not expired<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName)&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND (@OriginalSize * 8 /1024) &gt; @NewSize&nbsp; <br />
&nbsp; BEGIN -- Outer loop.<br />
&nbsp;&nbsp;&nbsp; SELECT @Counter = 0<br />
&nbsp;&nbsp;&nbsp; WHILE&nbsp; ((@Counter &lt; @OriginalSize / 16) AND (@Counter &lt; 50000))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BEGIN -- update<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; INSERT DummyTrans VALUES ('Fill Log')&nbsp; <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DELETE DummyTrans<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SELECT @Counter = @Counter + 1<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; EXEC (@TruncLog)&nbsp; <br />
&nbsp; END&nbsp;&nbsp; <br />
SELECT 'Final Size of ' + db_name() + ' LOG is ' +<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CONVERT(VARCHAR(30),size) + ' 8K pages or ' + <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CONVERT(VARCHAR(30),(size*8/1024)) + 'MB'<br />
&nbsp; FROM sysfiles <br />
&nbsp; WHERE name = @LogicalFileName<br />
DROP TABLE DummyTrans<br />
SET NOCOUNT OFF <br />
8、说明：更改某个表<br />
exec sp_changeobjectowner 'tablename','dbo'<br />
9、存储更改全部表<br />
CREATE PROCEDURE dbo.User_ChangeObjectOwnerBatch<br />
&nbsp;@OldOwner as NVARCHAR(128),<br />
&nbsp;@NewOwner as NVARCHAR(128)<br />
AS<br />
DECLARE @Name&nbsp;&nbsp; as NVARCHAR(128)<br />
DECLARE @Owner&nbsp; as NVARCHAR(128)<br />
DECLARE @OwnerName&nbsp; as NVARCHAR(128)<br />
DECLARE curObject CURSOR FOR <br />
&nbsp;select 'Name'&nbsp;&nbsp; = name,<br />
&nbsp; 'Owner'&nbsp;&nbsp; = user_name(uid)<br />
&nbsp;from sysobjects<br />
&nbsp;where user_name(uid)=@OldOwner<br />
&nbsp;order by name<br />
OPEN&nbsp; curObject<br />
FETCH NEXT FROM curObject INTO @Name, @Owner<br />
WHILE(@@FETCH_STATUS=0)<br />
BEGIN&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;if @Owner=@OldOwner <br />
&nbsp;begin<br />
&nbsp; set @OwnerName = @OldOwner + '.' + rtrim(@Name)<br />
&nbsp; exec sp_changeobjectowner @OwnerName, @NewOwner<br />
&nbsp;end<br />
-- select @name,@NewOwner,@OldOwner<br />
&nbsp;FETCH NEXT FROM curObject INTO @Name, @Owner<br />
END<br />
close curObject<br />
deallocate curObject<br />
GO</p>
<p>10、SQL SERVER中直接循环写入数据<br />
declare @i int<br />
set @i=1<br />
while @i&lt;30<br />
begin<br />
&nbsp;&nbsp; insert into test (userid) values(@i)<br />
&nbsp;&nbsp; set @i=@i+1<br />
end<br />
小记存储过程中经常用到的本周，本月，本年函数 <br />
Dateadd(wk,datediff(wk,0,getdate()),-1) <br />
Dateadd(wk,datediff(wk,0,getdate()),6) <br />
Dateadd(mm,datediff(mm,0,getdate()),0) <br />
Dateadd(ms,-3,dateadd(mm,datediff(m,0,getdate())+1,0)) <br />
Dateadd(yy,datediff(yy,0,getdate()),0) <br />
Dateadd(ms,-3,DATEADD(yy, DATEDIFF(yy,0,getdate())+1, 0)) <br />
上面的SQL代码只是一个时间段 <br />
Dateadd(wk,datediff(wk,0,getdate()),-1) <br />
Dateadd(wk,datediff(wk,0,getdate()),6) <br />
就是表示本周时间段. <br />
下面的SQL的条件部分,就是查询时间段在本周范围内的: <br />
Where Time BETWEEN Dateadd(wk,datediff(wk,0,getdate()),-1) AND Dateadd(wk,datediff(wk,0,getdate()),6) <br />
而在存储过程中 <br />
select @begintime = Dateadd(wk,datediff(wk,0,getdate()),-1) <br />
select @endtime = Dateadd(wk,datediff(wk,0,getdate()),6)</p>
<img src ="http://www.blogjava.net/morphis/aggbug/156998.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/morphis/" target="_blank">morphis</a> 2007-10-30 17:40 <a href="http://www.blogjava.net/morphis/archive/2007/10/30/156998.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ruby on Rails学习 (一) </title><link>http://www.blogjava.net/morphis/archive/2007/03/24/106144.html</link><dc:creator>morphis</dc:creator><author>morphis</author><pubDate>Sat, 24 Mar 2007 15:08:00 GMT</pubDate><guid>http://www.blogjava.net/morphis/archive/2007/03/24/106144.html</guid><wfw:comment>http://www.blogjava.net/morphis/comments/106144.html</wfw:comment><comments>http://www.blogjava.net/morphis/archive/2007/03/24/106144.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/morphis/comments/commentRss/106144.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/morphis/services/trackbacks/106144.html</trackback:ping><description><![CDATA[
		<div class="postTitle">　　“从书籍销售情况就可以看出那种技术是当前最流行的技术，具体的数据我不太记得了，只记得JAVA书籍的销售量是增长了4%，C#增长了16%，Python增长了20%，Perl下降4%，而Ruby书籍的销售量增长了1552%（没错，我没少打小数点）”，<a href="http://radar.oreilly.com/archives/2005/12/ruby_book_sales_surpass_python.html">原文在这</a>。虽然Java书籍销售量基数肯定是远远大于Ruby书籍，但是如此之大的增长量还是引起了我的好奇，到底是什么东西能使相关科技书以这么大销售量增长?<br /></div>
		<div class="postText">
				<h2>
						<h3>什么是Ruby on Rails</h3>
				</h2>
				<div>让我们先来看一张图片：</div>
				<div> </div>
				<div>
				</div>
				<div> <img alt="" src="http://static.flickr.com/28/55632873_4c0eba44ec.jpg?v=0" /></div>
				<div>看完这张图片，我心里充满疑惑，难道Ruby + Rails真的能够有这么好吗？</div>
				<div>
						<div> </div>
						<div>心里有这么几个疑问：</div>
						<div>１、Ruby是谁开发的？</div>
						<div>２、Ruby是什么？</div>
						<div>３、Rails是什么？</div>
						<div>４、Ruby on Rails与目前已经有的开发语言相比有什么优点？为什么要使用它？</div>
						<div>５、Ruby on Rails稳定吗？效率高吗？能够承受大数据量的访问吗？</div>
						<div>６、Ruby on Rails有长远的发展前景吗？</div>
						<div> </div>
						<div>让我们一个一个的解开这些疑问：</div>
						<div>１、<i>松本行弘"Matz"(Matsumoto Yukihiro)</i><i>是Ruby</i><i>语言的发明人，他从1993</i><i>年起便开始着手Ruby</i><i>的研发工作。他一直想发明一种语言，使你既能进行高效开发又能享受编程的快乐。1993</i><i>年2</i><i>月24</i><i>日Ruby</i><i>诞生了，1995</i><i>年12</i><i>月Matz</i><i>推出了Ruby</i><i>的第一个版本Ruby 0.95</i><i>。不久Ruby</i><i>便凭借其独特的魅力横扫日本，相信在不久的将来，Ruby</i><i>将走向世界。</i>Ruby是日本人发明的，这点让我很不是滋味，人也是很奇怪的，美国，欧洲比我们强还能接受，而日本比我们强我就….</div>
						<div align="left">２、Ruby是一种有着超级清晰语法的纯面向对象的编程语言，它能够让编程变得有趣和优雅（这点在后面的内容中确实得到印证）。Ruby成功的组合了Smalltalk的优雅以及Python的易用性，还有Perl的实用主义。Ruby起源于９０年代的日本，在过去的几年时间里随着更多的英语资料的出现变得更加的流行。</div>
						<div align="left">３、Rails是一个用来开发数据库后台的WEB应用的开源框架。</div>
						<div>４、到目前为止我发现Ruby on Rails最大的优点就是在于简单！RoR的核心思想就是“更少的编程，更简单的配置！”</div>
						<ul>
								<li>
										<div align="left">安装和配置非常简单，不象Java需要安装运行环境，安装应用服务器，然后再进行一大堆的配置。在安装上Ruby和Perl很象，只需要装一个简单的解释环境就可以了（和Perl很象的地方很多，例如正则表达式的支持）。RoR避免了繁杂的XML配置文件，一个Rails应用程序只需要简单编程就可以通过影射和发现配置好所有的东西。你的应用程序和数据库里已经包含了所有Rails需要的东西。</div>
								</li>
								<li>
										<div align="left">编码简单，很多代码都是可以自动生成，可以自动生成MVC，可以自动生成框架、Web服务。甚至你只要写上一行代码就可以实现以前使用Java上百行代码的工作量，比其他开发工具速度快１０倍！。当然越少的编程量就意味着越少的bug。</div>
								</li>
						</ul>
						<div>５、关于稳定性目前还没有很全面的数据，暂时还不太清楚。关于效率，从相关的资料上可以看到：<a href="http://www.duduwolf.com/cmd.asp?act=tb&amp;id=273">有人说RoR的性能和开发效率比java的struts+spring+hibernate经典搭配还要快15%-30%</a>。</div>
						<div>６、RoR目前发展势头强劲，在使用RoR的过程中你将会发现它已经具备了作为WEB开发语言的本质。如果它能够以简单为主的理念继续发展，相信它将象当年的PHP和Linux在网络上引起新的一轮革命。</div>
						<div>
								<div id="ftn1">
										<div>
										</div>
								</div>
						</div>
				</div>
				<div>图片和部分内容转自：</div>
				<div>
						<a href="http://www.duduwolf.com/cmd.asp?act=tb&amp;id=273">http://www.duduwolf.com/cmd.asp?act=tb&amp;id=273</a>
				</div>
				<div>
						<a href="http://www.neokeen.com/mornlee/2005/07/06/1120663087531.html">http://www.neokeen.com/mornlee/2005/07/06/1120663087531.html</a>
				</div>
				<div>
						<a href="http://dev.csdn.net/article/73751.shtm">http://dev.csdn.net/article/73751.shtm</a>
				</div>
		</div>
<img src ="http://www.blogjava.net/morphis/aggbug/106144.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/morphis/" target="_blank">morphis</a> 2007-03-24 23:08 <a href="http://www.blogjava.net/morphis/archive/2007/03/24/106144.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Comet: Low Latency Data for the Browser</title><link>http://www.blogjava.net/morphis/archive/2007/03/20/104992.html</link><dc:creator>morphis</dc:creator><author>morphis</author><pubDate>Tue, 20 Mar 2007 07:25:00 GMT</pubDate><guid>http://www.blogjava.net/morphis/archive/2007/03/20/104992.html</guid><wfw:comment>http://www.blogjava.net/morphis/comments/104992.html</wfw:comment><comments>http://www.blogjava.net/morphis/archive/2007/03/20/104992.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/morphis/comments/commentRss/104992.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/morphis/services/trackbacks/104992.html</trackback:ping><description><![CDATA[
		<a href="http://alex.dojotoolkit.org/?p=545">http://alex.dojotoolkit.org/?p=545</a>
		<br />
		<a href="http://www.cnblogs.com/allenyoung/archive/2006/08/24/485140.html">http://www.cnblogs.com/allenyoung/archive/2006/08/24/485140.html</a>
		<br />
		<br />
		<p>An old web technology is slowly being resurrected from the depths of history. Browser features that have gone untouched for years are once again being employed to bring better responsiveness to UIs. Servers are learning to cope with a new way of doing things. And I’m not talking about Ajax.</p>
		<p>New services like <a href="http://jotlive.com/">Jot Live</a> and <a href="http://meebo.com/">Meebo</a> are built with a style of data transmission that is neither traditional nor Ajax. Their brand of low-latency data transfer to the browser is unique, and it is becoming ever-more common. Lacking a better term, I’ve taken to calling this style of event-driven, server-push data streaming “Comet”. It doesn’t stand for anything, and I’m not sure that it should. There is much confusion about how these techniques work, and so using pre-existing definitions and names is as likely to get as much wrong as it would get right.</p>
		<h3>Defining Comet</h3>
		<p>For a new term to be useful, at a minimum we need some examples of the technology, a list of the problems being solved, and properties which distinguish it from other techniques. As with Ajax, these aren’t hard to find. A short list of example applications includes:</p>
		<ul>
				<li>
						<a href="http://mail.google.com/mail/help/chat.html">GMail’s GTalk integration</a>
				</li>
				<li>
						<a href="http://jotlive.com/">Jot Live</a>
				</li>
				<li>
						<a href="http://renkoo.com/">Renkoo</a>
				</li>
				<li>
						<a href="http://cgiirc.sourceforge.net/">cgi:irc</a>
				</li>
				<li>
						<a href="http://meebo.com/">Meebo</a>
				</li>
		</ul>
		<p>So what makes these apps special? What makes them different from other things that might at first glance appear similar? Fundamentally, they all use long-lived HTTP connections to reduce the latency with which messages are passed to the server. In essence, they do <em>not</em> poll the server occasionally. Instead the server has an open line of communication with which it can <em>push</em> data to the client.</p>
		<p>From the perspective of network activity, we can modify JJG’s <a href="http://www.adaptivepath.com/images/publications/essays/ajax-fig2.png">original Ajax diagram</a> to illustrate how Comet differs:</p>
		<p>
				<img style="BORDER-RIGHT: black 2px solid; BORDER-TOP: black 2px solid; BORDER-LEFT: black 2px solid; BORDER-BOTTOM: black 2px solid" alt="" src="http://alex.dojotoolkit.org/wp-content/Comet.png" />
		</p>
		<p>As is illustrated above, Comet applications can deliver data to the client at any time, not only in response to user input. The data is delivered over a single, previously-opened connection. This approach reduces the latency for data delivery significantly.</p>
		<p>The architecture relies on a view of data which is event driven on both sides of the HTTP connection. Engineers familiar with SOA or message oriented middleware will find this diagram to be amazingly familiar. The only substantive change is that the endpoint is the browser.</p>
		<p>While Comet is similar to Ajax in that it’s asynchronous, applications that implement the Comet style can communicate state changes with almost negligible latency. This makes it suitable for many types of monitoring and multi-user collaboration applications which would otherwise be difficult or impossible to handle in a browser without plugins. </p>
		<h3>Why Is Comet Better For Users?</h3>
		<p>Regular Ajax improves the responsiveness of a UI for a single user, but at the cost of allowing the context to go “stale” for long-lived pages. Changes to data from others users is lost until a user refreshes the whole page. An application can alternately return to the “bad old days” and maintain some sort of state mechanism by which it tells client about changes since the last time they’ve communicated. The user has to either wait until they preform some action which would kick off a request to see the updated state from other users (which might impact the action they wanted to preform!) or request changes from the server at some interval (called “polling”). Since the web is inherently multi-user, it’s pretty obvious that regular Ajax imposes usability and transparency hurdles for users. Applications that employ the Comet technique can avoid this problem by <em>pushing</em> updates to all clients as they happen. UI state does not go out of sync and everyone using an application can easily understand what their changes will mean for other users. Ajax improves single-user responsiveness. Comet improves application responsiveness for collaborative, multi-user applications and does it without the performance headaches associated with intermittent polling.</p>
		<h3>But Does It Scale?</h3>
		<p>New server software is often required to make applications built using Comet scale, but the patterns for event-driven IO on the server side are becoming better distributed. Even Apache will provide a Comet-ready worker module in the upcoming 2.2 release. Until then, tools like <a href="http://twistedmatrix.com/">Twisted</a>, <a href="http://poe.perl.org/?What_POE_Is">POE</a>, Nevow, mod_pubsub, and other higher-level event-driven IO abstractions are making Comet available to developers on the bleeding edge. Modern OSes almost all now support some sort of kernel-level event-driven IO system as well. I’ve even heard that Java’s NIO packages will start to take advantage of them in a forthcoming release. These tools are quietly making the event-driven future a reality. This stuff will scale, and most of the tools are in place already.</p>
		<p>I’ll be giving a more <a href="http://conferences.oreillynet.com/cs/et2006/view/e_sess/7995" in-depth="" talk<="" a="">on this topic at </a><a href="http://conferences.oreillynet.com/et2006/">ETech</a> and describing the various techniques that Comet applications can employ to push data from the server to the client. As always, I’ll post the slides here as well.</p>
		<p>The future of the read-write web is multi-user. There is life after Ajax.</p>
		<h3>Endnotes</h3>
		<p>First, a word on terminology and its importance. “Ajax” <a href="http://www.adaptivepath.com/publications/essays/archives/000385.php">was coined</a> to describe background request/response data transfer. Many of <a href="http://dojotoolkit.org/community/contributors.shtml">us</a> had worked on solutions to do exactly this, but it wasn’t until a simple name and accompanying description were provided that it was possible for people not directly building applications to describe what it was they liked about it. Common terminology acts not only as a shortcut in discussions between technical folks, but also as a bridge for those who may not be able to give a technical rundown of exactly how it works.</p>
		<p>As with Ajax, those of us who build technology are now faced with another communication challenge. We have a hard problem for which solutions are available (and have been for some time) but no way to communicate about them. Terminology is again the missing link. Today, keeping an HTTP connection open for doing low-latency data transfer to the browser has no digestible name. When I describe a <a href="http://alex.dojotoolkit.org/?p=538">cool new hack</a>, there’s nothing to associate it with. When people say “how the hell did they <a href="http://jotlive.com/">do that</a>?”, we don’t have a compact answer. Therefore, in the spirit of improved communication (and not technology invention), I’m proposing a new name for this stuff.</p>
		<p>Next, for those who are network-level programmers or are familiar with sockets and/or basic TCP/IP programming, you will probably scoff at the concept of web applications finally getting this kind of datagram packet support. Fair enough. It is however interesting to note that while more responsive UIs have been available on a variety of platforms to date, the Web has “won” the broad majority of market share for most classes of applications in which the browser provides enough native (non-plugin) support to make the performance and/or UI feasible. Comet may be a new name for an old set of concepts wrapped in some pretty grotty hacks, but that in no way diminishes the market impact it will have (and is already having).</p>
		<p>Lastly, as current Dojo users might expect, Dojo already supports Comet via <code>dojo.io.bind()</code>. More than a year ago we designed the API with Comet in mind. In the next couple of weeks I’ll be showing how <code>bind</code>’s pluggable transport layer can be combined with Dojo’s event topic mechanism to provide message delivery on top of a message bus.</p>
<img src ="http://www.blogjava.net/morphis/aggbug/104992.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/morphis/" target="_blank">morphis</a> 2007-03-20 15:25 <a href="http://www.blogjava.net/morphis/archive/2007/03/20/104992.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>