![]() |
![]() Spring Semester 2003 |
Quick summary of some important notes:
jakarta-tomcat-4.0.4.tar.gz
and gunzip
is needed
gnu
's tar (revisit your installation of PHP to see what's needed)
/l/www/classes/a348/software
(as expected,
I hope)
And now the lab notes.
We first "create" an applet, and install it on our website.
1. Create the source code of the applet.
For the purpose of this lab you will get the source code from me. We will install a fairly complex applet, and we will ignore the source code for now.Here's how you do that:Take the following files
from my home directory and put them in a special directory (called/u/dgerman/fall2000/lab7/Matrix3D.java /u/dgerman/fall2000/lab7/XYZApp.javalab10
) under your document root directory of your web server. Once you copy them you have the source code; that makes it as if you have written the source code yourself.
Please don't overlook the dots (.) at the end of the commands. Thank you.burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/apache/apache_1.3.22/htdocs/lab10 burrowww.cs.indiana.edu% cp /u/dgerman/fall2000/lab7/Matrix3D.java . burrowww.cs.indiana.edu% cp /u/dgerman/fall2000/lab7/XYZApp.java . burrowww.cs.indiana.edu% ls -l total 20 -rw-r--r-- 1 dgerman faculty 6327 Oct 11 09:32 Matrix3D.java -rw-r--r-- 1 dgerman faculty 13161 Oct 11 09:32 XYZApp.java
2. Compile them (prepare the bytecode).
UseHere's how you do that:javac
to compile the source code. This will create a number of.class
files that may or may not be in one-to-one correspondence with the source code (java
) files. The number and names of the.class
files can be deduced from the actual contents of the source code files. Of those createdXYZApp.class
is the main file (although for applets we don't have amain
method) and we need to make a note of that.
Please note there is a warning. The reason is that this is a very old, very famous applet, using the very first (1.0) Java API. It does not matter, and once we know that we can move on. We will talk more about that later. If your class files are created, move to step 3. If not, what are you waiting for?burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/apache/apache_1.3.22/htdocs/lab10 burrowww.cs.indiana.edu% ls -l total 20 -rw-r--r-- 1 dgerman faculty 6327 Oct 11 09:34 Matrix3D.java -rw-r--r-- 1 dgerman faculty 13161 Oct 11 09:34 XYZApp.java burrowww.cs.indiana.edu% javac *.java Note: XYZApp.java uses or overrides a deprecated API. Recompile with "-deprecation" for details. 1 warning burrowww.cs.indiana.edu% ls -l total 35 -rw-r--r-- 1 dgerman faculty 2003 Oct 11 09:35 Atom.class -rw-r--r-- 1 dgerman faculty 3683 Oct 11 09:35 Matrix3D.class -rw-r--r-- 1 dgerman faculty 6327 Oct 11 09:34 Matrix3D.java -rw-r--r-- 1 dgerman faculty 4580 Oct 11 09:35 XYZApp.class -rw-r--r-- 1 dgerman faculty 13161 Oct 11 09:34 XYZApp.java -rw-r--r-- 1 dgerman faculty 3762 Oct 11 09:35 XYZChemModel.class burrowww.cs.indiana.edu%
3. Prepare an .html
file to distribute the applet.
Create an HTML file (call itindex.html
) in the same directory with the classes and the source code, and make sure it has an applet tag inside it that looks like this:Notice the<applet code=XYZApp.class width=100 height=100> <param name =model value=models/benzene.xyz> </applet>param
tag. It communicates important data to the applet, without which the applet won't run. (Also, you're responsible for the rest of the HTML in the file).
4. Prepare data for the applet.
Create a directoryHere's how I did it:models
inside the folder that contains your Java applets code.Next, copy all the
*.xyz
files from the following folderinto your/u/dgerman/fall2000/lab7models
directory. They contain important rendering information for the applet. The fact that the applet is taking this info from a file is part of the actual design of the applet (it's a decision of the original program writer).
burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/apache/apache_1.3.22/htdocs/lab10 burrowww.cs.indiana.edu% ls -ld models ls: models: No such file or directory burrowww.cs.indiana.edu% mkdir models burrowww.cs.indiana.edu% ls -ld models drwxr-xr-x 2 dgerman faculty 512 Oct 11 09:40 models burrowww.cs.indiana.edu% cp /u/dgerman/fall2000/lab7/*.xyz models burrowww.cs.indiana.edu% ls -l models total 11 -rw-r--r-- 1 dgerman faculty 3674 Oct 11 09:40 HyaluronicAcid.xyz -rw-r--r-- 1 dgerman faculty 269 Oct 11 09:40 benzene.xyz -rw-r--r-- 1 dgerman faculty 2317 Oct 11 09:40 buckminsterfullerine.xyz -rw-r--r-- 1 dgerman faculty 460 Oct 11 09:40 cyclohexane.xyz -rw-r--r-- 1 dgerman faculty 170 Oct 11 09:40 ethane.xyz -rw-r--r-- 1 dgerman faculty 66 Oct 11 09:40 water.xyz burrowww.cs.indiana.edu%
5. Check your applet over the web.
6. Improve your HTML interface.
Describe what the page contains and what the user needs to do to interact with it.
7. Show all other molecule models.
I'll let you figure out how.
Now that we have seen this, let's include in our web page an applet from another site.
Take a look at this
example
from O'Reilly.
In this second part of the lab we prepare the installation of Tomcat.
For this, you should know up front, you will need two more port numbers.
They have been listed on the students page from the beginning of the semester.
So let's describe the process below.
TOMCAT INSTALLATION.
Create a folder where you will install tomcat
.
Go there, and copy it from myburrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat burrowww.cs.indiana.edu%
public
directory.
Unzip it, and you're almost done.burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat burrowww.cs.indiana.edu% cp /u/dgerman/public/jak*.gz . burrowww.cs.indiana.edu% ls -l total 5160 -rw-r--r-- 1 dgerman faculty 5275338 Mar 7 12:09 jakarta-tomcat-4.0.4.tar.gz burrowww.cs.indiana.edu%
Check yourgunzip *.gz
quota
, tar xvf
, then remove the archive.
For reference, latest version of Tomcat is always available here.burrowww.cs.indiana.edu% which tar /usr/local/gnu/bin/tar burrowww.cs.indiana.edu% tar xvf *.tar ... jakarta-tomcat-4.0.4/bin/digest.bat jakarta-tomcat-4.0.4/bin/bootstrap.jar jakarta-tomcat-4.0.4/bin/startup.bat jakarta-tomcat-4.0.4/bin/tomcat.exe jakarta-tomcat-4.0.4/conf/catalina.policy jakarta-tomcat-4.0.4/conf/server-noexamples.xml.config jakarta-tomcat-4.0.4/conf/web.xml jakarta-tomcat-4.0.4/conf/server.xml jakarta-tomcat-4.0.4/conf/tomcat-users.xml burrowww.cs.indiana.edu% quota -v Disk quotas for dgerman (uid 10867): Filesystem usage quota limit timeleft files quota limit timeleft /nfs/paca/home/user1 94490 100000 102400 2766 0 0 burrowww.cs.indiana.edu% ls -ld * drwxr-xr-x 11 dgerman faculty 1024 Mar 1 14:49 jakarta-tomcat-4.0.4 -rw-r--r-- 1 dgerman faculty 5275338 Mar 7 12:09 jakarta-tomcat-4.0.4.tar burrowww.cs.indiana.edu% rm *.gz burrowww.cs.indiana.edu% quota -v Disk quotas for dgerman (uid 10867): Filesystem usage quota limit timeleft files quota limit timeleft /nfs/paca/home/user1 89330 100000 102400 2765 0 0 burrowww.cs.indiana.edu%
Let's now configure our server.
First we need to set a few environment variables.
Here's my ~/.cshrc
Please make sure yours is compatible.# # .cshrc - This file is executed whenever a C shell is started. # # set the umask, which controls the permissions on new files you create/ # 022 denies write access to other people, but not read access. # 077 denies read and write access to other people. umask 022 # Set the PATH. You can put your own personal commands in # your ~/bin directory. # # Note for use on Solaris: # Put /usr/ucb in your path before /usr/bin and /usr/sbin if you # want the bsd-ish versions of things like ps and df. # Put /usr/bin and /usr/sbin in your path before /usr/ucb if you # want the svr4-ish versions of things like ps and df. # If you don't know the difference between bsd and svr4, then # it is safe to just leave this as it is. # set path = ( ~/bin \ /home/user1/mysql/bin /usr/local/gnu/bin /usr/bin \ /usr/local/bin /usr/sbin /usr/ucb \ /usr/bin/X11 /usr/openwin/bin /usr/dt/bin /opt/SUNWspro/bin \ /usr/ccs/bin /usr/local/gnu/bin ) # This prevents programs from dumping a large file called "core" # in the current directory when they crash. # If you really do want these core files, delete this line. limit coredumpsize 0 # Tell the shell how many previous commands to remember. You can # view the previous commands using the history command set history=20 # Uncomment the following line if you don't want ^D to log you out #set ignoreeof # The following lines tell the shell to periodically check for new mail # and print the messages "You have new mail" when mail arrives. # This is a separate sort of mail notification from that provided # by biff (see your .login file) setenv MAIL /var/mail/$USER set mail=$MAIL # You may want to set the prompt to something fancy. The following # line puts the hostname, your username, and the current command number # in the prompt #set prompt="[`whoami`@`hostname`:\!] " set prompt="`hostname`% " # Select a default printer. Under Solaris, some programs use PRINTER # and others use LPDEST. See the printers man page (man printers) # for a list of available printers. #setenv PRINTER psburrow #setenv LPDEST psburrow # You can create aliases for common commands. The following line # makes lls equivalent to 'ls -l' alias lls ls -l setenv JAVA_HOME /l/jdk setenv CATALINA_HOME /u/dgerman/tomcat/jakarta-tomcat-4.0.4 setenv CLASSPATH .:$CATALINA_HOME/common/lib/servlet.jar # setenv startTomcat $TOMCAT_HOME/bin/startup.sh # setenv stopTomcat $TOMCAT_HOME/bin/shutdown.sh
Here's a description of the Tomcat folders.
Here's my$CATALINA_HOME/bin # contains the startup/shutdown scripts /conf # main config files: server.xml, a global web.xml /server # contains Tomcat Java Archive files /lib # JAR files that the servlet engine depends on /common/lib # JAR files shared between Tomcat components (server.jar) /jasper # JAR files for Jasper the JSP compiler /logs # contains Tomcat's log files /src # source files /webapps # where all web applications are deployed /work # where all servlets generated from JSP are placed
server.xml
(which goes under
$CATALINA_HOME/conf
)
I might actually create this file for you, but let's look at it a bit:burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/conf burrowww.cs.indiana.edu% ls -ld server.xml -rw-r--r-- 1 dgerman faculty 2846 Mar 21 12:59 server.xml burrowww.cs.indiana.edu% cat server.xml <Server port="19201" shutdown="SHUTDOWN" debug="0"> <Service name="Tomcat-Standalone"> <Connector className="org.apache.catalina.connector.http.HttpConnector" port="19200" minProcessors="5" maxProcessors="75" enableLookups="true" acceptCount="10" debug="0" connectionTimeout="60000"/> <Engine name="Standalone" defaultHost="localhost" debug="0"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="catalina_log." suffix=".txt" timestamp="true"/> <Realm className="org.apache.catalina.realm.MemoryRealm" /> <Host name="localhost" debug="0" appBase="webapps" unpackWARs="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="common"/> <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="localhost_log." suffix=".txt" timestamp="true"/> <Context path="/manager" docBase="manager" debug="0" privileged="true"/> <Context path="/one" docBase="one" debug="0" reloadable="true" /> <Context path="/examples" docBase="examples" debug="0" reloadable="true" crossContext="true"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_examples_log." suffix=".txt" timestamp="true"/> <Ejb name="ejb/EmplRecord" type="Entity" home="com.wombat.empl.EmployeeRecordHome" remote="com.wombat.empl.EmployeeRecord"/> <Environment name="maxExemptions" type="java.lang.Integer" value="15"/> <Parameter name="context.param.name" value="context.param.value" override="false"/> <Resource name="jdbc/EmployeeAppDb" auth="SERVLET" type="javax.sql.DataSource"/> <ResourceParams name="jdbc/EmployeeAppDb"> <parameter><name>user</name><value>sa</value></parameter> <parameter><name>password</name><value></value></parameter> <parameter><name>driverClassName</name> <value>org.hsql.jdbcDriver</value></parameter> <parameter><name>driverName</name> <value>jdbc:HypersonicSQL:database</value></parameter> </ResourceParams> <Resource name="mail/Session" auth="Container" type="javax.mail.Session"/> <ResourceParams name="mail/Session"> <parameter> <name>mail.smtp.host</name> <value>localhost</value> </parameter> </ResourceParams> </Context> </Host> </Engine> </Service> </Server> burrowww.cs.indiana.edu%
$CATALINA_HOME/conf
in your folder
hierarchy
server.xml
files will be available from
/u/dgerman/public/a348/tomcats/
Copy it where you should and make the changes to include your ports./u/dgerman/public/a348/tomcats/sampleServer.xml
Once you have a customized server.xml
in place start Tomcat.
Then test it, here's mine.burrowww.cs.indiana.edu% ps -ef | grep dgerman dgerman 16121 18943 0 08:00:02 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 16119 18943 0 08:00:02 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 25984 23278 0 13:31:34 pts/42 0:00 grep dgerman dgerman 16101 18943 0 08:00:02 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 18943 1 0 Feb 12 ? 0:03 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 23278 23006 0 12:05:26 pts/42 0:00 -csh dgerman 16141 18943 0 08:00:03 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 24021 18943 0 12:06:30 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 24034 18943 0 12:06:31 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 16100 18943 0 08:00:02 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd burrowww.cs.indiana.edu% $CATALINA_HOME/bin/startup.sh Using CATALINA_BASE: /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4 Using CATALINA_HOME: /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4 Using CATALINA_TMPDIR: /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/temp Using JAVA_HOME: /l/jdk burrowww.cs.indiana.edu% ps -ef | grep dgerman dgerman 16121 18943 0 08:00:02 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 26019 1 3 13:32:03 pts/42 0:05 /l/jdk/bin/../bin/sparc/native_threads/java -Djava.endorsed.dirs=/nfs/paca/home dgerman 16119 18943 0 08:00:02 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 16101 18943 0 08:00:02 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 18943 1 0 Feb 12 ? 0:03 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 23278 23006 0 12:05:26 pts/42 0:00 -csh dgerman 26033 23278 0 13:32:08 pts/42 0:00 grep dgerman dgerman 16141 18943 0 08:00:03 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 24021 18943 0 12:06:30 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 24034 18943 0 12:06:31 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd dgerman 16100 18943 0 08:00:02 ? 0:00 /u/dgerman/apache/apache_1.3.22/bin/httpd burrowww.cs.indiana.edu%
Try the sample servlets, then the sample JSPs.
Then stop it, using:
Then start it again and let's develop a simple application, call it$CATALINA_HOME/bin/shutdown.sh
one
.
This structure is not random or accidental, and we will revisit (and review) it soon.burrowww.cs.indiana.edu% mkdir one burrowww.cs.indiana.edu% mkdir one/WEB-INF burrowww.cs.indiana.edu% mkdir one/WEB-INF/classes burrowww.cs.indiana.edu% mkdir one/WEB-INF/lib burrowww.cs.indiana.edu% du -a one 1 one/WEB-INF/classes 1 one/WEB-INF/lib 3 one/WEB-INF 4 one burrowww.cs.indiana.edu% cd one burrowww.cs.indiana.edu% ls WEB-INF burrowww.cs.indiana.edu% cd WEB-INF burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/one/WEB-INF burrowww.cs.indiana.edu%
Then create your deployment descriptor web.xml
as follows:
Notice that theburrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/one/WEB-INF burrowww.cs.indiana.edu% ls -l total 3 drwxr-xr-x 2 dgerman faculty 512 Mar 21 12:38 classes drwxr-xr-x 2 dgerman faculty 512 Mar 21 12:38 lib -rw-r--r-- 1 dgerman faculty 340 Mar 21 12:46 web.xml burrowww.cs.indiana.edu% cat web.xml <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>howdy</servlet-name> <servlet-class>HelloWorld</servlet-class> </servlet> </web-app> burrowww.cs.indiana.edu%
examples
folder also contains a WEB-INF/web.xml
inside.
You now need to create a ServletContext
in server.xml
This line should be added in between the<Context path="/one" docBase="one" debug="0" reloadable="true" />
manager
and the examples
contexts. We now only need to write, compile, deploy the servlet.
To access it, use this URL:burrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.4/webapps/one/WEB-INF/classes burrowww.cs.indiana.edu% ls -ld Hell*.java -rw-r--r-- 1 dgerman faculty 344 Mar 21 13:03 HelloWorld.java burrowww.cs.indiana.edu% cat HelloWorld.java import javax.servlet.*; import java.io.*; public class HelloWorld extends GenericServlet { int n; public void service(ServletRequest req, ServletResponse resp) throws ServletException, IOException { n = n + 1; resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.println("Counter is: " + n); } } burrowww.cs.indiana.edu% javac Hell*.java burrowww.cs.indiana.edu% ls -ld * -rw-r--r-- 1 dgerman faculty 841 Mar 21 13:03 HelloWorld.class -rw-r--r-- 1 dgerman faculty 344 Mar 21 13:03 HelloWorld.java burrowww.cs.indiana.edu%
Bibliography for Tomcat, servlets, and J2EE:http://burrowww.cs.indiana.edu:xxzzz/one/servlet/howdy
Also tutorials on-line at java.sun.com
A348/A548 LAB ASSIGNMENT TEN