获取Perl CGI脚本的空白屏幕

时间:2018-05-18 07:41:19

标签: perl cgi dbi

我在网页上显示以下Perl CGI脚本的空白屏幕。 脚本在终端上执行得很好,但是当我从Web浏览器运行它时它是空白的。请帮忙。

当我将Web内容移动到页面顶部时,这是有效的。基本上我在数据库连接后放置的任何内容都没有显示在Web浏览器上。

操作系统:Unix Apache2 Web服务器

注意:该脚本具有执行权限。

#!/usr/bin/perl

use strict;
use warnings;
use DBI;
use CGI;

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

# Simple HTML code follows
my $driver= "Oracle";
my $dsn = "DBI:$driver:sid=xxxxx;host=xxxxx;port=1521";
my $dbh = DBI->connect($dsn,'xxxx','xxxx');

#print $dbh;

my $sth = $dbh->prepare("SELECT * FROM TABLE WHERE ROWNUM <= 10");
$sth->execute;

print "<html> <head>\n";
print "<title>Hello, world!</title>";
print "</head>\n";
print "<body>\n";
print "<h1>Hello, world!</h1>\n";
print "<p>The Details  are as follows:</p>\n";
print "<table cols=5 border=1>\n";
print "<tr>\n";
print "<th>ACTION</th>\n";
print "<th>ALARM_TEXT</th>\n";
print "<th>ALARM_SEV</th>\n";
print "<th>EMS_NAME</th>\n";
print "</tr>";

while(  my $ref = $sth->fetchrow_hashref() ) {
        print "<tr>\n";
        print "<td>", $ref->{'ACTION'}, "</td>\n";
        print "<td>", $ref->{'ALARM_TEXT'}, "</td>\n";
        print "<td>", $ref->{'ALARM_SEV'}, "</td>\n";
        print "<td>", $ref->{'EMS_NAME'}, "</td>\n";
        print "</tr>\n";
}
print "</table>\n";
print "<h1>Hello, world!</h1>\n";
print "</body> </html>\n";

1 个答案:

答案 0 :(得分:1)

通过在httdd.conf文件中添加以下行来修复它。

SetEnv ORACLE_HOME /oracle/app/oracle/product/11.2.0.4/db_1