我现在有一个html的网页代码,要将其改为perl程序,如果只是单纯在其第一行加上"#!../perl/bin/perl",并将文件后缀名改为.cgi,会出现错误提示"You don't have permission to access /test/index.cgi on this server."。换句话说:后缀名为.cgi的perl里如何包含html代码?谢谢。
---------------------------------------------------------------
给你篇文章看看:
把程式語言嵌在 HTML 裡, 一直是許多網頁計者的夢想... 最近紅透半邊天的 PHP (讓 M$ 的 ASP 靠邊站), 成為廣大網站設計者的最愛(超過100萬個站台), 身為 Perl 的愛好者, 不禁要問: Perl 也可以嵌在 HTML 中嗎? 答案是: 可以的!
以下為您介紹三種不錯的 Embed Perl:
Mason - http://www.masonhq.com/
Embperl - http://perl.apache.org/embperl/index.html
ePerl - http://www.engelschall.com/sw/eperl/
首先, 您必須安裝好 Apache + mod_perl
Mason安裝法:
perl Makefile.PL
make
make install
修改 httpd.conf, 加入:
PerlRequire /usr/local/mason/handler.pl
Alias /mason /usr/local/www/htdocs
1<location mason="">
2SetHandler perl-script
3PerlHandler HTML::Mason
4</location>
重新啟動 Apache.
範例:
http://www.tnc.edu.tw/ml/TestMason.htm
http://www.tnc.edu.tw/ep/ePerl_test.htm
http://www.tnc.edu.tw/emp/embperl_test.htm
Embperl 及 ePerl 的安裝法類似,請自行參考程式包中的安裝說明.
sub html_html
{
print "Content-type: text/html\n\n";
print <
1<eof; "content-type:="" #!..="" #这里输出html="" <<eof;="" <html="" \n\n";="" bin="" eof="" exit;="" html="" perl="" print="" text="" top.gif"却不能显示,代码如下:="" }="" 加了以后果然可以,但里面的图片"resource="" 谢谢ceocio。="">
2<head>
3<title>Top</title>
4<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
5</head>
6<body bgcolor="#FFFFFF" text="#000000">
7<table border="0" cellpadding="2" cellspacing="0" height="100%" width="100%">
8<tr>
9<td><img height="100%" src="resource/Top.gif" width="100%"/></td>
10</tr>
11</table>
12</body>
13
14eof
15
16图片的属性为755,也正确地存在于相应的目录.
17
18用相对路径,最好做一个安装文件setup.cgi
19
20在你的这个文件中:
21require "setup.cgi";
22
23然后这样调用:
24<img src="$gif/top.gif"/>
25
26setup.cgi文件中有这一行:
27$gif='http://your url/resource'; #图片的URL路径
28
29这样用相对路径应该可以了。</eof;>