tomcat6.0运行CGI程序

Tomcat6 调用cgi

项目中要用tomcat调用cgi,在网上找了一些资料都是用tomcat5.5配置,因为tomcat6和tomcat5有很大的改变,所以配置并不使用。只能自行研究,结果如下:

tomcat6已经把servlets-cgi.jar集成到catalina.jar,无需象tomcat5.5一样配置jar包;

1、去掉conf/web.xml中的如下段中的注释;

<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>passShellEnvironment</param-name>
          <param-value>true</param-value>//?
         </init-param>


        <init-param>
          <param-name>cgiPathPrefix</param-name>
          <param-value>WEB-INF/cgi-bin</param-value>//此处映射真实路径

                                                      形式为tomcat path+projectname+param-value
        </init-param>
   <init-param> 
          <param-name>executable</param-name>
          <param-value>cmd /c</param-value>      //c++的cgi解析方式
      </init-param>

     <init-param>
          <param-name>clientInputTimeout</param-name>
          <param-value>100</param-value>
        </init-param>
         <load-on-startup>5</load-on-startup>
    </servlet>


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

2、配置权限

在conf/context

<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>

不配置步骤2,将会出现java.lang.SecurityException: Servlet of class org.apache.catalina.servlets.CGIServlet is privileged and cannot be loaded by this web application这一异常。

Java中编写CGI程序用System.getProperty(String key)
System.getProperty(String key)
public class Information {  
  1.     public static void main(String args[]) {  
  2.          System.out.println("java_vendor:" + System.getProperty("java.vendor"));  
  3.          System.out.println("java_vendor_url:"  
  4.                  + System.getProperty("java.vendor.url"));  
  5.          System.out.println("java_home:" + System.getProperty("java.home"));  
  6.          System.out.println("java_class_version:"  
  7.                  + System.getProperty("java.class.version"));  
  8.          System.out.println("java_class_path:"  
  9.                  + System.getProperty("java.class.path"));  
  10.          System.out.println("os_name:" + System.getProperty("os.name"));  
  11.          System.out.println("os_arch:" + System.getProperty("os.arch"));  
  12.          System.out.println("os_version:" + System.getProperty("os.version"));  
  13.          System.out.println("user_name:" + System.getProperty("user.name"));  
  14.          System.out.println("user_home:" + System.getProperty("user.home"));  
  15.          System.out.println("user_dir:" + System.getProperty("user.dir"));  
  16.          System.out.println("java_vm_specification_version:"  
  17.                  + System.getProperty("java.vm.specification.version"));  
  18.          System.out.println("java_vm_specification_vendor:"  
  19.                  + System.getProperty("java.vm.specification.vendor"));  
  20.          System.out.println("java_vm_specification_name:"  
  21.                  + System.getProperty("java.vm.specification.name"));  
  22.          System.out.println("java_vm_version:"  
  23.                  + System.getProperty("java.vm.version"));  
  24.          System.out.println("java_vm_vendor:"  
  25.                  + System.getProperty("java.vm.vendor"));  
  26.          System.out  
  27.                  .println("java_vm_name:" + System.getProperty("java.vm.name"));  
  28.          System.out.println("java_ext_dirs:"  
  29.                  + System.getProperty("java.ext.dirs"));  
  30.          System.out.println("file_separator:"  
  31.                  + System.getProperty("file.separator"));  
  32.          System.out.println("path_separator:"  
  33.                  + System.getProperty("path.separator"));  
  34.          System.out.println("line_separator:"  
  35.                  + System.getProperty("line.separator"));  
  36.      }  



  37. From jdk 1.5.0 documents

    java.version

    Java 运行时环境版本

    java.vendor

    Java 运行时环境供应商

    java.vendor.url

    Java 供应商的 URL

    java.home

    Java 安装目录

    java.vm.specification.version

    Java 虚拟机规范版本

    java.vm.specification.vendor

    Java 虚拟机规范供应商

    java.vm.specification.name

    Java 虚拟机规范名称

    java.vm.version

    Java 虚拟机实现版本

    java.vm.vendor

    Java 虚拟机实现供应商

    java.vm.name

    Java 虚拟机实现名称

    java.specification.version

    Java 运行时环境规范版本

    java.specification.vendor

    Java 运行时环境规范供应商

    java.specification.name

    Java 运行时环境规范名称

    java.class.version

    Java 类格式版本号

    java.class.path

    Java 类路径

    java.library.path

    加载库时搜索的路径列表

    java.io.tmpdir

    默认的临时文件路径

    java.compiler

    要使用的 JIT 编译器的名称

    java.ext.dirs

    一个或多个扩展目录的路径

    os.name

    操作系统的名称

    os.arch

    操作系统的架构

    os.version

    操作系统的版本

    file.separator

    文件分隔符(在 UNIX 系统中是“/”

    path.separator

    路径分隔符(在 UNIX 系统中是“:”

    line.separator

    行分隔符(在 UNIX 系统中是“/n”

    user.name

    用户的账户名称

    user.home

    用户的主目录

    user.dir

    用户的当前工作目录

posted @ 2010-01-29 10:01  留心_frankliujava  阅读(3766)  评论(0编辑  收藏  举报