Notes/Minute Paper for Nov. 29 1. Define a context: inside $CATALINA_HOME/webapps, create a directory - say, 'whoa' 2. Give the context directory the proper structure by creating subdirectories: whoa | WEB-INF / \ classes lib 3. Check that the context is accessible by checking the url: http://burrowww.cs.indiana.edu:#####/whoa (where '#####' is your tomcat server port number) If this doesn't work, stop and start the server (which you will have to do anyway at some point) and check this again. See step 9. 4. Go up to the WEB_INF directory and create web.xml: 1. modify the tag, and 2. the tag. In the example below the definition of Larry appears, it is standard, there is also a more sophisticated definition for some other servlet that we don't discuss: Larry Larry Larry /servlet/Larry Fv2_3 Two Fv2_3 /servlet/Fancy This step can be delayed until after you write your servlet, but must be done before you can deploy your servlet on the web. 5. Go into the classes directory and write the servlet (example): unixprompt> pico Larry.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Larry extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); // other code, such as out.println("How are you?"); } } (see Notes for lab 11 for another template) 6. Go back to classes and compile the servlet: unixprompt> javac Larry.java Correct any syntax errors preventing compilation. 7. Check that the servlet deploys by checking the url: http://burrowww.cs.indiana.edu:#####/whoa/servlet/Larry 8. Redefine $CATALINA_HOME/conf/server.xml by adding a new context definition inside the host tag. Until this step is done, the servlet will not update on the web even if you change and recompile it. 9. Stop and start the server: unixprompt> $CATALINA_HOME/bin/shutdown.sh Then check you're not running any more with: unixprompt> ps -ef | grep username (your username!) and if you are kill the process. Take the time now to delete the logs in $CATALINA_HOME/logs (useful sometimes for debugging): unixprompt> rm $CATALINA_HOME/logs/* Then restart Tomcat: unixprompt> $CATALINA_HOME/bin/startup.sh Now the servlet will update on the web each time you recompile, so you can edit and update conveniently.