Start Tomcat as explained earlier. Tomcat must be running before you try to execute a servlet.
Start a Web Browser and Request the Ser vlet
Start a web browser and enter the URL shown here:
Alternatively, you may enter the URL shown here:
This can be done because 127.0.0.1 is defined as the IP address of the local machine.
You will observe the output of the servlet in the browser display area. It will contain the
string Hello! in bold type.
The Ser vlet API
Two packages contain the classes and interfaces that are required to build servlets. These are
javax.servlet and javax.servlet.http. They constitute the Servlet API. Keep in mind that these
packages are not part of the Java core packages. Instead, they are standard extensions provided
by Tomcat. Therefore, they are not included with Java SE 6.
The Servlet API has been in a process of ongoing development and enhancement. The
current servlet specification is version 2.4, and that is the one used in this topic. However,
because changes happen fast in the world of Java, you will want to check for any additions
or alterations. This chapter discusses the core of the Servlet API, which will be available to
The javax.ser vlet Package
The javax.servlet package contains a number of interfaces and classes that establish the
framework in which servlets operate. The following table summarizes the core interfaces
that are provided in this package. The most significant of these is Servlet. All servlets must
implement this interface or extend a class that implements the interface. The ServletRequest
and ServletResponse interfaces are also very important.
Declares life cycle methods for a ser vlet.
Allows ser vlets to get initialization parameters.
Enables ser vlets to log events and access information about their
Used to read data from a client request.
Ser vletResponse Used to write data to a client response.
Search WWH :