C、Shell、Perl基于Tomcat开发CGI程序环境配置
基于Tomcat7.0版本號配置CGI開發環境,步聚例如以下:
以我的Tomcat7安裝文件夾為例:TOMCA_HOME =?/Users/yangxin/Documents/devToos/java/apache-tomcat-7.0.39
1、打開TOMCA_HOME/conf/web.xml
將CGI的Serlvet配置與URL映射凝視打開
<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>executable</param-name><param-value></param-value></init-param><init-param><param-name>cgiPathPrefix</param-name><param-value>WEB-INF/cgi</param-value></init-param><load-on-startup>5</load-on-startup></servlet><!-- The mapping for the CGI Gateway servlet --><servlet-mapping><servlet-name>cgi</servlet-name><url-pattern>/cgi-bin/*</url-pattern></servlet-mapping>CGI Servlet初始化參數說明:
1>?cgiPathPrefix:設置cgi程序在應用中的訪問位置,默認訪問位置為:應用名稱/WEB-INF/cgi
2> executable:CGI程序解析器,默覺得perl。假設為空。能夠是不論什么安裝在操作系統環境變量的腳本解析器,或是C/C++程序
3> parameterEncoding:訪問CGI Servlet的默認參數編碼,默覺得utf-8
4> passShellEnvironment:是否開啟shell環境變量。默覺得false
5> stderrTimeout:讀取標準錯誤信息超時時長,默覺得2000毫秒
2、打開TOMCAT_HOME/conf/context.xml
在context節點上加入一個屬性privileged=true
<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 eventson session expiration as well as webapp lifecycle) --><!--<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />--></Context>
3、創建CGI測試程序
在TOMCAT_HOME/webapps文件夾下創建建一個應用,如:cgitest,在cgitest應用下創建一個WEB-INF文件夾。在WEB-INF文件夾下創建一個cgi文件夾和一個web.xml文件,然后在cgi文件夾加入一個CGI測試腳本程序hello.sh和a.c并編譯成a.cgi,并改動訪問權限。
隨后啟動tomcat。訪問http://localhost:8080/cgitest/cgi-bin/hello.sh就能夠訪問自己寫的CGI程序了
創建好的應用文件夾結構例如以下所看到的:
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?><web-app xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version="3.0"metadata-complete="true"><display-name>Welcome to Tomcat</display-name><description>Welcome to Tomcat</description></web-app>hello.sh:
#!/bin/sh echo "Content-type:text/html\n\n" echo "hello world"a.c
#include <stdlib.h> #include <stdio.h>int main(int argc, const char** args) {printf("Content-type:text/html\n\n");printf("i is cgi programe");return 0; }
測試結果:
轉載于:https://www.cnblogs.com/blfshiye/p/5250026.html
總結
以上是生活随笔為你收集整理的C、Shell、Perl基于Tomcat开发CGI程序环境配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#语言基础— 输入与输出
- 下一篇: 最优化方法(无约束)转载