[英]basic mod_perl question
I am very newbie to Perl. 我是Perl的新手。
I wrote a very simple Perl program (script): 我写了一个非常简单的Perl程序(脚本):
print "hello";
When I execute it on command prompt (with command - perl first.pl), it works. 当我在命令提示符(使用命令-perl first.pl)上执行它时,它可以工作。
However, when I use the same Perl code in "filter" of apache it doesn't work. 但是,当我在apache的“过滤器”中使用相同的Perl代码时,它不起作用。 To provide more details, I am invoking a filter for a URL in Apache Http Server with following configuration in httpd.conf file:
为了提供更多详细信息,我正在使用httpd.conf文件中的以下配置调用Apache Http Server中URL的过滤器:
<Location /something.do>
SetHandler modperl
PerlResponseHandler MyApache2::FirstPerlProg
</Location>
FirstPerlProg.pm file (in indigoampp\\perl-5.12.1\\site\\lib\\MyApache2 location) has same code as first.pl. FirstPerlProg.pm文件(在indigoampp \\ perl-5.12.1 \\ site \\ lib \\ MyApache2位置)具有与first.pl相同的代码。
The index.html page (first page) has a form which submits request to something.do and this filter gets invoked. index.html页面(第一页)具有一种将请求提交到something.do的形式,并且此过滤器被调用。
The issue is, how and where do I see this filter's output (hello)? 问题是,如何以及在哪里看到此过滤器的输出(您好)?
Hope my question is clear. 希望我的问题清楚。
I know that I am not making any HTTP response to be sent to browser in this filter code and that's why I get 'page can't be displayed' after submit. 我知道我不会在此过滤器代码中进行任何HTTP响应发送到浏览器,这就是为什么提交后出现“无法显示页面”的原因。 However what shall I do is something I don't know.
但是我不知道该怎么办。
Thanks. 谢谢。
Depends on how you wrote it. 取决于您的编写方式。 Going by your code, the skeleton should look like
按照您的代码,骨架应该看起来像
package MyApache2::FirstPerlProg; use Apache2::Const qw(OK); use Apache2::RequestRec; use Apache2::RequestIO; sub handler { my ($r) = @_; $r->content_type("text/html"); $r->print("hello"); return OK; } 1;
This would be roughly the bare minimum for a mod_perl request handler. 对于mod_perl请求处理程序而言,这几乎是最低的要求。 And this should be the response coming back from the request, should see it in the browser.
这应该是从请求返回的响应,应该在浏览器中看到它。 You can also use
Apache2::Log
and then use $r->log_error("text")
to send to the error_log. 您也可以使用
Apache2::Log
,然后使用$r->log_error("text")
发送到error_log。
If you want your script to run CGI-ish, then use the ModPerl::Registry. 如果您希望脚本运行CGI-ish,请使用ModPerl :: Registry。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.