Tomcat also supports JavaServer Pages (JSP), which is similar to PHP in that it provides a convenient syntax to write dynamic web pages. JavaServer Pages may contain scriptlets or tags that the system converts into servlets.
A Java servlet is analogous to a Java applet, except that is runs on the web server instead of on the web client (browser). A servlet is implemented as an instance of the servlet class. It is designed to respond to requests and typically generates HTML code that is sent to the user’s web browser.
Servlets have the capability to maintain state over a sequence of web transactions. HTTP Cookies or URL rewriting methods are used track session information.
During software development the servlet library can be accessed with the package javax.servlet. The API defines the expected interactions between the servlet and the web container, such as request and response methods, as well as configuration objects.
Tomcat typically generates servlets from instructions (tags) in JSP pages. The servlets are first written in Java source code, which is then compiled in Java classes that can be executed by the Java Runtime Engine (JRE).
Conceptually, JSP files are HTML files that can include code for dynamically retrieving and inserting content on a web page. That is, JSP provides a way to keep the user interface (HTML code) separate from the content generation (servlet/Java code).
Content can be generated in a programmatic way (database access, loops, conditionals, etc.) using special XML tags embedded in the HTML code.
Through the use of libraries of tags that implement frequently used functionality, it is possible to write dynamic web pages without the need of programming skills. For example, the JavaServer Pages Standard Tag Library (JSTL) provides tags that implement the commonly used functions of web applications.
The part of Tomcat the implements the servet container is called Catalina. One of the services provided by servlet containers is container managed security. In order manage access permissions, Tomcat uses Realms, which are databases of usernames, passwords, and roles that specify access rights.
The Jasper engine parses JSP files and compiles servlets to be processed by Catalina. The web server functionality is implemented through the coyote module, which monitors a specified TCP port for HTTP requests. Such requests are processed by Tomcat and the results sent back to the client.
Web applications typically involve access to databases, such as . Tomcat uses the Java Database Connectivity (JDBC) API connect to databases. In conjunction with JDBC drivers specific the database systems being used, the JDBC abstraction layer enables developers to use the same code for different database systems. Tomcat uses thread pooling to handle high volume database requests.
Like Java, Tomcat is cross platform. It can be installed an run on Linux and Windows operation systems. It can be installed to run as daemon or service so that is starts up automatically when the operating system is booted.
Under the installation directory, which is stored in the variable $CATALINA_HOME, a Tomcat server is organized in four subdirectories. The /bin directory contains the startup and shutdown scripts. Your web applications are deployed in the /webapps directory. The /conf directory is for configuration files, and /log for log files.
You can find instructions on how to install and administer Tomcat on the Tomcat documentation page.