The Apache web server – Part 3
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.
First we need to install the following packages:
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:
If everything is right, this message should be displayed: „It works!“.
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:
<role rolename="manager-gui" />
<user username="manager" password="meinpasswort" roles="manager-gui"/>
When the file is saved, we restart Tomcat. Now we can log in with our newly created user to the management gui of 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:
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.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Your browser is: <%= request.getHeader("User-Agent") %><br>
Your IP address is: <%= request.getRemoteAddr() %><br>
If you are now interested into web development you will easily find more on this topic on this blog or on the net.