| Interface
/ Class
|
Method
|
Description
|
|
Servlet
|
init(ServletConfig) |
Called by the servlet container to indicate to a
servlet that the servlet is being placed into
service. |
| destroy() |
Called by the servlet container to indicate to a
servlet that the servlet is being taken out of
service. |
| service(ServletRequest, ServletResponse) |
Called by the servlet container to allow the
servlet to respond to a request. |
| ServletConfig getServletConfig() |
Returns a ServletConfig object,
which contains initialization and startup parameters
for this servlet. |
| String getServletInfo |
Returns information about the servlet, such as
author, version, and copyright. |
| ServletConfig
|
String getInitParameter(String) |
Returns a String
containing the value of the named initialization
parameter, or null
if the parameter does not exist. |
| Enumeration getInitParameterNames() |
Returns the names of the servlet's initialization
parameters as an Enumeration
of String
objects, or an empty Enumeration
if the servlet has no initialization parameters. |
| ServletContext getServletContext() |
Returns a reference to the ServletContext in
which the caller is executing. |
| String getServletName() |
Returns the name of this servlet instance. The
name may be provided via server administration,
assigned in the web application deployment
descriptor, or for an unregistered (and thus
unnamed) servlet instance it will be the servlet's
class name. |
| ServletContext
|
String getInitParameter(String) |
Returns a String
containing the value of the named context-wide
initialization parameter, or null
if the parameter does not exist. |
| Enumeration getInitParameterNames() |
Returns the names of the context's initialization
parameters as an Enumeration
of String
objects, or an empty Enumeration
if the context has no initialization parameters. |
| Object getAttribute(String) |
Returns the servlet container attribute with the
given name, or null
if there is no attribute by that name. |
| setAttribute(String, Object) |
Binds an object to a given attribute name in this
servlet context. |
| removeAttribute(String) |
Removes the attribute with the given name from
the servlet context. |
| Enumeration getAttributeNames() |
Returns an Enumeration
containing the attribute names available within this
servlet context. |
| log(String) |
Writes the specified message to a servlet log
file, usually an event log. |
| log(String, Throwable) |
Writes an explanatory message and a stack trace
for a given Throwable
exception to the servlet log file. |
| ServletContext getContext(String uripath) |
Returns a ServletContext
object that corresponds to a specified URL on the
server. The given path must be absolute (beginning
with "/") and is interpreted based on the
server's document root. |
| String getRealPath(String path) |
Returns a String
containing the real path for a given virtual path. |
| java.net.URL getResource(String path) |
Returns a URL to the resource that is mapped to a
specified path. The path must begin with a
"/" and is interpreted as relative to the
current context root. |
| ServletContext
|
java.net.URL getResource(String path) |
This method allows the servlet container to make
a resource available to servlets from any source.
Resources can be located on a local or remote file
system, in a database, or in a .war
file. The resource content is returned directly, so
be aware that requesting a .jsp
page returns the JSP source code. Use a RequestDispatcher
instead to include results of an execution.
This method has a different purpose than java.lang.Class.getResource,
which looks up resources based on a class loader.
This method does not use class loaders. |
| java.io.InputStream
getResourceAsStream(String path)
|
Returns the resource located at the named path as
an InputStream
object. |
| RequestDispatcher getRequestDispatcher(String
path) |
Returns a RequestDispatcher object that acts as a
wrapper for the resource located at the given path.
The resource can be dynamic or static.
The pathname must begin with a "/"
and is interpreted as relative to the current
context root. Use getContext
to obtain a RequestDispatcher
for resources in foreign contexts. This method
returns null
if the ServletContext
cannot return a RequestDispatcher. |
| RequestDispatcher getNamedDispatcher(String name) |
Returns a RequestDispatcher object that acts as a
wrapper for the named servlet. |
|
ServletRequest
|
Object getAttribute(String) |
Returns the value of the named attribute as an Object,
or null
if no attribute of the given name exists. |
| setAttribute(String, Object) |
Stores an attribute in this request. |
| removeAttribute(String) |
Removes an attribute from this request. |
| Enumeration getAttributeNames() |
Returns an Enumeration
containing the names of the attributes available to
this request. This method returns an empty Enumeration
if the request has no attributes available to it. |
| String getParameter(String) |
Returns the value of a request parameter as a String,
or null
if the parameter does not exist. |
| String[] getParameterValues(String) |
Returns an array of String
objects containing all of the values the given
request parameter has, or null
if the parameter does not exist. |
| Enumeration getParameterNames() |
Returns an Enumeration
of String
objects containing the names of the parameters
contained in this request. |
| ServletInputStream getInputStream() |
Retrieves the body of the request as binary data
using a ServletInputStream. Either this method or
getReader() may be called to read the body, not
both. |
| BufferedReader getReader() |
Retrieves the body of the request as character
data using a BufferedReader.
The reader translates the character data according
to the character encoding used on the body.
Either this method or getInputStream() may be
called to read the body, not both.
|
| RequestDispatcher getRequestDispatcher(String
path) |
Returns a RequestDispatcher
object that acts as a wrapper for the resource
located at the given path. A RequestDispatcher
object can be used to forward a request to the
resource or to include the resource in a response.
The resource can be dynamic or static. |
| ServletRequest
|
RequestDispatcher getRequestDispatcher(String
path) |
The pathname specified may be relative, although
it cannot extend outside the current servlet
context. If the path begins with a "/" it
is interpreted as relative to the current context
root. This method returns null
if the servlet container cannot return a RequestDispatcher.
The difference between this method and
ServletContext’s method is that this method can
take a relative path.
|
| String getRemoteAddr() |
Returns the Internet Protocol (IP) address of the
client that sent the request. |
| String getRemoteHost() |
Returns the fully qualified name of the client
that sent the request, or the IP address of the
client if the name cannot be determined. |
| String getServerName() |
Returns the host name of the server that received
the request. |
| int getServerPort() |
Returns the port number on which this request was
received. |
| String getProtocol() |
Returns the name and version of the protocol the
request uses in the form protocol/majorVersion.minorVersion,
for example, HTTP/1.1. |
| String getScheme() |
Returns the name of the scheme used to make this
request, for example, http,
https,
or ftp.
|
| boolean isSecure() |
Returns a boolean indicating whether this request
was made using a secure channel, such as HTTPS. |
| String getContentType() |
Returns the MIME type of the body of the request,
or null
if the type is not known. |
| int getContentLength() |
Returns the length, in bytes, of the request body
and made available by the input stream, or -1 if the
length is not known. |
| String getCharecterEncoding() |
Returns the name of the character encoding used
in the body of this request. |
| setCharecterEncoding(String) |
Overrides the name of the character encoding used
in the body of this request. |
| ServletResponse
|
ServletOutputStream getOutputStream() |
Returns a ServletOutputStream suitable for
writing binary data in the response. The servlet
container does not encode the binary data. Calling
flush() on the ServletOutputStream commits the
response. Either this method or getWriter() may be
called to write the body, not both |
| PrintWriter getWriter() |
Returns a PrintWriter
object that can send character text to the client.
The character encoding used is the one specified in
the charset=
property of the setContentType method, which must be
called before calling this method for the charset to take effect.
Calling flush() on the PrintWriter commits the
response.
Either this method or getOutputStream may be
called to write the body, not both.
|
| setContentType(java.lang.String type)
|
Sets the content type of the response being sent
to the client. The content type may include the type
of character encoding used, for example, text/html;charset=ISO-8859-4.
If obtaining a PrintWriter,
this method should be called first.
|
| setContentLength(int) |
Sets the length of the content body in the
response. In HTTP servlets, this method sets the
HTTP Content-Length header. |
| boolean isCommitted() |
Returns a boolean indicating if the response has
been committed. A commited response has already had
its status code and headers written. |
| ServletResponse
|
reset() |
Clears any data that exists in the buffer as well
as the status code and headers. If the response has
been committed, this method throws an IllegalStateException. |
| int getBufferSize() |
Returns the actual buffer size used for the
response. If no buffering is used, this method
returns 0. |
| setBufferSize(int) |
Sets the preferred buffer size for the body of
the response.
This method must be called before any response
body content is written; if content has been
written, this method throws an IllegalStateException.
|
| flushBuffer() |
Forces any content in the buffer to be written to
the client. A call to this method automatically
commits the response, meaning the status code and
headers will be written. |
| resetBuffer() |
Clears the content of the underlying buffer in
the response without clearing headers or status
code. If the response has been committed, this
method throws an IllegalStateException. |
| abstract
class GenericServlet implements Servlet,
ServletConfig, Serializable |
init() |
A convenience method which can be overridden so
that there's no need to call super.init(config). |
| log(String) |
Writes the specified message to a servlet log
file, prepended by the servlet's name. |
| log(String, Throwable) |
Writes an explanatory message and a stack trace
for a given Throwable
exception to the servlet log file, prepended by the
servlet's name. |
| abstract service() |
Called by the servlet container to allow the
servlet to respond to a request.
This method is declared abstract so subclasses,
such as HttpServlet,
must override it.
|
| HttpServletRequest
|
String getHeader(String) |
Returns the value of the specified request header
as a String.
If the request did not include a header of the
specified name, this method returns null.
The header name is case insensitive. You can use
this method with any request header. |
| Enumeration getHeaders(String) |
Returns all the values of the specified request
header as an Enumeration
of String
objects. If the request did not include any headers
of the specified name, this method returns an empty Enumeration.
The header name is case insensitive. You can use
this method with any request header. |
| Enumeration getHeaderNames() |
Returns an enumeration of all the header names
this request contains. If the request has no
headers, this method returns an empty enumeration. |
| int getIntHeader(String) |
Returns the value of the specified request header
as an int.
If the request does not have a header of the
specified name, this method returns -1. If the
header cannot be converted to an integer, this
method throws a NumberFormatException. |
| long getDateHeader(String) |
Returns the value of the specified request header
as a long
value that represents a Date
object. Use this method with headers that contain
dates, such as If-Modified-Since.
If the request did not have a header of the
specified name, this method returns -1. |
| Cookie getCookies() |
Returns an array containing all of the Cookie
objects the client sent with this request, or null
if no cookies sent. |
| HttpSession getSession() |
Returns the current session associated with this
request, or if the request does not have a session,
creates one. |
| HttpServletRequest |
HttpSession getSession(boolean create) |
Returns the current HttpSession
associated with this request or, if if there is no
current session and create
is true, returns a new session. |
| String getRequestURI() |
Returns the part of this request's URL from the
protocol name up to the query string in the first
line of the HTTP request.
requestURI
= contextPath + servletPath + pathInfo
|
| String getContextPath() |
Returns the portion of the request URI that
indicates the context of the request. The context
path always comes first in a request URI. The path
starts with a "/" character but does not
end with a "/" character. For servlets in
the default (root) context, this method returns
"". |
| String getServletPath() |
Returns the part of this request's URL that calls
the servlet. This includes either the servlet name
or a path to the servlet, but does not include any
extra path information or a query string. |
| String getPathInfo() |
Returns any extra path information associated
with the URL the client sent when it made this
request. The extra path information follows the
servlet path but precedes the query string. This
method returns null
if there was no extra path information. |
| String getPathTranslated() |
Returns any extra path information after the
servlet name but before the query string, and
translates it to a real path. |
| String getQueryString() |
Returns the query string that is contained in the
request URL after the path. |
| String getMethod() |
Returns the name of the HTTP method with which
this request was made, for example, GET, POST, or
PUT. |
| String getAuthType() |
Returns the name of the authentication scheme
used to protect the servlet. All servlet containers
support BASIC_AUTH, FORM_AUTH, and CLIENT_CERT_AUTH
and may support DIGEST_AUTH. If the servlet is not
authenticated null
is returned. |
| String getRemoteUser() |
Returns the login of the user making this
request, if the user has been authenticated, or null
if the user has not been authenticated. |
| Principal getUserPrincipal() |
Returns a java.security.Principal
object containing the name of the current
authenticated user. If the user has not been
authenticated, the method returns null. |
| boolean isUserInRole(String role) |
Returns a boolean indicating whether the
authenticated user is included in the specified
logical "role". Roles and role membership
can be defined using deployment descriptors. If the
user has not been authenticated, the method returns false. |
| String getRequestedSessionId() |
Returns the session ID specified by the client.
This may not be the same as the ID of the actual
session in use. For example, if the request
specified an old (expired) session ID and the server
has started a new session, this method gets a new
session with a new ID. If the request did not
specify a session ID, this method returns null. |
| boolean isRequestedSessionIdValid() |
Checks whether the requested session ID is still
valid. |
| boolean isRequestedSessionIdFromCookie() |
Checks whether the requested session ID came in
as a cookie. |
| boolean isRequestedSessionIdFromURL()
|
Checks whether the requested
session ID came in as part of the request URL. |
| HttpServletResponse |
addCookie(Cookie) |
Adds the specified cookie to the response. This
method can be called multiple times to set more than
one cookie. |
| addHeader(String name, String value) |
Add a response header with the given name and
String value / integer value / date value
respectively. These methods allow response headers
to have multiple values. |
| addIntHeader(String name, int value) |
| addDateHeader(String name, long value) |
| setHeader(String name, String value) |
Set a response header with the given name and
String value / integer value / date value
respectively. If the header had already been set,
the new value overwrites the previous one. The containsHeader
method can be used to test for the presence of a
header before setting its value. |
| setIntHeader(String name, int value) |
| setDateHeader(String name, long value) |
| setStatus(int sc)
|
Sets the status code for this response. This
method is used to set the return status code when
there is no error (for example, for the status codes
SC_OK or SC_MOVED_TEMPORARILY). If there is an
error, and the caller wishes to invoke an error-page
defined in the web applicaion, the sendError
method should be used instead.
If this method is called after the response is
committed, the call is ignored.
|
| sendError(int sc)
sendError(int sc, java.lang.String msg)
|
Sends an error response to the client using the
specified status clearing the buffer. The server
defaults to creating the response to look like an
HTML-formatted server error page, setting the
content type to "text/html", leaving
cookies and other headers unmodified. If an
error-page declaration has been made for the web
application corresponding to the status code passed
in, it will be served back in preference to the
suggested msg parameter.
If the response has already been committed, this
method throws an IllegalStateException. After using
this method, the response should be considered to be
committed and should not be written to.
|
| sendRedirect(java.lang.String location)
|
Sends a temporary redirect response to the client
using the specified redirect location URL. This
method can accept relative URLs; the servlet
container must convert the relative URL to an
absolute URL before sending the response to the
client. If the location is relative without a
leading '/' the container interprets it as relative
to the current request URI. If the location is
relative with a leading '/' the container interprets
it as relative to the servlet container root.
If the response has already been committed, this
method throws an IllegalStateException. After using
this method, the response should be considered to be
committed and should not be written to.
|
| String encodeURL(java.lang.String url)
|
Encodes the specified URL by including the
session ID in it, or, if encoding is not needed,
returns the URL unchanged.
For
robust session tracking, all URLs emitted by a
servlet should be run through this method.
Otherwise, URL rewriting cannot be used with
browsers which do not support cookies.
|
| String encodeRedirectURL(String url) |
Encodes the specified URL for use in the sendRedirect
method or, if encoding is not needed, returns the
URL unchanged.
All URLs sent to the HttpServletResponse.sendRedirect
method should be run through this method. Otherwise,
URL rewriting cannot be used with browsers which do
not support cookies.
|
|
HttpSession
|
Object getAttribute(String) |
Returns the object bound with the specified name
in this session, or null
if no object is bound under the name. |
| setAttribute(String, Object) |
Binds an object to a given attribute name in this
session. If an object of the same name is already
bound to the session, the object is replaced.
After this method executes, and if the new object
implements HttpSessionBindingListener,
the container calls HttpSessionBindingListener.valueBound.
If an object was already bound to this session of
this name that implements HttpSessionBindingListener,
its HttpSessionBindingListener.valueUnbound
method is called.
|
| removeAttribute(String) |
Removes the attribute with the given name from
the session. After this method executes, and if the
object implements HttpSessionBindingListener,
the container calls HttpSessionBindingListener.valueUnbound. |
| Enumeration getAttributeNames() |
Returns an Enumeration
of String
objects containing the names of all the objects
bound to this session. |
| String getId() |
Returns a string containing the unique identifier
assigned to this session. |
| long getCreationTime() |
Returns the time when this session was created |
| long getLastAccessedTime() |
Returns the last time the client sent a request
associated with this session |
| int getMaxInactiveInterval() |
Returns the maximum time interval, in seconds,
that the servlet container will keep this session
open between client accesses. After this interval,
the servlet container will invalidate the session.
The maximum time interval can be set with the setMaxInactiveInterval
method. A negative time indicates the session should
never timeout. |
| setMaxInactiveInterval(int) |
Specifies the time, in seconds, between client
requests before the servlet container will
invalidate this session. A negative time indicates
the session should never timeout. |
| invalidate() |
Invalidates this session then unbinds any objects
bound to it. |
| isNew() |
Returns true
if the client does not yet know about the session or
if the client chooses not to join the session. For
example, if the server used only cookie-based
sessions, and the client had disabled the use of
cookies, then a session would be new on each
request. |
|
abstract class HttpServlet extends
GenericServlet
Eventhough this class is abstract it provides
empty implementations of all methods. Typically
servlets extending this class would override one of
the doXXX methods.
|
public service(ServletRequest, ServletResponse) |
Dispatches client requests to the protected service
method. There's no need to override this method. |
| protected service(HttpServletRequest,
HttpServletResponse) |
Receives standard HTTP requests from the public service
method and dispatches them to the doXXX
methods defined in this class.
There's no need to override this method.
|
| doGet(HttpServletRequest, HttpServletResponse) |
Should be safe and idempotent (repeatable)
Override to service GET requests. HEAD requests
are also satisfied since doHead internally uses this
method with a specialized response.
|
| doPost(HttpServletRequest, HttpServletResponse) |
Need not be safe or idempotent.
Override to service POST requests.
|
| doPut(), doDelete(), doHead(), doTrace(),
doOptions() |
These methods are not common and service the
corresponding requests. |
| long getLastModified() |
Returns the time the HttpServletRequest
object was last modified |
| RequestDispatcher
|
forward(ServletRequest,
ServletResponse) |
Forwards a request from a servlet
to another resource (servlet, JSP file, or HTML
file) on the server. This method allows one servlet
to do preliminary processing of a request and
another resource to generate the response. forward
should be called before the response has been
committed to the client (before response body output
has been flushed). If the response already has been
committed, this method throws an IllegalStateException.
Uncommitted output in the response buffer is
automatically cleared before the forward. |
| include(ServletRequest,
ServletResponse) |
Includes the content of a resource
(servlet, JSP page, HTML file) in the response. In
essence, this method enables programmatic
server-side includes.
The ServletResponse object has its path elements
and parameters remain unchanged from the caller's.
The included servlet cannot change the response
status code or set headers; any attempt to make a
change is ignored.
|
| SingleThreadModel
|
No methods |
This is a ‘marker’ interface |
| ServletContext
Listener
|
contextInitialized(ServletContextEvent) |
Implementations of this interface
receive notifications about changes to the servlet
context of the web application they are part of. To
receive notification events, the implementation
class must be configured in the deployment
descriptor for the web application. |
| contextDestroyed(ServletContextEvent) |
| ServletContext
AttributeListener |
attributeAdded
(ServletContextAttributeEvent)
|
Implementations of this interface
receive notifications of changes to the attribute
list on the servlet context of a web application. To
receive notification events, the implementation
class must be configured in the deployment
descriptor for the web application.
|
|
attributeRemoved
(ServletContextAttributeEvent)
|
|
attributeReplaced
(ServletContextAttributeEvent)
|
| HttpSession
Listener
|
sessionCreated(HttpSessionEvent)
|
Implementations of this interface
are notified of changes to the list of active
sessions in a web application. To receive
notification events, the implementation class must
be configured in the deployment descriptor for the
web application. |
|
sessionDestroyed(HttpSessionEvent)
|
| HttpSession
AttributeListener
|
attributeAdded
(HttpSessionBindingEvent)
|
This listener interface can be
implemented in order to get notifications of changes
made to sessions within this web application. |
|
attributeRemoved
(HttpSessionBindingEvent)
|
|
attributeReplaced
(HttpSessionBindingEvent)
|
| HttpSession
ActivationListener
|
sessionDidActivate(HttpSessionEvent)
|
Objects that are bound to a session
may listen to container events notifying them that
sessions will be passivated and that session will be
activated. A container that migrates session between
VMs or persists sessions is required to notify all
attributes bound to sessions implementing
HttpSessionActivationListener. |
|
sessionWillPassivate(HttpSessionEvent)
|
| HttpSession
BindingListener
|
valueBound(HttpSessionBindingEvent)
|
Causes an object to be notified
when it is bound to or unbound from a session. The
object is notified by an HttpSessionBindingEvent
object. This may be as a result of a servlet
programmer explicitly unbinding an attribute from a
session, due to a session being invalidated, or die
to a session timing out. |
|
valueUnbound
(HttpSessionBindingEvent)
|