I installed Tomcat on my laptop which runs Ubuntu Linux. APT package manager makes it very easy to install many software packages.
Firstly, make sure that you have configured software sources correctly. Go to "System"--"Administration"--"Software Sources" and do it as below:
If you skip this step, apt-get may not find tomcat package.
Before installing tomcat, I have to install Java programming environment. Just use "sudo apt-get install sun-java6-jdk sun-java6-jre" to install JDK and JRE. I suggest choosing Sun JDK or JRE. If you have more than one, you'd better use "sudo update-alternatives --config java" and "sudo update-alternatives --config javac" to choose Sun Java interpretor and compiler as default.
Then you can install tomcat-5.5 with "sudo apt-get install tomcat5.5". After that, Tomcat will start. The default port is 8180. i.e. you can visit http://localhost:8180 to test your tomcat. If you see a blank page, it means tomcat works.
One of configure files is /etc/tomcat5.5/server.xml. I want to make tomcat use port 8080. Open it and find:
<Connector port="8180" maxHttpHeaderSize="8192" .... />
Change ""8180" to "8080", save it and use "sudo /etc/init.d/tomcat5.5 restart" to restart tomcat.
The last step you should specify a directory as web root directory. Go to /etc/tomcat5.5/Catalina/localhost directory, add an XML file (for example: ROOT.xml) which contains:
<Context path="/" docBase="/home/albert/Programs/JavaEE" reloadable="true" />
Put a JSP file (test.jsp) in /home/albert/Programs/JavaEE/, which contains:
<% out.println("It works"); %>
Restart tomcat and visit http://localhost:8080/test.jsp to test it.