|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.servlet.GenericServlet | +--javax.servlet.http.HttpServlet | +--com.mortbay.Servlets.SessionDump
This is an example of a simple Servlet
Constructor Summary | |
SessionDump()
|
Method Summary | |
void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Receives an HTTP GET request from the protected service method and handles the request. |
void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Receives an HTTP POST request from the protected service method and handles the request. |
java.lang.String |
getServletInfo()
Returns a String that contains information about
the servlet such as its author, version, and copyright information. |
void |
init(javax.servlet.ServletConfig config)
Initializes this servlet. |
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete,
doOptions,
doPut,
doTrace,
getLastModified,
service,
service |
Methods inherited from class javax.servlet.GenericServlet |
destroy,
getInitParameter,
getInitParameterNames,
getServletConfig,
getServletContext,
init,
log,
log |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public SessionDump()
Method Detail |
public void init(javax.servlet.ServletConfig config) throws javax.servlet.ServletException
The servlet engine calls this method once,
automatically, each time it loads the servlet. This
method is guaranteed to finish before the servlet accepts any
requests to its service
method. If a fatal
error occurs while the servlet is being initialized,
the servlet engine should throw
an UnavailableException
, rather than
calling the System.exit
method.
The init
method stores the
ServletConfig
object it receives from the servlet engine. If you override init
,
you should either call super.init
or store the ServletConfig
object in the new
init
method. If you decide to store the
ServletConfig
object in a different location,
you should also override the GenericServlet.getServletConfig()
method.
config
- the ServletConfig
object
that contains initialization parameters
for this servletUnavailableException
public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
service
method and handles the request.
The HTTP POST method allows the client to send
data of unlimited length to the Web server once
and is useful when posting information such as
credit card numbers.
If you override this method, you should read data from
the HttpServletRequest
object, set headers
for the response (including Content-Type and Content-Encoding),
access a PrintWriter
or
output stream object, and then write any response data
using a ServletOutputStream
object.
If you use a PrintWriter
object to
write response data, set the Content-Type header before
you access the PrintWriter
object.
The servlet engine must write the headers before the
the response data, because the headers can be flushed at
any time after the servlet engine begins to write the body
of the response.
If you use HTTP 1.1 chunked encoding (which means that the response has a Transfer-Encoding header), do not set the Content-Length header. If you do not use chunked encoding, set the content length to allow the servlet to take advantage of the HTTP "connection keep alive" feature, If you cannot set the content length and therefore cannot use "keep alive," you may be able to avoid the performance penalty if the response fits in an internal buffer.
This method does not need to be either safe or idempotent. Operations requested through POST can have side effects for which the user can be held accountable, for example, updating stored data or buying items online.
If the HTTP POST request is incorrectly formatted,
doPost
returns an HTTP BAD_REQUEST message.
req
- an HttpServletRequest
object that
contains the request the client has made
of the servletresp
- an HttpServletResponse
object that
contains the response the servlet sends
to the objectServletOutputStream
,
ServletResponse.setContentType(java.lang.String)
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
service
method and handles the request.
The GET method allows a client to read information
from the Web server, passing a query string appended
to an URL to tell the server what information
to return.
Overriding this method to support a GET request also automatically supports an HTTP HEAD request. A HEAD request is a GET request that returns no body in the response, only the request header fields.
If you override this method, you should read data from
the request, set entity headers in the response,
access the writer or output stream object, and finally,
write the response data. When you set headers, be
sure to include content type and encoding. If you use
a PrintWriter
object to return the response,
you must set the content type before you access the
PrintWriter
object.
The servlet engine must write the headers before the response data, because the headers can be flushed at any time after the data is written.
If you can set the Content-Length header (with the
javax.servlet.ServletResponse.#contentType
method),
the servlet
can use a persistent connection to return its response
to the client, improving performance dramatically.
If you cannot set Content-Length, you can sometimes avoid
the performance penalty if the response fits in an internal
buffer.
The GET method should be safe, that is, without any side effects for which users are held responsible. For example, most form queries have no side effects. If a client request is intended to change stored data, the request should use some other HTTP method.
The GET method should also be idempotent, meaning that it can be safely repeated. Sometimes making a method safe also makes it idempotent. For example, repeating queries is both safe and idempotent, but buying a product online or modifying data is neither safe nor idempotent.
If the request is incorrectly formatted, doGet
returns an HTTP BAD_REQUEST message.
req
- an HttpServletRequest
object that
contains the request the client has made
of the servletresp
- an HttpServletResponse
object that
contains the response the servlet sends
to the objectServletResponse.setContentType(java.lang.String)
public java.lang.String getServletInfo()
String
that contains information about
the servlet such as its author, version, and copyright information.
You must override this method before it returns this information.
If you do not override this method, it returns an empty string.String
until
you override this method
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |