Configuring WebLogic Server to Use CGI

7-6 Developing Web Applications, Servlets, and JSPs for Oracle WebLogic Server

7.7 Using CGI with WebLogic Server

WebLogic Server supports all CGI scripts through an internal WebLogic servlet called the CGIServlet. To use CGI, register the CGIServlet in the Web application deployment descriptor. See Section 3.4, Configuring How a Client Accesses a Web Application .

7.7.1 Configuring WebLogic Server to Use CGI

To configure CGI in WebLogic Server: 1. Declare the CGIServlet in your Web application by using the servlet and servlet-mapping elements in the J2EE standard Web application deployment descriptor, web.xml. The web.xml file is located in the WEB-INF directory of your Web application. The class name for the CGIServlet is weblogic.servlet.CGIServlet. You do not need to package this class in your Web application. 2. Register the following initialization attributes for the CGIServlet by defining the following init-param elements: ■ cgiDir—The path to the directory containing your CGI scripts. You can specify multiple directories, separated by a ; Windows or a : UNIX. If you do not specify cgiDir, the directory defaults to a directory named cgi-bin under the Web application root. ■ useByteStream—By default, character streams are used to read the output of CGI scripts. When scripts produce binary data, the stream may become corrupted due to character encoding. Use the useByteStream parameter to keep the stream from becoming corrupted. Using this parameter for ascii output also improves performance. ■ extension mapping—Maps a file extension to the interpreter or executable that runs the script. If the script does not require an executable, this initialization attribute may be omitted. ■ The param-name for extension mappings must begin with an asterisk followed by a dot, followed by the file extension, for example, .pl. ■ The param-value contains the path to the interpreter or executable that runs the script. You can create multiple mappings by creating a separate init-param element for each mapping. Example 7–5 Example Web Application Deployment Descriptor Entries for Registering the CGIServlet servlet servlet-nameCGIServletservlet-name Note: Because the ClasspathServlet serves any resource located in the system CLASSPATH, do not place resources that should not be publicly available in the system CLASSPATH. Note: WebLogic Server provides functionality to support your legacy Common Gateway Interface CGI scripts. For new projects, we suggest you use HTTP servlets or JavaServer Pages. Configuring Resources in a Web Application 7-7 servlet-classweblogic.servlet.CGIServletservlet-class init-param param-namecgiDirparam-name param-value beawlserver6.0configmydomainapplicationsmyWebAppcgi-bin param-value init-param init-param param-name.plparam-name param-valuebinperl.exeparam-value init-param servlet ... servlet-mapping servlet-nameCGIServletservlet-name url-patterncgi-binurl-pattern servlet-mapping

7.7.2 Requesting a CGI Script