如何使用 cgi.pm 获得正确的 HTML 标头

how to for a correct html header using cgi.pm?

本文关键字:HTML 标头 何使用 cgi pm      更新时间:2023-09-26

我对 CGI.pm 语法并不熟悉。

我尝试创建html_header但我无法让它工作。我需要同时拥有http_equiv和javascript。标头在没有 -script 部分的情况下工作正常。我在这里做错了什么?

print $cgi->start_html( 
    -head => meta({
        -http_equiv => "Refresh",
        -content =>"$viive;URL=http://192.168.1.42/saldo/index.cgi?varasto=$varasto"
    }),
    -title => 'Varasto '.$varasto, 
    -style => { -src => 'infotaulu.css' }
    -script => {
    -language => 'javascript',
    -src => '/sorttable.js'
);

您的问题是您错过了 -style 参数末尾的逗号。使用这个:

print $cgi->start_html(
    -head => $cgi->meta({
        -http_equiv => "Refresh",
        -content =>"$viive;URL=http://192.168.1.42/saldo/index.cgi?varasto=$varasto"
    }),
    -title => 'Varasto '.$varasto,
    -style => { -src => 'infotaulu.css' },
    -script => {
    -language => 'javascript',
    -src => '/sorttable.js'
    }
);

给我这个输出:

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Varasto varasto</title>
<meta http-equiv="Refresh" content="viive;URL=http://192.168.1.42/saldo/index.cgi?varasto=varasto" />
<link rel="stylesheet" type="text/css" href="infotaulu.css" />
<script src="/sorttable.js" type="text/javascript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>

我想这就是你想要的。

但是,我真的认为您应该重新考虑您的方法。在 CGI.pm 中使用HTML生成函数是一个糟糕的主意。你最终会得到一堆可怕的无法维护的代码。请考虑改用模板系统。