C, shell, and Perl develop CGI program environment configuration based on Tomcat

Source: Internet
Author: User

Configure the CGI Development Environment Based on tomcat7.0. The steps are as follows:

Take my tomcat 7 installation directory as an example: tomca_home =/users/Yangxin/documents/devtoos/Java/Apache-Tomcat-7.0.39

1. Open tomca_home/CONF/Web. xml

Open comments of CGI Serlvet configuration and URL ing

<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 initialization parameters:

1> cgipathprefix: Set the access location of the CGI program in the application, the default access location is: Application name/WEB-INF/cgi

2> executable: CGI program parser. The default value is Perl. If it is null, it can be a script parser installed in the operating system environment variables, or a C/C ++ program.

3> parameterencoding: the default parameter encoding for accessing CGI servlet. The default value is UTF-8.

4> passshellenvironment: Specifies whether to enable shell environment variables. The default value is false.

5> stderrtimeout: timeout duration for reading standard error messages. The default value is 2000 milliseconds.



2. Open tomcat_home/CONF/context. xml

Add an attribute on the context nodePrivileged = 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 events         on session expiration as well as webapp lifecycle) -->    <!--    <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />    --></Context>

3. Create a CGI Test Program

Create an application under the tomcat_home/webapps directory, such as cgitest, create a WEB-INF directory under the cgitest application, create a CGI directory and a web under the WEB-INF directory. XML file, and then add a CGI test script program Hello in the CGI directory. SH and. C and compile it into. CGI and modify the access permission. Start Tomcat and access http: // localhost: 8080/cgitest/cgi-bin/Hello. Sh to access your own CGI program.

The created application directory structure is as follows:


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/javaee                      http://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/shecho "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;}

Test results:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.