| Programmer's Guide
|
|
Servlet Programming Techniques
|
Servlet API packages
The Servlet API is a specification published by the Java Software division of Sun Microsystems. It outlines classes, methods, and behaviors required by Java Servlets and servers that support Java Servlets. JRun Version 4.0 supports the Java Servlet Specification Version 2.3.
The Servlet API includes the following packages:
javax.servlet
javax.servlet.http
JRun ships with full online Servlet API documentation, located in jrun_root/docs/api. You can also access the latest API documentation from http://java.sun.com/products/servlet.
javax.servlet
The javax.servlet package contains interfaces, classes, and exceptions that apply to all servlets, as the following tables explain.
javax.servlet interfaces
The following table describes the interfaces in javax.servlet:
| Interface |
Description |
RequestDispatcher
|
Defines an object that forwards processing of a request to another servlet, JSP, or HTML file. Also lets you include the output of another servlet in the response. |
Servlet
|
Defines methods to initialize a servlet instance, process a request, and destroy a servlet instance. The GenericServlet class implements this interface. |
ServletConfig
|
Defines an object that passes information to the servlet's init method. Contains name/value pairs, the servlet's name, and a reference to the web application's ServletContext object. |
ServletContext
|
Defines methods that a servlet uses to access information about the servlet container. Also includes application init parameters. There is one ServletContext per web application per virtual machine. |
ServletRequest
|
Defines an object that encapsulates client request information. Each instance includes name/value pairs, attributes, and an input stream. |
ServletResponse
|
Defines an object that encapsulates information returned to the client. You can send binary data or character data. |
SingleThreadModel
|
Defines an object that ensures that each servlet instance executes only one request at a time. For more information on this interface, see the servlet API JavaDoc. |
javax.servlet classes
The following table describes the classes in javax.servlet:
| Class |
Description |
GenericServlet
|
Protocol-independent servlet. You typically use HttpServlet instead of this class. |
ServletInputStream
|
Stream for reading binary data from a client request. You typically do not use this class. |
ServletOutputStream
|
Stream for sending binary data to a client. You typically do not use this class. |
javax.servlet exceptions
The following table describes the exceptions in javax.servlet:
| Exception |
Description |
ServletException
|
Indicates problems in a servlet. |
UnavailableException
|
Indicates that a servlet is unavailable. You can use this exception to indicate either temporary or permanent unavailability. |
javax.servlet.http
The javax.servlet.http package contains interfaces and classes that apply to servlets requiring HTTP functionality, as the following tables explain.
javax.servlet.http interfaces
The following table describes the interfaces in javax.servlet.http:
| Interface |
Description |
HttpServletRequest
|
Extends ServletRequest for HTTP servlets. Use this object to access cookies, attributes, and other information for the request. |
HttpServletResponse
|
Extends ServletResponse for HTTP servlets. Use this object to send a response to the browser. |
HttpSession
|
Contains user information that persists across page requests. Sessions are keyed by session ID, which is maintained either in cookies or by URL parameters. |
HttpSessionBinding
Listener
|
Notifies objects when they are bound or unbound from a session. Use this interface to initialize and clean up session-specific resources. |
javax.servlet.http classes
The following table describes the classes in javax.servlet.http:
| Class |
Description |
Cookie
|
Lets servlets create, read, and modify client cookies. Read cookies using the HttpServletRequest object. Set cookies using the HttpServletResponse object. |
HttpServlet
|
Abstract class that you extend to create HTTP servlets. Use this class for all web-oriented servlets. |
HttpSessionBindingEvent
|
Contains two methods, getName and getSession. Passed to objects that implement the HttpSessionBindingListener interface when they are bound or unbound from a session. |
HttpUtils
|
Contains useful utility methods. Methods include getRequestURL, parsePostData, and parseQueryString. |