NonStop Servlets for JavaServer Pages (5.0) System Administrator's Guide

Programming and Management Features
NonStop Servlets for JavaServer Pages (NSJSP) System Administrator’s Guide525644-002
4-6
Obtaining Specific CGI Environment Variable Values
Obtaining Specific CGI Environment Variable Values
To obtain the value of a specific CGI environment variable, use the
getHeaderNames() or getAttribute() methods 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 4-1 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, a series of
requests to the servlet class may not be serviced by the same process. This situation
has 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 run in the same data space.
Therefore, a servlet that needs 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 services a series of requests is to limit the web container
to one process (Maxservers=1). A ServerClass limited in this way retains the quality
of persistence but loses the scalability advantage of a ServerClass. To support
sessions, the web container’s Numstatic and Maxservers attributes must have the
same value unless you are using persistent sessions and turn off session-based load
balancing. For information about turning off session-based load balancing.
Multithreading – Spawning Java Threads
The NSJSP product supports spawning Java threads from within a servlet or JSP.
When multiple users access a servlet simultaneously, the web container does not
instantiate a new servlet instance for each user. When a client access the servlet, the
service() method is invoked in a separate thread. Therefore, each client is sharing
Example 4-1. 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>");