Glory

星期四, 三月 29, 2007

Blogger搬家

blogspot经常访问不了,据说是被封,受不了,转到blogger spaces 了。
本来想弄到自己的服务器上不知道什么原因老是无法完成,转移时在我的ftp上blogger的ftp创建了目录结构就是传不了文件,老是超时,郁闷
转到blogger spaces也挺不错的,以后可以把自己的blogger中的东西备份到自己的服务器上
希望以后我的blogger能够正常!

标签:

星期三, 三月 21, 2007

Perl Ajax

对Ajax了解过一些,但一直没有实践过,最近学习Perl,昨天用ppm安装Module的时候无意中发现有个叫CGI::Ajax的模块,今天装上并弄了个示例程序测试了一下,感觉不错比较简单。

#!c:/perl/bin/perl.exe -w
use strict;
use CGI::Ajax;
use CGI;
#下面是我们这个程序的核心逻辑部分.
#客户端通过会Ajax调用这个函数,得到想要的结果。
sub test_calculate{
my ($cal1,$cal2)=@_;
return ($cal1+$cal2);
}
#下面是客户端显示的html
#注意onclick部分的写法。你可以将其理解为一段伪码(其实不是伪码,其实际代码部分都是CGI::Ajax自动生成的),表示:
#调用函数calculate,参数是val1控件和val2控件的值,结果显示在result控件上。
sub Show_HTML{
my $html = <











EOHTML
return $html;
}
my $cgi=new CGI();
# 这里的代码将刚才提到的伪码calculate和我们的perl实现函数关联起来。
#这样,当客户端点击时调用calculate伪码,其效应就是:
#程序自动生成的javascript代码就会启动Ajax机制,远程调用我们这个cgi中的test_calculate函数,
#并得到其结果,输出到相应的页面控件来显示。
my $ajax=new CGI::Ajax('calculate'=>\&test_calculate);
#build_html,这一步中,CGI::Ajax会自动生成html网页和Ajax调用的所有javascript代码。
#而当客户端通过Ajax调用本程序时,这个build_html函数还会自动调用相应的函数(test_calculate)并且返回结果。
print $ajax->build_html($cgi,\&Show_HTML);

exit;

Perl简洁实用,非常符合程序员的思想。

标签: , ,

Perl CGI 中文问题

用Perl写CGI程序比较方便,但是由于刚开始用,发现输出中文的内容变为乱码,分析产生的html代码,原来是默认字符集不是gb2312,找了一下解决办法。

不要用默认的print header


print "Content-type: text/html;charset:GB2312\n";

print "Pragma:no-cache\n\n";

正常!


关于编码的问题碰到了很多,尤其在页面之间传递参数,中文文件名的文件下载等都会遇到这类编码问题。

标签: , ,

星期一, 三月 19, 2007

Perl-CGI

CGI.pm Method Groupings

Group Description

:all Contains all of the methods available in the CGI.pm module

:cgi Contains methods specific to the CGI protocol

:form Contains methods used to generate forms

:html A superset of the :html2, :html3, :html4, and :netscape groups

:html2 Contains methods that enable the developer to quickly use elements from theHTML version 2 specification

:html3 Like the :html2 group, contains methods that enable the developer to quickly use elements from the HTML version 3 specification

:html4 Contains methods that enable the developer to quickly use elements from theHTML version 4 specification

:netscape Contains the Netscape extensions for the HTML 3 specification, including a shortcut to my favorite HTML tag <BLINK>

:multipart Contains methods used to help work with MIME types

:standard Probably the most frequently used group of methods, a superset of the :html2,:html3, :html4, :form, and :cgi groups


A function-oriented Fashion CGI

#!/usr/bin/perl T


use strict;

use CGI ':standard';


print header;

print start_html('Hello World');

print h1('Hello World');

print end_html();


exit;


An object-oriented Fashion CGI

#!/usr/bin/perl T


use strict;

use CGI;


my $cgi = new CGI;

print $cgi->header;

print $cgi->start_html('Hello World');

print $cgi->h1('Hello World');

print $cgi->end_html();


exit;


The CGI module has a large number of functions to make the life of the programmer easier. These functions range from those that create HTML tags, HTTP headers, and cookies to those for working with web forms.

HTML Shortcuts

Most of the HTML version 3 and 4 tags are available through a function in the CGI module. Simply calling the HTML function with a print statement will cause it to be sent to the outputted page.


Dynamic Pages and Forms

Just as standard HTML elements are available through functions in the CGI module, so are form elements. For example, tags to start and end forms, code for text fields and other input fields, and code for buttons are available as CGI module functions. The syntax for these functions is the same as the syntax for calling HTML tag functions.

Printing the Name Input Using the CGI Module

#!/usr/bin/perl -T

use strict;

use CGI qw/:standard/;

print header,

start_html('Hello'),

start_form,

"Enter your name: ",textfield('name'),

submit,

end_form,

hr;

if (param()) {

print "Hello ",

param('name'),

p;

}

print end_html;

exit;


Cookies

A Simple Cookie Example

#!/usr/bin/perl -T

use strict;

print "Content-type: text/html\n";

print "Set-Cookie: testcookie=testvalue;";

print "\n\n";

print "You've received a cookie<p>\n";

exit;



Post by Word2007

标签: ,

星期二, 三月 13, 2007

一年之计在于春

春天来了,不过这个春天真的不轻松!

幸好有这一句:一年之计在于春!

星期四, 三月 08, 2007

Word2007发博客测试

Word2007发博客测试