Today we will start from the notes of Wed July 22: http://silo.cs.indiana.edu:44063/ That day we installed Tomcat. We need two ports for Tomcat, two new ports. Our Apache ports are 44xxx (mine, for example, is 44063). Your Tomcat ports are 43xxx and 42xxx (mine: 43063 and 42063). If you follow(ed) the instructions your Tomcat will be available from http://silo.cs.indiana.edu:43xxx Last time we started the servers and created a simple index.html in $CATALINA_HOME/webapps/ROOT Let's check if the servers are still up. Here's what we see for Gang: -bash-3.2$ ps -ef | grep ggh root 1317 3861 0 15:40 ? 00:00:00 sshd: gghuang [priv] gghuang 1320 1317 0 15:40 ? 00:00:00 sshd: gghuang@pts/12 gghuang 1321 1320 0 15:40 pts/12 00:00:00 -bash dgerman 1879 775 0 15:45 pts/0 00:00:00 grep ggh gghuang 26214 1 0 Jul22 ? 00:00:31 /l/jdk1.5/bin/java -Djava.util.logging.config.file=/u/gghuang/apache-tomcat-5.5.27/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/u/gghuang/apache-tomcat-5.5.27/common/endorsed -classpath :/u/gghuang/apache-tomcat-5.5.27/bin/bootstrap.jar:/u/gghuang/apache-tomcat-5.5.27/bin/commons-logging-api.jar -Dcatalina.base=/u/gghuang/apache-tomcat-5.5.27 -Dcatalina.home=/u/gghuang/apache-tomcat-5.5.27 -Djava.io.tmpdir=/u/gghuang/apache-tomcat-5.5.27/temp org.apache.catalina.startup.Bootstrap start -bash-3.2$ Let's stop those servers that are still running. One option is: run $CATALINA_HOME/bin/shutdown.sh But this is not available since the environment variable is not defined. Why? Because our definitions last time were only temporary. Let's make them permanent: pico -w ~/.bash_profile In it at the end place these lines: JAVA_HOME=/l/jdk1.5 export JAVA_HOME CATALINA_HOME=/u/dgerman/apache-tomcat-5.5.27 export CATALINA_HOME CLASSPATH=.:$CATALINA_HOME/common/lib/servlet-api.jar export CLASSPATH In the third line replace dgerman with your actual username. So I assume that your settings are permanent now and your Tomcat is still running if you haven't stopped (since you started it, if did you start it at some point). So you can kill your server (using the process ID) or shutdown.sh Now bring your servers down and verify that they are down. I used $CATALINA_HOME/bin/shutdown.sh followed by ps -ef | grep dgerman. Let's go to $CATALINA_HOME/conf/tomcat-users.xml and add this line: So mine looks like this now: Now we start the server: $CATALINA_HOME/bin/startup.sh Let's create a context and write our first web program/script. A context in Tomcat is a folder under webapps. You can choose any name for the context but the structure is given: -bash-3.2$ pwd /u/dgerman/apache-tomcat-5.5.27/webapps -bash-3.2$ du -a vikas 8 vikas/WEB-INF/lib 8 vikas/WEB-INF/classes 24 vikas/WEB-INF 32 vikas -bash-3.2$ Let's go inside and create one.jsp: Howdy. -bash-3.2$ ls -l total 16 -rw-r--r-- 1 dgerman faculty 7 Jul 24 16:32 one.jsp drwxr-xr-x 4 dgerman faculty 4096 Jul 24 16:30 WEB-INF -bash-3.2$ cat one.jsp Howdy. -bash-3.2$ My Tomcat is not running, I start it, then check on-line: http://silo.cs.indiana.edu:43063/ The context is available, let's look at it: http://silo.cs.indiana.edu:43063/vikas Looks like it's not available. That's because it doesn't have an index.html inside. But it's working so we can try: http://silo.cs.indiana.edu:43063/vikas/one.jsp The JSP responds: Howdy. Let's develop a simple JSP. I will need the flags at http://silo.cs.indiana.edu:44063/images/ I change the JSP to: <% String number = request.getParameter("number"); String[] names = { "Australia", "Brazil", "China", "Italy", "Russia", "South Africa", "Spain", "$ int index = Integer.parseInt(number); index = index % names.length; String flag = names[index]; %>
Here's a flag: >
This is keeping state in the normal way but crashes when you first call it. We'll discuss servlets on Monday.