![]() |
![]()
T540 Spring Semester 2002 |
In which we finish the installation of Tomcat.
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.3 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
I have already prepared aburrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.3/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="36401" shutdown="SHUTDOWN" debug="0"> <Service name="Tomcat-Standalone"> <Connector className="org.apache.catalina.connector.http.HttpConnector" port="36400" 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%
server.xml
for each one of you. Here's where you can find them:
Once you haveburrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/public/tomcats burrowww.cs.indiana.edu% ls -ld serv* -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.arausche -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.bkeese -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.cmfriend -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.cmhall -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.dgerman -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.dheald -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.gpolit -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.jchong -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.jffox -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.jfleetwo -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.jlbaumga -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.meblewis -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.ncincott -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.nlu -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.thom -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.thscott -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.wehrlich -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.wpernice -rw-r--r-- 1 dgerman faculty 2774 Mar 21 11:00 server.xml.yinjin burrowww.cs.indiana.edu%
server.xml
place start Tomcat.
Then test it, here's the list of assigned ports: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.3 Using CATALINA_HOME: /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.3 Using CATALINA_TMPDIR: /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.3/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%
These ports are already written in the201,BL,1255,36000,Last Name, First Name ,dgerman ,36400 201,BL,T540,36084,Baumgartner, Jason ,jlbaumga ,36402 201,BL,T540,36085,Cincotta, Nicholas ,ncincott ,36404 201,BL,T540,36086,Ehrlichman, Wesley ,wehrlich ,36406 201,BL,T540,36087,Fleetwood, Joshua ,jfleetwo ,36408 201,BL,T540,36088,Fox, John ,jffox ,36410 201,BL,T540,36089,Friend, Christopher ,cmfriend ,36412 201,BL,T540,36090,Hall, Christopher ,cmhall ,36414 201,BL,T540,36091,Heald, David ,dheald ,36416 201,BL,T540,36092,Keese, Brian ,bkeese ,36418 201,BL,T540,36093,Lewis, Megan ,meblewis ,36420 201,BL,T540,36094,Lu, Nan ,nlu ,36422 201,BL,T540,36095,Polit, Gregory ,gpolit ,36424 201,BL,T540,36096,Rauscher, Andrew ,arausche ,36426 201,BL,T540,36097,Scott, Thomas ,thscott ,36428 201,BL,T540,36098,CHONG, Ji Young ,jchong ,36430 201,BL,T540,36099,Pernice, Wolfram ,wpernice ,36432 201,BL,T540,36109,Jin, Ying ,yinjin ,36434 201,BL,T540,36111,Gillespie, Thom ,thom ,36436
server.xml.username
files. Try the sample servlets, then the sample JSPs.
Then stop it, using:
Then start it again and let's develop a simple application.$CATALINA_HOME/bin/shutdown.sh
The code we need to use is available in
But first let's develop a simple application, call it/l/www/classes/a348/t540/lectures/servlets/jservlet2-examples/ch10
one
.
Then create your deployment descriptorburrowww.cs.indiana.edu% mkdir one burrowww.cs.indiana.edu% mkdir one/WEB-IN 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.3/webapps/one/WEB-INF burrowww.cs.indiana.edu%
web.xml
as follows:
Notice thatburrowww.cs.indiana.edu% pwd /nfs/paca/home/user1/dgerman/tomcat/jakarta-tomcat-4.0.3/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
also contain 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.3/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%
The rest of the lecture/lab will be dedicated to chapter 10 from Jason Hunter's book.http://burrowww.cs.indiana.edu:364xx/one/servlet/howdy
That's basically a triple-chat application.
The code we need to use is available in
Bibliography for Tomcat, servlets, and J2EE:/l/www/classes/a348/t540/lectures/servlets/jservlet2-examples/ch10
Also tutorials on-line at java.sun.com
Say we keep everything in the same application, one
.
Start by copying the entire code in the classes
folder.
Now we need to identify three groups of files.
Group One: Client Side.
This is composed of the following three files:
DayTimeApplet.java
daytime.html
HttpMessage.java
htdocs
(webapps/ROOT/index.html
). Group Two: Server Side.
This is composed of the following two files:
DayTimeServlet.java
DaemonHttpServlet.java
These are to be placed in classes
.
Compile them all.
Notice that we implement applet-servlet connections in five ways:
That is needed for the socket communication.
The value is to be initialized as a parameter for both.
This will likely be shown next time.
Today we should implement the basic HTTP chat applet.