iTP Secure WebServer System Administrator's Guide (iTPWebSvr 6.0+)
Using NonStop Servlets for JavaServer Pages
(NSJSP)
iTP Secure WebServer System Administrator’s Guide—523346-002
9-33
Obtaining Specific CGI Environment Variable Values
ServletException
This class provides methods for reporting servlet-specific exceptions. The doGet()
and doPost() methods of your servlet should use this class, or a class you derive
from this class, to report an error.
HttpUtils
This class provides a method to parse a query string or other form-encoded data.
Obtaining Specific CGI Environment Variable Values
To obtain the value of a specific CGI environment variable, use the getAttribute()
method with the string parameter value
"com.tandem.servlet.parameter-name"
where parameter_name is the name of the desired environment variable.
The code fragment in Example 9-2 illustrates the use of getAttribute to obtain and
print an enumeration of environment variables and their values:
Context-Management
Because the same servlet or JSP can be running in multiple processes in the same
web container, a series of requests to the servlet class may not be serviced by the
same process. This situation has important implications for the design of a servlet:
•
No data maintained by a servlet can be presumed to apply to the servlet class
collectively. Class data applies only within a process.
•
Context created in memory by one request may not be available to subsequent
requests, because subsequent requests might not execute in the same data space.
Therefore, a servlet that wishes to make context available should write the context
to disk before returning.
Unless you are using session tracking, a feature of the Servlet API, the only way to
ensure that the same process will service a series of requests is to limit the web
container to one process (Maxservers=1). A server class limited in this way retains the
quality of persistence but loses the scalability advantage of a server class. To support
Example 9-2. Use of getAttribute() Method to Obtain Environment Variables
out.println("</pre>");
Enumeration x =
(Enumeration)req.getAttribute("com.tandem.servlet.attribute_names");
out.println("<pre>");
while (x.hasMoreElements()) {
String pn = (String)x.nextElement();
out.println(pn +" = " + req.getAttribute(pn) );
}
out.println("</pre>");