Not So Simple Stuff

If you've looked at any of the example apps in Simple Servlet Examples you know that they are pretty straight forward. The idea was to put only what was absolutely needed into the code to get the concept to work. Code comments and explanations were left out with the theory that, "If it needs to be explained, it's not simple enough".

There are a few things that I see people asking about in various JSP and Servlet forums that can't really be written without taking a little time to explain. For these projects I wanted to have a separate page. In them, I will add lots of comments and try to explain as much as possible right in the Java and JSP sources. These projects may also demonstrate more than one concept. In fact, they all will because they will all be written using MVC and will therefore be MVC examples as well as whatever else is in their titles.

NOTE:
All of these projects were written on Tomcat 5.5.9 and were compiled with jdk1.5.0. They may run on older versions of Tomcat and may run (with a recompile) on an older JVM but there are no guarantees.

Both Tomcat and the Java Software Development Kit are free so, if you have any trouble with these apps, try upgrading your environment first.


Dynamic Select Lists

The first is an app that shows how to build and read dynamic select lists using server side Java with an MVC pattern. Questions about doing this come up often in various JSP and Servlet forums. Hopefully, this demo will answer some of the more common questions such as:
  • How do I build a select list dynamically with data pulled from a database?
  • How do maintain the selected value or set a default value in a select list?
  • How do I populate one select list with data determined by the selection of another?
  • This project uses a mock database made out of a HashMap so there is no need install or configure a relational database to run it.

    Download this war file to your TOMCAT_HOME/webapps directory. Make sure that MSIE doesn't add a ".zip" extension to it (this may be hard to tell becuase Windows by default, hides extensions for known file types).
    DynamicSelectLists.war Then access the project by clicking on the following link: http://localhost:8080/DynamicSelectLists


    Session Monitor

    This app demonstrates one way of monitoring the users who are logged into your application by using a session listener to add references to all sessions into a context scoped map. It also shows how to use a ServletFilter to restrict access to any of your app's components to logged in users.

    This project uses a mock database made out of a HashMap so there is no need install or configure a relational database to run it.

    Download this war file to your TOMCAT_HOME/webapps directory. Make sure that MSIE doesn't add a ".zip" extension to it (this may be hard to tell becuase Windows by default, hides extensions for know file types).
    SessionMonitor.war Then access the project by clicking on the following link: http://localhost:8080/SessionMonitor


    Long Running Process

    This app shows one technique for improving the end user's experience when dealing with long running process (large reports, slow webservices, etc..) without leaving the user sitting at a blank browser window - wondering if their browser, or connection is hung, or if the process has indeed been started.

    Download this war file to your TOMCAT_HOME/webapps directory. Make sure that MSIE doesn't add a ".zip" extension to it (this may be hard to tell becuase Windows by default, hides extensions for know file types).
    LongRunningProcess.war Then access the project by clicking on the following link: http://localhost:8080/LongRunningProcess


    Simple Login

    Most containers have a container managed security mechanism that you can use to maintain your usernames and passwords. Often though, developers will need more functionality than this mechanism offers (get database settgings for this user, etc..). In these cases, it makes sense for the developer to write his/her own login code. This example uses a filter to verify that the user is logged in by testing for the existence of a "userBean" in session scope. If it's not there, it forwards the user to a login screen with a message letting them know they will need to login before they can access this resource. It also remembers which page they were trying to access and shows them that page, once they've logged in.
    One nice thing about using a filter for this functionality is that it can be applied to static resources as well as dynamic components such as servlets and JSPs.
    This pages leverages techniques used in SimpleMVC and SimpleCommand. The functionality in this demo also exists in the, larger, SessionMonitor demo.

    Download this war file to your TOMCAT_HOME/webapps directory. Make sure that MSIE doesn't add a ".zip" extension to it (this may be hard to tell becuase Windows by default, hides extensions for know file types).
    SimpleLogin.war Then access the project by clicking on the following link: http://localhost:8080/SimpleLogin