Top Description Inners Fields Constructors Methods
org.mortbay.servlet

public Class CGI

extends HttpServlet
Class Inheritance
Imports
java.io.BufferedReader, .File, .IOException, .InputStream, .InputStreamReader, .OutputStream, .PrintWriter, java.util.Enumeration, .HashMap, .Map, javax.servlet.ServletException, javax.servlet.http.HttpServlet, .HttpServletRequest, .HttpServletResponse, org.mortbay.log.Log, org.mortbay.util.IO, .StringUtil

CGI Servlet. The cgi bin directory can be set with the "cgibinResourceBase" init parameter or it will default to the resource base of the context. The "commandPrefix" init parameter may be used to set a prefix to all commands passed to exec. This can be used on systems that need assistance to execute a particular file type. For example on windows this can be set to "perl" so that perl scripts are executed. The "Path" init param is passed to the exec environment as PATH.

Note

Must be run unpacked somewhere in the filesystem. Any initParameter that starts with ENV_ is used to set an environment variable with the name stripped of the leading ENV_ and using the init parameter value.

Authors
Julian Gosnell, Thanassis Papathanasiou - Some minor modifications for Jetty6 port

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
CGI.EnvList

private utility class that manages the Environment passed to exec.

Field Summary

Modifier and TypeField and Description
private String
private File
private CGI.EnvList
private boolean
private boolean
private String

Constructor Summary

AccessConstructor and Description
public
CGI()

Method Summary

Modifier and TypeMethod and Description
private void
exec(File command, String pathInfo, HttpServletRequest req, HttpServletResponse res)

private String

Returns:

the line of text
getTextLineFromStream
(InputStream
the input stream
is
)

Utility method to get a line of text from the input stream.

public void
init()

Overrides javax.servlet.GenericServlet.init.

A convenience method which can be overridden so that there's no need to call super.init(config).
public void
service(HttpServletRequest
the HttpServletRequest object that contains the request the client made of the servlet
req
,
HttpServletResponse
the HttpServletResponse object that contains the response the servlet returns to the client
res
)

Overrides javax.servlet.http.HttpServlet.service.

Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class.
Inherited from javax.servlet.http.HttpServlet:
doDeletedoGetdoHeaddoOptionsdoPostdoPutdoTracegetLastModifiedservice

Field Detail

_cmdPrefixback to summary
private String _cmdPrefix
_docRootback to summary
private File _docRoot
_envback to summary
private CGI.EnvList _env
_ignoreExitStateback to summary
private boolean _ignoreExitState
_okback to summary
private boolean _ok
_pathback to summary
private String _path

Constructor Detail

CGIback to summary
public CGI()

Method Detail

execback to summary
private void exec(File command, String pathInfo, HttpServletRequest req, HttpServletResponse res) throws IOException
getTextLineFromStreamback to summary
private String getTextLineFromStream(InputStream is) throws IOException

Utility method to get a line of text from the input stream.

Parameters
is:InputStream

the input stream

Returns:String

the line of text

initback to summary
public void init() throws ServletException

Overrides javax.servlet.GenericServlet.init.

Doc from javax.servlet.GenericServlet.init.

A convenience method which can be overridden so that there's no need to call super.init(config).

Instead of overriding init(ServletConfig), simply override this method and it will be called by GenericServlet.init(ServletConfig config). The ServletConfig object can still be retrieved via getServletConfig.

Exceptions
ServletException:
if an exception occurs that interrupts the servlet's normal operation
serviceback to summary
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException

Overrides javax.servlet.http.HttpServlet.service.

Doc from javax.servlet.http.HttpServlet.service.

Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class. This method is an HTTP-specific version of the javax.servlet.Servlet#service method. There's no need to override this method.

Parameters
req:HttpServletRequest

the HttpServletRequest object that contains the request the client made of the servlet

res:HttpServletResponse

the HttpServletResponse object that contains the response the servlet returns to the client

Exceptions
ServletException:
if the HTTP request cannot be handled
IOException:
if an input or output error occurs while the servlet is handling the HTTP request
org.mortbay.servlet back to summary

private Class CGI.EnvList

extends Object
Class Inheritance

private utility class that manages the Environment passed to exec.

Field Summary

Modifier and TypeField and Description
private Map<K, V>

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String[]
getEnvArray()

Get representation suitable for passing to exec.

public void
set(String name, String value)

Set a name/value pair, null values will be treated as an empty String

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

envMapback to summary
private Map<K, V> envMap

Constructor Detail

EnvListback to summary
pack-priv EnvList()
EnvListback to summary
pack-priv EnvList(CGI.EnvList l)

Method Detail

getEnvArrayback to summary
public String[] getEnvArray()

Get representation suitable for passing to exec.

setback to summary
public void set(String name, String value)

Set a name/value pair, null values will be treated as an empty String

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object