The Tomcat Servlet Container
The Tomcat Servlet Container
The Tomcat Servlet Container
About Tomcat
• A “servlet container” is like a mini server, but only for
serving html, jsp and servlets.
• Many servlet containers could be used for this course.
Some may even be easier to configure than tomcat, but
tomcat provides an easy-to-use
development/deployment tool and also complies with the
servlet specification best of all containers.
• Tomcat is from Apache and is open-source.
• Tomcat can be used as a stand-alone servlet container.
• You can install the Apache server with Tomcat, and then
proceed to configure each for their individual purposes.
(The server would relay servlet requests to Tomcat.)
About these notes
• Two texts & many of my own examples
were used to compile servlet notes.
• The texts referenced are Jason Hunter’s
Servlet book and Core Servlets Vol 1 by
Hall & Brown. Both excellent books.
Asides: XML
• XML stands for eXtensible-markup-language and is a
SGML.
• Unlike older HTML, XML can be validated.
• XHTML, for example, is HTML that is XML compliant.
• XML is widely used in internet programming. Some
technologies - like SOAP - are based on XML.
• Many files on Tomcat are XML.
• In the past I’ve taught XML as a full component of this
course. I am not doing that this semester. There are
websites with tutorials. I have links to a whole text of xml
content at
http://employees.oneonta.edu/higgindm/internet%20progra
mming/xmllinks.html
More Asides
• Case sensitivity
– Java, C, C++ and Ruby are all case-sensitive
languages.
– At times my notes and ppts will be sloppy and
incorrectly show case, but in your work you
can’t be sloppy.
• JAR files, classpath, batch files,
environment variables, even WAR files:
We are likely to use all of these.
Download tomcat at http://
tomcat.apache.org/
Webapps
Web-inf
web.xml
<description>
This is the Web application in which we
demonstrate our JSP and Servlet examples.
</description>
web.xml- con’t
<!-- Servlet definitions -->
<servlet>
<servlet-name>welcome1</servlet-name>
<description>
A simple servlet that handles an HTTP get request.
</description>
<servlet-class>
WelcomeServlet
</servlet-class>
</servlet>
<servlet>
<servlet-name>welcome2</servlet-name>
web.xml- con’t
<description>
A simple servlet that handles an HTTP get request with data.
</description>
<servlet-class>
WelcomeServlet2
</servlet-class>
</servlet>
<!-- Servlet mappings -->
<servlet-mapping>
<servlet-name>welcome1</servlet-name>
<url-pattern>/welcome1</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>welcome2</servlet-name>
<url-pattern>/welcome2</url-pattern>
</web-app>
Tomcat
• You’ll have to watch the blackscreen
associated with your server session for
errors on startup or reloads. If these occur
you may have to fix them before your
servlets can be accessed.