Fall Semester 2009


Lecture 11/12: Developing servlets.
Today we will learn to develop servlets and Java Servlet Pages.

Things we have done so far:

All of these are explained in (and we followed from) chapter 17 in the .pdf text for this class.

Now we want to start developing servlets for purposes previously pursued by Homework Two, Four, Five and Six.

Here's a reminder of the progression in complexity for the concepts/programs we followed.

Here are the links to the Flag Quiz lab development exercises:

Here are the notes for building the Flag Quiz as a servlet.

The Flag Quiz in DHTML/Javascript for Homework Six is here (just in case).

Now: writing our first servlet, deploying it, recompiling it, reloading it, converting it to JSP.

  1. Start by stopping your Tomcat and verifying that it's down.
    If it's not down use kill -9 ... on the process IDs seen with ps -ef | grep yourUsername.

  2. With Tomcat down check your $CATALINA_HOME/conf/tomcat-users.xml: you need the password for your manager role.
    If you don't have one you need to set that.

  3. If you don't have the three environment variables set you need to set them.

  4. Start Tomcat, check that it's running. Make sure your page identifies you (e.g., "Adrian's server") minimally.

  5. Create a context: name it something weird, so it sticks out.
    The result will be, for example: $CATALINA_HOME/webapps/watermelon

  6. Make sure WEB-INF and index.html appear inside it.

  7. Create and leave empty two folders: classes and lib inside WEB-INF.

  8. Access the watermelon context through Tomcat manager, look at the URL.

  9. Develop the servlet in stages, compile etc. (see below) in classes.

  10. Add web.xml in WEB-INF to deploy it. Access servlet, recompile, reload context, access servlet again.

  11. When you're done with the servlet copy it as one.jsp in ../../ relative to classes and convert it.

The rest will be added here between 10:30 and 11:00am today.


Updated by Adrian German for A202/A598, A290/A590 and A348/A548