To enable CGI (common gateway interface) processing for a specific web module, add the CGIServlet to your web.xml file as follows:
<web-app> <servlet> <servlet-name>cgi</servlet-name> <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class> </servlet> ... <servlet-mapping> <servlet-name>cgi</servlet-name> <url-pattern>/cgi-bin/*</url-pattern> </servlet-mapping> </web-app>
To enable CGI processing for all web modules, un-comment the corresponding sections in the default-web.xml file.
Package the CGI program under the cgiPathPrefix. The default cgiPathPrefix is WEB-INF/cgi. For security, it is highly recommended that the contents and binaries of CGI programs be prohibited from direct viewing or download. For information about hiding directory listings, see Using the default-web.xml File.
Invoke the CGI program using a URL of the following format:
http://host:8080/context-root/cgi-bin/cgi-name |
For example:
http://localhost:8080/mycontext/cgi-bin/hello |
You can configure the following init-param values for the CGIServlet.
Table 7–3 CGIServlet init-param Values
init-param |
Type |
Default |
Description |
---|---|---|---|
cgiPathPrefix |
String |
WEB-INF/cgi |
Specifies the subdirectory containing the CGI programs. |
debug |
int |
0 (for no debugging) |
Specifies the debugging level. |
executable |
String |
perl |
Specifies the executable for running the CGI script. |
parameterEncoding |
String |
System.getProperty("file.encoding", "UTF-8") |
Specifies the parameter's encoding. |
passShellEnvironment |
boolean |
false |
Specifies whether to pass shell environment properties to the CGI program. |
To work with a native executable, do the following:
Set the value of the init-param named executable to an empty String in the web.xml file.
Make sure the executable has its executable bits set correctly.
Use directory deployment to deploy the web module. Do not deploy it as a WAR file, because the executable bit information is lost during the process of jar and unjar. For more information about directory deployment, see the Sun GlassFish Enterprise Server v3 Prelude Application Deployment Guide.