A Servlet Javadoc!!

The javax.servlet package

javax.servlet.Servlet interface methods

init()
service(ServletRequest req, ServletResponse res)
destroy()
get ServletConfig()
getServletInfo()

javax.servlet.GenericServlet(abstract) implements all methods of Servlet interface except service().

javax.servlet.http.HttpServlet(abstract) overloads
service(ServletRequest, ServletResponse)
with
service(HttpServletRequest,HttpServletResponse)
and in addition defines methods doXXX() for GET, HEAD, POST, DELETE, PUT, OPTIONS, TRACE

The javax.servlet.Servlet interface
All servlets must implement this interface directly or indirectly.
The javax.servlet.GenericServlet class
It is an abstract class that provides implementation for all methods of javax.servlet.Servlet interface except the service() method. This class can be extended and its service method implemented to write any type of servlet.
javax.servlet.ServletRequest interface
This is a generic interface defines methods that can be used to extract information from the Request
javax.servlet.ServletResponse interface
This is a generic interface that defines methods that can be used to generate a http response to the client.
javax.servlet.http package
This package provides support for the http protocol. Classes and interfaces in this package extend the corresponding interfaces and classes in the javax.servlet package.
javax.servlet.http.HttpServlet class
This class extends javax.servlet.GenericServlet and provides a different implementation of the service method:
protected void service(HttpSerlvetRequest req, HttpServletResponse res) throws ServletException,IOException;
In the servlets we write we extend our HttpServlet and override its service() method.
Understanding the sequence of events in HttpServlet
The ServletContainer calls the
service(ServletRequest req. ServletResponse res)
method of theHttpServlet class.
This method calls the
service(HttpservletRequest req, HttpServletResponse res)
method of the same class(HttpServlet) which in turn calls the method doXXX() based on the information obtained from the request object.
Note that the service() method is overloaded in the HttpServlet class.
Overloaded Methods:
service(ServletRequest req. ServletResponse res) throws ServletException, IOException
service(HttpservletRequest req, HttpServletResponse res) throws ServletException, IOException.
If any of these methods are overridden the programmer may have to provide some of the functionality so that the appropriate doXXX() method is called.
All doXXX() methods take two parameters HttpServletRequest and HttpServletResponse.
The HttpServletRequest and HttpServletResponse are interfaces that are implemented by classes providedby the servlet containter.
The servletRequest and HttpServletRequest objects provide methods that help us to analyze the data inthe incoming request(parameters/meta-data/text/binary/).
ServletRequest provides methods to handle requests in any protocol while HttpServletRequest adds HTTP specific methods to handle requests.
Sending the response
The HttpServletResponse provides methods that accepts data that the servlet needs to send to the clientand formats it in a HTTP specific way as per the HTTP specification.

How does a DTD look like?

Consider this xml file:

<document>
	<database>
		<authors>
			<authors-ROW>
				<isbn_CODE>abc123</isbn_CODE>
				<author-NAME>Karl Peter</author-NAME>
			</authors-ROW>
			<authors-ROW>
				<isbn_CODE>xyz123</isbn_CODE>
				<author_NAME>John Smith</author_NAME>
			</authors-ROW>
		</authors>
		<publishers>
			<publishers-ROW>
				<pub_CODE>aaa123</pub_CODE>
				<pub_NAME>Martin Hall</pub_NAME>
			</publishers-ROW>
			<publishers-ROW>
				<pub_CODE>bbb123</pub_CODE>
				<pub_NAME>Mark Robinson</pub_NAME>
			</publishers-ROW>
		</publishers>
	</database>
</document>

It is perfectly legal to have XML documents without DTDs.Think of them as XML files without a pre-defined format.XML Documents that do not have DTDs are called well-formed XML documents.XML Documents that do have DTDs are called well-formed and valid XML documents.
To see how a DTD looks like, let’s create a DTD for out XML document above-

<?xml version = "1.0" standalone="no"?>
<doctype DOCUMENT [<!ELEMENT DOCUMENT(DATABASE)>
<!ELEMENT DATABASE(AUTHORS, PUBLISHERS)>
<!ELEMENT AUTHORS(AUTHORS-ROW)*>
<!ELEMENT AUTHORS-ROW(ISBN_CODE, AUTHOR_NAME)>
<!ELEMENT ISBN_CODE(#PCDATA)>
<!ELEMENT AUTHOR_NAME(#PCDATA)>
<!ELEMENT PUBLISHERS(PUBLISHERS-ROW)*>
<!ELEMENT PUBLISHERS-ROW(PUB_CODE, PUB_NAME)>
<!ELEMENT PUB_CODE(#PCDATA)>
<!ELEMENT PUB_NAME(#PCDATA)>

Explanation for this DTD –

<!ELEMENT DOCUMENT(DATABASE)>

This means that the “DOCUMENT” element should have only one “DATABASE” element inside it.

<!ELEMENT DATABASE(AUTHORS, PUBLISHER)>

This means that the “DATABASE” element should have two elements inside it “AUTHORS” and “PUBLISHERS” – in that order.

<!ELEMENT AUTHORS(AUTHORS-ROW)*>

This means that the “AUTHORS” element should have zero or more “AUTHORS_ROW” elements inside it.
(The * signifies the “zero or more” relationship).

<!ELEMENT AUTHORS-ROW(ISBN_CODE, AUTHOR_NAME)>

This means that the “AUTHORS-ROW” element should have two elements inside it “ISBN_CODE” and “AUTHOR_NAME” – in that order.

<!ELEMENT ISBN_CODE(#PCDATA)>

this means that the ISBN_CODE element has some data in it (PCDATA stands for Parsed Character DATA).

<!ELEMENT AUTHOR_NAME(#PCDATA)>

this means that the AUTHOR_NAME element has some data in it (PCDATA stands for Parsed Character DATA).

<!ELEMENT PUBLlSHERS(PUBLlSHERS-ROW)*>

This means that the “PUBLISHERS” element should have zero or more “PUBLISHERS-ROW” elements inside
it. (The * signifies the “zero or more” relationship).

<!ELEMENT PUBLISHERS-ROW(PUB_CODE, PUB_NAME)>

This means that the “PUBLISHERS-ROW” element should have two elements inside it “PUB_CODE” and “PUB_NAME” – in that order.

<!ELEMENT PUB_CODE(#PCDATA)>

this means that the PUB_CODE element has some data in it (PCDATA stands for Parsed Character DATA).

<!ELEMENT PUB_NAME(#PCDATA)>

this means that the PUB_NAME element has some data in it (PCDATA stands for Parsed Character DATA).