Java Reference
In-Depth Information
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>" + "Counter Page" + "</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Counter Page</h1><hr>");
out.println("Welcome to the Web site<p>");
out.println("You have been here " + count.intValue() + " time(s)<p>");
out.println("</body>");
out.println("</html>");
}
6. Compile the servlet. You will need to include the jar files that contain the
servlet classes in your compile command. Do this by adding the extdirs
command to the compile command.
javac -extdirs C:\apache-tomcat\lib CounterServlet.java
7. Once you have successfully compiled CounterServlet , you will need to copy
the java class to the location used by the servlet engine to deploy the servlet.
If you are using Tomcat, you will need to copy the class file to the servlet
classes directory (C:\apache-tomcat\webapps\examples\WEB-INF\classes).
You will also need to modify the Tomcat configuration file (C:\apache-tom-
cat\webapps\examples\WEB-INF\web.xml) and add the proper references
to CounterServlet . These references tell Tomcat how to convert the names
in the URL to a particular servlet. For your convenience, a modified
web.xml file (suitable for the Tomcat version supplied on the CD) is pro-
vided in the Examples directory for this chapter. Copy that file to C:\apache-
tomcat\webapps\examples\WEB-INF\web.xml. You may also need to stop,
and then restart Apache so that it loads this new configuration file.
If you are using another servlet engine, you will have to consult the docu-
mentation about how to deploy the servlet. In most cases, you can deploy
a simple servlet by dropping the class file into the correct directory. If the
documentation is hard to understand, just keep dropping it into different
directories until you find the one that works.
In order to invoke the servlet, you will need to start your browser and key
into the address line the correct URL to connect to the servlet engine and
invoke the servlet. A typical line might be something like this (although the
port number may be different with your servlet engine):
ON THE DVD
Search WWH ::




Custom Search