This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Javax.servlet package
Javax.servlet package The javax.servlet package provides interfaces and classes for writing servlets. The architecture of the package is described below. The Servlet Interface
The Servlet Interface
The central abstraction in the Servlet API is the Servlet interface. All servlets implement this interface, either directly or, more commonly, by extending a class that implements it such as HttpServlet Servlet Interface
Servlet Interface The Servlet interface declares, but does not implement, methods that manage the servlet and its communications with clients. Servlet writers provide some or all of these methods when developing a servlet. Client interaction
Client interaction When a servlet accepts a call from a client, it receives two objects: A ServletRequest , which encapsulates the communication from the client to the server. A ServletResponse , which encapsulates the communication from the servlet back to the client. ServletRequest and ServletResponse are interfaces defined by the javax.servlet package. The ServletRequest The ServletRequest The ServletRequest interface allows the servlet access to: Information such as the names of the parameters passed in by the client, the protocol (scheme) being used by the client, and the names of the remote host that made the request and the server that received it. The input stream, ServletInputStream . Servlets use the input stream to get data from clients that use application protocols such as the HTTP POST and PUT methods. HttpServletRequest extends HttpServletRequest extends ServletRequest Interfaces that extend ServletRequest interface allow the servlet to retrieve more protocolspecific data. For example, the HttpServletRequest interface contains methods for accessing HTTPspecific header information. The ServletResponse Interface
The ServletResponse Interface The ServletResponse interface gives the servlet methods for replying to the client. It: Allows the servlet to set the content length and MIME type of the reply. Provides an output stream, ServletOutputStream , and a Writer through which the servlet can send the reply data. HttpServletResponse extends HttpServletResponse extends ServletResponse Interfaces that extend the ServletResponse interface give the servlet more protocol
specific capabilities. For example, the HttpServletResponse interface contains methods that allow the servlet to manipulate HTTPspecific header information. HttpServlet
HttpServlet Additional Capabilities of HTTP Servlets
The classes and interfaces described above make up a basic Servlet.
HTTP servlets have some additional objects that provide sessiontracking capabilities. The servlet writer can use these APIs to maintain state between the servlet and the client that persists across multiple connections during some time period. HTTP servlets also have objects that provide cookies. The servlet writer uses the cookie API to save data with the client and to retrieve this data. ...
View Full Document
- Summer '10