$ sudo apt-get install tomcat6 tomcat6-admin tomcat6-examples tomcat6-docsTomcat starts automatically and, by default, uses port 8080. Internally, one or more Java virtual machines handle browser requests by spawning program threads. Each request uses byte-compiled code created at run-time for the Java Server Pages. The whole setup is very fast and efficient. Once you have Tomcat started, view the Tomcat root URL:
/etc/tomcat6/tomcat-users.xmlWithin the tomcat-users start and end tags (outside of the comments), add the following (you can make the values of username and password anything you'd like):
<role rolename="manager"/> <user username="admin" password="adminfoo" roles="manager"/>Restart tomcat by:
# /etc/init.d/tomcat6 restartAccess the manager from this URL: Look in the Administration section on the left-hand side and select the Tomcat Manager hyperlink. Clicking on this hyperlink will require you to give the user/password combination just entered to the authentication popup window:
user: admin password: adminfooThe manager application displays currently deployed web applications in the central table of the List Applications page; there are also the features: HTML Manager Help, Manager Help, and Server Status.
In Deploy section at the bottom you can deploy web applications dynamically either through a URL to the application directory, or via a WAR (Web ARchive) file. If you know about Java JAR files, a WAR file is simply JAR files which contain the additional web control information.
$ unzip ~/Desktop/apache-tomcat-6.0.20.zip -d ~/binOpen Eclipse. We will install our local tomcat server in Eclipse.
Open Perspective
Other
Other.
Open the Server category,
select the Server entry within and click Next.
Tomcat v6.0 Server, click
Next.
Tomcat admin port 8005 HTTP/1.1 8080 AJP/1.3 8090These all conflict with the system-wide tomcat ports, so we want to avoid the conflict. The easiest way is to add a "1" in front of each port, getting:
Tomcat admin port 18005 HTTP/1.1 18080 AJP/1.3 18090Save the configuration and close this configurator.
Project
Web
Dynamic Web Project;
click Next.
Set HelloJSP as the Project Name; click Finish.
JSP.
Give it the name index.jsp.
Click Finish.
First example: <% out.println( "Hello World 1" ); %> <br /> Second example:<br /> <% String s = "Hello World 2"; %> Here it is: <%= s %>The web tags <%, %> and <%= are the special JSP server-side execution tags, equivalent to the Php versions with the special "element" % replacing ?.
Run on Server.
First example: Hello World 1 Second example: Here it is: Hello World 2If the server output fails, go to the Servers window, right-click on the Tomcat server entry and select Restart.
WAR file. In the popup, browse
to select the destination, the default being
/home/LOGIN/HelloJSP.war
Access the system tomcat manager from this URL:
At the bottom, in the WAR file to deploy section,
click the Browse... button
and navigate to select the WAR file we just created.
After choosing this file, click the Deploy button just
below the field. If it went right (which it should),
you should see "OK" in the Message
section at the top of the page. You should also see the new
context (web application) "/HelloJSP" appear in the list.
Then activate /HelloJSP by clicking on it
in the leftmost column of the List Applications
table to get this URL:
$ sudo a2enmod proxy proxy_httpCreate the following Apache configuration file:
/etc/apache2/conf.d/proxy.confwith this content (I did not have time to check every detail about what is absolutely necessary):
ProxyRequests On ProxyVia On <Proxy *> Order deny,allow Allow from all </Proxy> ProxyPass /HelloJSP http://localhost:8080/HelloJSP ProxyPassReverse /HelloJSP http://localhost:8080/HelloJSP ProxyPass /manager http://localhost:8080/manager ProxyPassReverse /manager http://localhost:8080/managerthen reload Apache and try the URL's: Note that, in the case of the manager, the "links" to other applications will not work, but the manager itself will work in terms of deploying WAR files, etc.
$ sudo apt-get install apache2-prefork-devOne bothersome issue about Apache2 is that it has two "modes", prefork and threaded. Ubuntu requires the prefork version to run Php, but there is a lingering sense that the threaded version may be necessary (??). First of all you have to ensure that tomcat is serving port 8009. Edit the file
/etc/tomcat6/server.xmlLook for the line:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />which is inside the comments. Move it outside the comments and restart tomcat6:
$ sudo /etc/init.d/tomcat6 restartIn Fedora, there is no need to do this last step, 8009 is already open in its config file. Next download the JK source. A recent is available from the Computer Science website as: Extract the tar ball somewhere:
$ tar xzf tomcat-connectors-1.2.28-src.tar.gzobtaining the directory:
tomcat-connectors-1.2.28-srcThen compile and install as follows:
$ cd tomcat-connectors-1.2.28-src/native $ ./configure --with-apxs=/usr/bin/apxs2 $ make $ sudo make installThe only thing installed the Apache module:
/usr/lib/apache2/modules/mod_jk.soCreate a startup configuration file:
/etc/apache2/conf.d/mod_jk.confwith this content:
# mod_jk configuration LoadModule jk_module /usr/lib/apache2/modules/mod_jk.so JkLogFile /var/log/apache2/mod_jk.log JkLogLevel info JkMount /manager/ ajp13 JkMount /manager/* ajp13 JkMount /HelloJSP ajp13 JkMount /HelloJSP/* ajp13The last two line groups make the connection between Tomcat and Apache for this specific URLs "/manager" and /HelloJSP and all their descendants. After creating this file, restart Apache
# /etc/init.d/apache2 restartTest the connector service by these URLs: