The application has been developed and tested on Windows XP using following components:
- JBoss 6.0 Application Server
- Sun JDK 1.6
- log4j 1.2.16
- Ant 1.6.5 (bundled with JWSDP 2.0, however you should download the latest version independently and use it. At this time the latest available version is 1.8.1)
Set JAVA_HOME to JDK 1.6 installation directory
Set JBOSS_HOME to JBoss 6.0 installation directory
Set ANT_HOME to Ant installation directory
Add into PATH => %JAVA_HOME%\bin;%JBOSS_HOME%\bin;%ANT_HOME%\bin
Add into CLASSPATH => %JAVA_HOME%\lib\tools.jar;.;%ANT_HOME%\lib\ant.jar
JBoss server can be started as <JBOSS_HOME>\bin\run.bat from a command window, and stopped by pressing Ctrl C in that window.
This is a simple HTML, JSP, Servlet based application. No java script has been used except calling the onClick command on a button. It provides following functionality:
- Add a new record
- Delete a record
- Update a record
- Find records based on the first name and last name.
Data will be saved into a flat file, and there are no security checks have been applied yet. These checks will be incorporated in later versions of this application.
Starting point of the application is index.jsp which calls various other jsp pages or controller servlet actions. The controller servlet will capture action commands as:
These actions have been added in the web.xml file under servlet mappings. There is only one servlet (ControllerServlet) which performs the business logic, provides results into a List and add its reference to the user session. Similarly some other data variables have also been added to the user session. Then the servlet forwards the call to an appropriate JSP page which retrieves the data from the session and displays it.
Following are the JSP pages:
- jsp\insert.jsp => inserts a record
- jsp\list.jsp => displays all the records with full information
- jsp\search.jsp => searches and displays based on the first & last name
- jsp\update.jsp => updates a record
- jsp\view.jsp => Similar to list but displays partial information only
- jsp\yes-no.jsp => Called while deleting a record for confirmation
Drop down list on update.jsp:
There are three drop down fields which are: gender, dept and title. While updating a record, these options should be displayed properly selected as previous values. This logic has been written in CommonUtils.buildOptions(), which sets the values as session attributes which then update.jsp retrieves and displays.
Log4j jar has been added under the lib directory and there is a corresponding log4j.properties file where a rolling file appender has been declared. The actual log file name comes from the build.properties via build.xml token replacement.
Currently it has following values:
FieldSeparator is the data field separator for the data file where all the records are saved into a flat file. Name of the data file also comes from the build.properties, replaced via build.xml into the web.xml init parameters.
- javac.home => Installation directory of Java JDK
- javaee.home => Installing directory of JBoss application server
- data.file => Name and location of the data file
- log.file => Name and location of the log file
I wanted to provide a delete and update button for each record separately in the table format, where if we click on the button it knows that for which userId (i.e. unique key) the button click has been made. This functionality has been provided by the onClick command of Java Script. Other button commands are simple html post forms.
How to build it:
Once you download the zip bundle, extract into a directory and run:
ant buildwar or ant final from a command window from the extracted root directory. It will generate JavaWebApp.war in the dist folder. Copy the war file into <JBOSS_HOME>\server\default\deploy directory. There is no need to restart the JBoss application server, it picks up the changes automatically and loads the web application into the JVM.
Type following URL in the browser: http://localhost:8080/JavaWebApp/
Assuming the JBoss server was already running, which can be verified by typing the URL: http://localhost:8080
The source code is self explanatory with enough comments. Following are the source code files:
Download the source code bundle:Download link