WebLogic Server 7.0 Code Examples, BEA Systems, Inc.

Package examples.cgi

This sample shows how to set up a cgi servlet mapping for including CGI scripts to your Web Application.

See:
          Description

CGI Example Summary
HelloWorld.pl This is a simple perl CGI script that outputs a static HTML file.
 

Package CGI Description

This example contains a simple CGI perl script, intended to show you how to use CGI with WebLogic Server. The intent here is not to teach CGI or perl, but to explain the process of configuring your Web Application to include CGI scripts. This functionality is to support your legacy Common Gateway Interface (CGI) scripts. For new projects, we suggest you use HTTP servlets or JavaServer Pages.

Perform the following steps to build and run the example:

  1. Configure the examplesWebApp
  2. Start the examplesServer
  3. Run the example

Configure the examplesWebApp

  1. Add the following to your the examplesWebApp web.xml file located at:

    %SAMPLES_HOME%\server\stage\examples\examplesWebApp\WEB-INF\web.xml:

      <servlet> 
        <servlet-name>CGIServlet</servlet-name>  
        <servlet-class>weblogic.servlet.CGIServlet</servlet-class>  
        <init-param>    
          <param-name>cgiDir</param-name>    
          <param-value>c:\path\to\cgi-bin</param-value>  
        </init-param>
        <init-param>      
          <param-name>*.pl</param-name>      
          <param-value>c:\path\to\perl.exe</param-value>    
        </init-param>
      </servlet>
    
      <servlet-mapping>      
        <servlet-name>CGIServlet</servlet-name>      
        <url-pattern>/cgi-bin/*</url-pattern>
      </servlet-mapping>
    

    Where:

    1. c:\path\to\cgi-bin should be substituted with your path to this directory. This path is the directory you will drop your CGI scripts into be associated with the CGIServlet. Since HelloWorld.pl already lives here, it is easiest to configure it this way.
    2. c:\path\to\perl.exe should be substituted with a path to the perl executable you would like to use. WebLogic Server dosen't bundle a perl executable, so you will need one installed to run this example. Note: this could be any executable that returns to standard out, not just perl.

    This will register the class weblogic.servlet.CGIServlet as a servlet, and map all requests to /examplesWebApp/cgi-bin/*.pl to perl CGI scripts, running the perl executable on each one before the WebLogic Server outputs the result.

Start the examplesServer

  1. Start the server with the examples configuration.

  2. Bring up the Administration Console in your browser.

  3. Make sure that the examplesWebApp is deployed on your server.

Run the Example

  1. Use a browser to call the CGI script, with a URL that follows the pattern:
      http://WebLogicURL:WebLogicPort/examplesWebApp/cgi-bin/HelloWorld.pl
    For example, this is how you load the HelloWorld.pl example in a browser running on the same NT host as your WebLogic Server, on port 7001:
    http://localhost:7001/examplesWebApp/cgi-bin/HelloWorld.pl

There's More...