http://www.javasoft.com/products/servlet/2.1/html/api-reference.fm.htmlThis appendix provides clarifications for using the following API with Enterprise Server 4.0:
public static StringBuffer getRequestURL(HttpServletRequest request);This method reconstructs the URL used by the client to make the given request on the server. This method accounts for difference in scheme (such as http, https) and ports, but does not attempt to include query parameters. This method returns a StringBuffer instead of a String so that the URL can be modified efficiently by the servlet
ServerName
in magnus.conf
. The server name by default is the machine name. But this value is editable while installing Enterprise Server 4.0. If the server name has been changed, HttpUtils.getRequestURL
might not return the host name that is needed to reconstruct the request.
For example, suppose the request is http://abc/index.html
. However, the server name has been changed to xyz
. In this case, HttpUtils.getRequestURL()
might return http://xyz/index.html
, which is not the original URL that was requested.
public int setMaxInactiveInterval(int interval);Sets the amount of time that a session can be inactive before the servlet engine is allowed to expire it.
int
is the previous value.
It is not possible to set the maximum inactive interval so that the session never times out. The session will always have a timeout value.
If you pass a negative or zero value, the session expires immediately.
public String getInitParameter(String name);
public String getInitParameter(String name);This method returns a String containing the value of the servlet's named initialization parameter, or null if this parameter does not exist.
public Enumeration getInitParameterNames();This method returns an enumeration of String objects containing the names of the initialization parameters for the calling servlet. If the calling servlet has no initialization parameters,
getInitParameterNames
returns an empty enumeration.
getInitParameter
and getInitParameterNames
for the class ServletConfig
only work for servlets that are invoked through virtual path translations. The same restriction applies to the convenience methods of the same names in the class GenericServlet
, which invoke the corresponding methods on ServletConfig
.
For information about setting virtual path translations, see the section Specifying Servlet Virtual Paths in Chapter 1, "Using Servlets and JavaServerPages."
These methods do not work if the servlet is invoked by a client request that specifies a servlet in a registered servlet directory rather than using a virtual path translation to access the servlet.
public ServletContext getContext(String uripath);Returns the servlet context object that contains servlets and resources for a particular URI path, or null if a context cannot be provided for the path.
uripath
) has been configured either through the Servlets>Configure Servlet attributes property of the Server Manager interface or by editing servlets.properties
.getContext()
is called from another servlet to get the context of an unloaded servlet.public void forward(ServletRequest request, ServletResponse response)Used for forwarding a request from this servlet to another resource on the web server. This method is useful when one servlet does preliminary processing of a request and wants to let another object generate the response. The request object passed to the target object will have its request URL path and other path parameters adjusted to reflect the target URL path of the target object. You cannot use this method if a
throws ServletException, IOException;
ServletOutputStream
object or PrintWriter
object has been obtained from the response. In that case, the method throws an IllegalStateException
.
public void include(ServletRequest request, ServletResponse response)Used for including the content generated by another server resource in the body of a response. In essence, this method enables programmatic server-side includes. The request object passed to the target object will reflect the request URL path and path info of the calling request. The response object only has access to the calling servlet's
throws ServletException, IOException
ServletOutputStream
object or PrintWriter
object.
An included servlet cannot set headers. If the included servlet calls a method that needs to set headers (such as cookies), the method is not guaranteed to work. As a servlet developer, you must ensure that any methods that might need direct access to headers are properly resolved. To ensure that a session works correctly, start the session outside the included servlet, even if you use session tracking.
dispatcher.forward(
) method may or may not throw an IllegalStateException
when either Writer
or OutputStream
have been obtained. This behavior follows the 2.2 draft and is needed for JSP error page handling. It throws the exception only if the actual data has been flushed out and sent to the client. Otherwise, the data pending in the buffer is simply discarded.
In the case of servlets in registered servlet directories and JSP, include()
flushes the output and headers before doing the include, which effectively causes any further calls to setHeader()
to have no effect. The same behavior occurs when forwarding to non-servlet URIs (like cgis or static files). In the case of statically-defined uri mapping rules setHeader()
might work until it exceeds the buffer.
The forward()
and include()
methods may throw a ServletException
if the target URI is identified as an unsafe URI (that is, it includes insecure path characters such as //
, /./
, /../
and/., /..
(and also ./
for NT) at the end of the URI.
request.InputStream()
method, an older method.request.getReader()
method, a method in use since 2.0.request.getContentLength()
.) However, if the servlet reads data using a BufferedReader returned from a call to getReader ()
, the allowed content length is automatically taken into the account.
Last Updated: 08/12/99 12:39:34
Copyright © 1999 Netscape Communications Corp. All rights reserved.