【发布时间】:2021-06-25 08:34:27
【问题描述】:
我有两个不同的 Perl CGI,如下所示,它们创建了两个 HTML。
tes1.pl 是从 test.html 调用,作为带有参数的 POST 调用。
test2.pl 将从 test1.pl 中调用。但问题出在这里,test2.pl 中有一个指向 test1.pl 的链接。
所以。单击链接时,所有 POST 参数都将消失,因为它在不同的上下文中运行。
有人可以告诉我如何解决这种情况吗?
test.html:
<form id = "test" action ="./tes1.pl" method="POST" target="_blank">
<input type="hidden" id='param_sender' name="param1" value="">
</form>
<a onclick="setValue();document.getElementById('test').submit();">SEND THE VALUE</td></tr>
test1.pl:
use CGI;
$page=CGI::new();
my $method=$page->request_method;
if ($method eq "POST") {
my $gpmsc_user=$page->param('param1');
}
print $page->header,
"<link rel='stylesheet' href='./test.css' type='text/css'>";
print $page->start_html(-title=>"TEST1");
test2.pl
my $page= new CGI();
print $page->header,
"<link rel='stylesheet' href='./test.css' type='text/css'>";
print $page->start_html(-title=>'TEST2');
print $page->startform(-method=>post,-action=>'test3.pl');
print $page->append,
"<table border=true>
<tr class=amhead>
<td colspan=3>
<br><a href='test1.pl'>Return to Test1</a>
</td>
</tr>..."
【问题讨论】:
-
你的例子真的很混乱。你没有表现出任何的召唤。我认为您的意思是用户在不同的脚本之间跳转。如果你必须做 CGI,看看 CGI::Session。您希望跨多个请求在后端保留每个用户的数据,因此您需要一个会话。
-
test.html 有一个锚标记来提交调用 test.pl 的表单 test2.pl 有一个锚标记,其中有指向 test1.pl 的链接。这是你指的吗?但是,你说得对,我需要在对同一个 CGI 的多个请求中保留数据