Java Reference
In-Depth Information
This address references a Web server running on port 8080 on your local machine.
By default, Tomcat uses port 8080, although you can change this at your convenience.
After you install Tomcat or another Web server/servlet engine, make sure the
examples supplied with the servlet engine work before you proceed to the exercises.
To make sure Tomcat is installed and working properly, type this URL in your
browser:
http://localhost:8080
You should see the introductory Tomcat page in your browser. Again, if you do
not, check the FAQ section of the Apache Tomcat Web site.
Next, make sure the Apache servlet environment is working properly. Type this
URL into your browser:
http://localhost:8080/examples/servlets/index.html
You should see a page that demonstrates several pre-packaged servlet pages.
Finally, make sure the Apache JSP environment is working properly. Type this
URL into your browser:
http://localhost:8080/examples/jsp/index.html
You should see a page that demonstrates several pre-packaged JSP pages.
E XERCISES
In this example exercise, you are going to code a simple servlet that creates a session
the first time it is invoked and displays a simple page. Every time you refresh the
page, you are going to run the servlet and increment a counter that counts the
number of times you have run the servlet and displays this result.
1. Create a CounterServlet.java file with the editor.
2. In order to compile a servlet, you will need to import the following
packages.
Search WWH ::




Custom Search