装机配置相关---tomcat配置CGI

mac2022-06-30  46

1、修改conf/web.xml

找到并将cgi的servlet和servlet-mapping的注释去掉

<servlet>          <servlet-name>cgi</servlet-name>          <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>          <init-param>            <param-name>debug</param-name>            <param-value>0</param-value>          </init-param>          <init-param>            <param-name>cgiPathPrefix</param-name>            <param-value>cgi-bin</param-value>          </init-param>           <load-on-startup>5</load-on-startup>  </servlet>  

注意:其中cgiPathPrefix是cgi文件的存放路径,默认是WEB-INF/cgi,我为了方面用awstats,所以改成cgi-bin

<servlet-mapping>          <servlet-name>cgi</servlet-name>          <url-pattern>/cgi-bin/*</url-pattern>  </servlet-mapping>  

/cgi-bin/*意思是,访问cgi文件的默认地址为cgi-bin/*

2、修改conf/context.xml

<?xml version='1.0' encoding='utf-8'?>  <Context privileged="true">        <!-- Default set of monitored resources -->      <WatchedResource>WEB-INF/web.xml</WatchedResource>            <!-- Uncomment this to disable session persistence across Tomcat restarts -->      <!--     <Manager pathname="" />     -->        <!-- Uncomment this to enable Comet connection tacking (provides events           on session expiration as well as webapp lifecycle) -->      <!--     <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />     -->    </Context>  

修改<Context>添加privileged="true"属性,否则页面提示Servlet CGI is not availabled,且tomcat会有错误提示java.lang.SecurityException: Restricted classclass org.apache.catalina.servlets.CGIServlet

3、如果tomcat的版本是6以下的,必须将server/lib/目录下的servlets-cgi.renametojar改名为servlets-cgi.jar

有以上三步,已经可以成功配置CGI了,访问地址如http://localhost:8080/cgi-bin/test.pl

转载于:https://www.cnblogs.com/VWIN/p/4540861.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)