The Apache web server – Part 3

Tomcat

Tomcat is needed if we want to execute Java Servlets and Java Server Pages on our web server. It adds this feature and also has some usable management tools.

Installation

First we need to install the following packages:
tomcat7
tomcat7-admin
tomcat7-docs

After a successful installation Tomcat can be started with the following command: ‘/etc/init.d/tomcat7 start’, stopped with ‘/etc/init.d/tomcat7 stop’ and restarted with ‘/etc/init.d/tomcat7 restart’. For this you need to be root.

You can test if the installation was successful if you type the following into your browser:
http://localhost:8080

If everything is right, this message should be displayed: “It works!”.

Configuration

You can configure Apache Tomcat with xml files in the ‘conf’ directory of the Tomcat directory (normally ‘/var/lib/tomcat7/conf’). The ‘tomcat-users.xml’ file is interesting. You can define user and user roles for the Tomcat manager tool. To use this tool, we define a new user and a new role:

When the file is saved, we restart Tomcat. Now we can log in with our newly created user to the management gui of Tomcat:
http://localhost:8080/manager

Managementkonsole von Tomcat

This tool displays all running applications. You can stop, restart or delete them. At the end of the site there are input fields to deplay new applications to this Tomcat web server.

You can test this with an example Java web application. You can find it here: Link auf JavaTest.war. Such an application can be implemented with IDEs like Netbeans or Eclipse. *.war files are compiled projects. When you deploy this project it is located at the following URL:
http://localhost/JavaTest

erste JSP Seite

You should see a success message. The site displays informations about your browser and you operating system. It also shows your IP address. If you are interested into the code, here is the whole source of this application. You can also find it in the JSP file in the war archiv.

If you are now interested into web development you will easily find more on this topic on this blog or on the net.

Part 1 I Part 2

(Visited 91 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *