请教:为什么这个留言 CGI 不能正常显示中文(附源代码)?[Apache1.3.26 + ActivePerl5.6.1] (100分)

  • 主题发起人 小雨哥
  • 开始时间

小雨哥

Unregistered / Unconfirmed
GUEST, unregistred user!
#!c:/Program Files/Apache Group/Perl/bin/perl
use strict;
use CGI qw:)all);
use Fcntl qw:)flock);
#信息文件存放位置和文件
my $gbdata="C:/Program Files/Apache Group/MsgBook.txt";
#临时文件,可以是任意的文件名
my $semaphore_file="C:/Program Files/Apache Group/BookMsg.sem";
#加锁
sub get_lock{
open(SEM,">$semaphore_file")
|| die "无法存入文件:$!";
flock SEM,LOCK_EX;
}
#解锁
sub release_lock {
close(SEM);
}

sub save {
get_lock();
open(GB,">>$gbdata")|| die "无法打开文件 $gbdata:$!";
print GB "姓名:",param('name'),"/n";
print GB "类型:",param('probtype'),"/n";
print GB "内容:",param('problem'),"/n";
close(GB);
release_lock();
}
#显示(你的问题:)
sub display{
# print "<html>","/n";
# print "<head>","/n";
# print '<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">',"/n";
# print "<title>结果</title>","/n";
# print "</head>";
# print "<body>","/n";
## print header;
open(GB,$gbdata) || die "不能打开 $gbdata:$!";
while(<GB>){
print "<B>$_</B><BR>";
my($type,$prob);
$type=<GB>;
$prob=<GB>;
print "$type<BR>";
print "$prob<BR><HR size=1 color=#0000FF><P>";
}
close(GB);
# print "</body>","/n";
# print "</html>";
}
#显示表头
print header;
if (defined param('submit')){
save;
display;
} else
{
display;
}
############### FORM.HTML ###############
#<div align="center">
# <center>
# <table border="0" height="306" width="343">
# <tr>
# <td width="19" height="16"> </td>
# <td width="304" height="16"> </td>
# <td width="23" height="16"> </td>
# </tr>
# <tr>
# <td width="19" height="16"> </td>
# <td width="304" height="16"> </td>
# <td width="23" height="16"> </td>
# </tr>
# <tr>
# <td width="19" height="16"> </td>
# <td width="304" height="16">
# <p align="center">你遇到问题了?</p>
# </td>
# <td width="23" height="16"> </td>
# </tr>
# <tr>
# <td width="19" height="212"> </td>
# <td width="304" height="212">
# <FORM action="script/Msgbook.cgi" name="Msgbook">
#问题类型:
#<INPUT TYPE=radio name=probtype value=硬件方面>硬件
#<INPUT TYPE=radio name=probtype value=软件方面>软件
#<INPUT TYPE=radio name=probtype value=其它方面>其它
#<BR>
#<TEXTAREA name=problem rows=5 cols=40>
#</TEXTAREA><BR>
#你的名字:
#<INPUT TYPE=text width=40 name=name><BR>
#<p align="center">
#<INPUT TYPE=submit name=submit value="发送问题">
#</FORM>
# </td>
# <td width="23" height="212"> </td>
# <tr>
# <td width="19" height="16"> </td>
# <td width="304" height="16"> </td>
# <td width="23" height="16"> </td>
# </tr>
# </table></div>
程序正常执行,但语言测试始终为:Charset=ISO-8859-1,显示为乱码,需要手工从浏览器
端改变编码才能看懂。我反复试验都不能完成,查 Apache 的配置文件,根本也没有 ISO-8859-1
的语言配置,它是从哪里来的?如果知道,请告诉我,谢谢。
 
在以下语句
print "<html>","/n";
的前面加上:
print "Content-type:text/html/n/n";
 
好象没有效果,今天可以在这里看到效果 http://218.0.239.239/script/book.cgi <----- [2002.8.21]有效
如下 a.cgi 简单文件:
#!c:/Program Files/Apache Group/Perl/bin/perl
use CGI ':standard';
print header;
print start_html('看看这个');
print "信息文件存放位置和文件","/n";
print end_html;
执行后后,呈现的结果输出如下:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
"http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"><head><title>看看这个</title>
</head><body>信息文件存放位置和文件
</body></html>
其中有一句好象 perl 有语言默认值,但中文下就是乱码。
怎么解决??
 
上面的这个header是你自己定义的,还是还是哪个库的?
header中有没有参数?
 
问题没有解决,好象大富翁不象传闻中那么优秀。
论坛无人论的感觉真的很不好。
不过,非常感谢 jsxjd 朋友。
 
顶部