To Do List

JSP

So! Who does not have things to do? Who does not have too many things to do? Life is not all about lists, but life is often better with well designed lists. This application is really just an exercise in JSP coding and list maintenance, but if you find it useful for time and resources management, that's great!

First of all, we need a place to keep our records. Here is a reasonably well defined table to get you started. You may add fields or rename or whatever, but make sure you note, and code for, the changes you make... -- DROP TABLE ToDo ; CREATE TABLE ToDo ( 	id            INTEGER, -- unique id 	description   VARCHAR(255),  	priority      VARCHAR(63), -- high, urgent, low, etc. 	status        VARCHAR(63), -- onhold, active, etc. 	dateDue       TIMESTAMP,  	dateInsert    TIMESTAMP,  	dateUpdate    TIMESTAMP  ) ;

Here is a screen shot of the main page.



Here is the code. &lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.text.*" import="java.io.*" import="java.sql.*" import="java.util.*" errorPage="" %> &lt;%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> &lt;% /* * ToDoList.jsp * * Copyright (c) 2013 Alfred J Wheeler * All rights reserved. * * This software is the proprietary * information of Alfred J Wheeler * */ /**  * The purpose of this program is to provide quick links to  * favorite or frequently visited WWW pages. * * SYNTAX *  ToDoList.jsp * * @author      8/14/2013 created by Alfred J Wheeler. * * @version     0.1 * * @see         AddNewToDoItem, EditToDoItem, DeleteToDoItem, ViewToDoItem * */ /*  * Database : demonstration, Table : todo *  * field name                        data type * ---  ---  * id                                integer * description                      character varying(255) * priority                         character varying(63) * status                           character varying(63) * datedue                          timestamp without time zone * sourceinsert                     character varying(63) * dateinsert                       timestamp without time zone * sourceupdate                     character varying(63) * dateupdate                       timestamp without time zone */ /* * Initialize some variables */ String message = ""; long dt = 0; String title = null; Connection conn = null; Statement st = null; ResultSet rs = null; String sql = ""; /* * Get a date time stamp. Set a page title, if needed... */ dt = System.currentTimeMillis; title = "ToDo"; /* * Get the database connection values, etc... from the properties file * ( This eventually will be externalized to reduce code clutter... ) */ String p = application.getRealPath("/") + "properties/Demo.properties"; InputStream propsFile; Properties appProp = new Properties; try { propsFile = new FileInputStream(p); appProp.load(propsFile); propsFile.close; } catch (IOException ioe) { out.println("&lt;PRE>"); out.println("I/O Exception."); ioe.printStackTrace; out.println("&lt;/PRE>"); } String dbDriver = "" + appProp.getProperty("dbDriver"); String dbUrl   = "" + appProp.getProperty("dbUrl"); String dbUid   = "" + appProp.getProperty("dbUid"); String dbUpw   = "" + appProp.getProperty("dbUpw"); String css     = "" + appProp.getProperty("css"); //out.println("&lt;PRE>"); //out.println(dbDriver); //out.println(dbUrl); //out.println(dbUid); //out.println(dbUpw); //out.println("&lt;/PRE>"); /* * Open the database */ try { Class.forName(dbDriver); conn = DriverManager.getConnection(dbUrl, dbUid, dbUpw); st = conn.createStatement; %> &lt;!DOCTYPE html> &lt;HTML> &lt;HEAD> &lt;link rel="stylesheet" type="text/css" href="&lt;%=css%>"> &lt;TITLE>&lt;%=title%>&lt;/TITLE> &lt;SCRIPT LANGUAGE="JavaScript" SRC="angular.js">&lt;/SCRIPT> &lt;SCRIPT LANGUAGE="JavaScript" SRC="jquery.js">&lt;/SCRIPT> &lt;/HEAD> &lt;BODY> &lt;H1>&lt;%=title%>&lt;/H1> &lt;br> &lt;div class="centered"> &lt;nobr> &lt;form action="ToDoAdd.jsp" name=f> &lt;input name=btnG type=submit value=" Add New ToDo Item "> &lt;/form> &lt;/nobr> &lt;/div> &lt;br> &lt;TABLE border="1" cellspacing="0"> &lt;TBODY> &lt;th colspan="2"> Item &lt;/th> &lt;% sql = "SELECT " + "id AS todo_id, " + "description AS todo_description, " + "priority AS todo_priority, " + "status AS todo_status, " + "datedue AS todo_datedue " + "FROM ToDo " + "ORDER BY UPPER( description )"; //		out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); while(rs.next) { out.println( "&lt;tr>" ); out.println( "&lt;td>" + rs.getString("todo_description") + "&lt;/td>" ); out.println( "&lt;td>" ); out.println( "&lt;table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">" ); out.println( "&lt;tr>" ); out.println( "&lt;td>" ); out.println( "&lt;form action=\"ToDoView.jsp\" name=\"view\">" ); out.println( "&lt;input name=\"todo_id\" type=\"hidden\" value=\"" + rs.getString("todo_id") + "\">" ); out.println( "&lt;input name=\"btnG\" type=\"submit\" value=\"View Item\">" ); out.println( "&lt;/form>" ); out.println( "&lt;/td>" ); out.println( "&lt;td>" ); out.println( "&lt;form action=\"ToDoEdit.jsp\" name=\"edit\">" ); out.println( "&lt;input name=\"todo_id\" type=\"hidden\" value=\"" + rs.getString("todo_id") + "\">" ); out.println( "&lt;input name=\"btnG\" type=\"submit\" value=\"Edit Item\">" ); out.println( "&lt;/form>" ); out.println( "&lt;/td>" ); out.println( "&lt;td>" ); out.println( "&lt;form action=\"ToDoRemove.jsp\" name=\"remove\">" ); out.println( "&lt;input name=\"todo_id\" type=\"hidden\" value=\"" + rs.getString("todo_id") + "\">" ); out.println( "&lt;input name=\"btnG\" type=\"submit\" value=\"Remove Item\">" ); out.println( "&lt;/form>" ); out.println( "&lt;/td>" ); out.println( "&lt;/tr>" ); out.println( "&lt;/table>" ); out.println( "&lt;/td>" ); out.println( "&lt;/tr>" ); } %> &lt;/tbody>&lt;/table> &lt;% } // end try catch ( SQLException ex ) { out.println ( "&lt;pre>" ); out.println ( "---" ); out.println ( "--                      FATAL ERROR IN SQL" ); out.println ( "---" ); out.println ( "-- " ); while ( ex != null ) { out.println ("-- SQLState: " + ex.getSQLState ); out.println ("-- Message: " + ex.getMessage ); out.println ("-- Vendor:  " + ex.getErrorCode ); ex = ex.getNextException ; out.println ( "-- " ); } 		out.println ( "---" ); } // end catch catch ( java.lang.Exception ex ) { /* 		 * Got some other type of exception. Dump it. */ 		out.println ( "&lt;pre>" ); out.println ( "---" ); ex.printStackTrace ; out.println("exception: " + ex.getMessage ); } // end catch finally { // No action for now } // end finally %> &lt;br>&lt;br>&lt;br>&lt;br> &lt;/body> &lt;/html>

The thing about lists is that they are always growing. Here is a screen shot of the Add (To Do List item) page.



Here is the code. &lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.io.*" import="java.sql.*" import="java.util.*" import="java.util.Properties" errorPage="" %> &lt;%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> &lt;% /* * ToDoAdd.jsp * * Copyright (c) 2013 Alfred J Wheeler * All rights reserved. * * This software is the proprietary * information of Alfred J Wheeler * */ /**  * The purpose of this application is to add a record to table "todo" * * SYNTAX *  ToDoAdd.jsp * * @author      8/20/2013 created by Alfred J Wheeler. * * @version     0.1 * * @see         ToDoList, ToDoView, ToDoEdit, ToDoDelete * */ /*  * Database : demonstration, Table : todo *  * field name                        data type * ---  ---  * id                                integer * description                      character varying(255) * priority                         character varying(63) * status                           character varying(63) * datedue                          timestamp without time zone * sourceinsert                     character varying(63) * dateinsert                       timestamp without time zone * sourceupdate                     character varying(63) * dateupdate                       timestamp without time zone */ /* * Initialize some variables */ long dt = 0; String title = null; Connection conn = null; Statement st = null; ResultSet rs = null; String sql = ""; String posted = "false"; boolean populated = true; boolean duplicate = false; int records = 0; String message = ""; int errors = 0; //String tableName = null; String todoDescription = ""; String todoPriority = ""; String todoStatus = ""; String todoDatedue = ""; /* * Get a date time stamp. Set a page title, if needed... */ dt = System.currentTimeMillis; title = "ToDo - Add New Item"; //tableName = "todo"; /* * Get the database connection values, etc... from the properties file * ( This eventually will be externalized to reduce code clutter... ) */ String p = application.getRealPath("/") + "properties/Demo.properties"; InputStream propsFile; Properties appProp = new Properties; try { propsFile = new FileInputStream(p); appProp.load(propsFile); propsFile.close; } catch (IOException ioe) { out.println("&lt;PRE>"); out.println("I/O Exception."); ioe.printStackTrace; out.println("&lt;/PRE>"); } String dbDriver = "" + appProp.getProperty("dbDriver"); String dbUrl   = "" + appProp.getProperty("dbUrl"); String dbUid   = "" + appProp.getProperty("dbUid"); String dbUpw   = "" + appProp.getProperty("dbUpw"); String css     = "" + appProp.getProperty("css"); //out.println("&lt;PRE>"); //out.println(dbDriver); //out.println(dbUrl); //out.println(dbUid); //out.println(dbUpw); //out.println("&lt;/PRE>"); /* * Open the database */ try { Class.forName(dbDriver); conn = DriverManager.getConnection(dbUrl, dbUid, dbUpw); st = conn.createStatement; /* 	 * Get the request values */ 	if ( request.getParameter( "posted" ) == null ) { posted = "false"; } 	else { posted = request.getParameter( "posted" ); } 	if ( posted.equals("true") ) { /* 		 * Are the fields populated? */ 		todoDescription = request.getParameter( "todo_description" ); // required todoPriority = request.getParameter( "todo_priority" ); // default urgent? todoStatus = request.getParameter( "todo_status" ); // default open todoDatedue = request.getParameter( "todo_datedue" ); // default null allowed populated = true; if ( (request.getParameter( "todo_description" )).equals( "" ) ) { if ( (request.getParameter( "todo_priority" )).equals( "" ) ) { if ( (request.getParameter( "todo_status" )).equals( "" ) ) { if ( (request.getParameter( "todo_datedue" )).equals( "" ) ) { populated = false; message = "Blank record not allowed. Please enter some values."; errors++; } 				} 			} 		} 		/* 		 * Does record exist already? */ 		duplicate = false; if ( populated ) { sql = "SELECT COUNT(*) AS records " + "FROM " + "todo" + " " + // It may make sense to use a variable here at some point... "WHERE description = '" + request.getParameter( "todo_description" ) + "' " + "AND priority = '" + request.getParameter( "todo_priority" ) + "' " + "AND status = '" + request.getParameter( "todo_status" ) + "' " ; // should also check datedue! //			out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { records = Integer.parseInt( rs.getString("records") ); if ( records > 0 ) { duplicate = true; message = "Record already exists. Duplicate records not allowed. Please check your entries."; errors++; } 			} 		} 		/* 		 * If no error, save data, clear fields, display form */ 		/* 		 * Save data... */ 		if ( errors == 0 ) { sql = "INSERT INTO " + "todo" + " " + // It may make sense to use a variable for the tableName here at some point... "SELECT " + "(SELECT COALESCE(MAX(id), 0) + 1 FROM todo) AS id, " + "'" + request.getParameter( "todo_description" ) + "' AS description, " + "'" + request.getParameter( "todo_priority" ) + "' AS priority, " + "'" + request.getParameter( "todo_status" ) + "' AS status, " + "" + "NOW" + " AS datedue, " + "'" + "WEBUSER" + "' AS sourceinsert, " + "" + "NOW" + " AS dateinsert, " + "'" + "WEBUSER" + "' AS sourceupdate, " + "" + "NOW" + " AS dateupdate "; //			out.print("sql = " + sql + " \n"); st.execute(sql); } 		/* 		 * Clear fields... */ 		todoDescription = ""; todoPriority = ""; todoStatus = ""; todoDatedue = ""; /* 		 * If error, display form as is with the message produced by the preceding code... 		 */ } %> &lt;!DOCTYPE html> &lt;HTML> &lt;HEAD> &lt;link rel="stylesheet" type="text/css" href="&lt;%=css%>"> &lt;TITLE>&lt;%=title%>&lt;/TITLE> &lt;SCRIPT LANGUAGE="JavaScript" SRC="angular.js">&lt;/SCRIPT> &lt;SCRIPT LANGUAGE="JavaScript" SRC="jquery.js">&lt;/SCRIPT> &lt;/HEAD> &lt;BODY> &lt;H1>&lt;%=title%>&lt;/H1> &lt;br> &lt;div align="center"> &lt;nobr> &lt;div class="centered"> &lt;nobr> &lt;form action="ToDoList.jsp" name=f> &lt;input name=btnG type=submit value=" Return to ToDo List "> &lt;/form> &lt;/nobr> &lt;/div> &lt;br> &lt;p class="centered">&lt;%=message%>&lt;/p> &lt;FORM NAME="form1" METHOD="POST"> &lt;!--Get time and pass as hidden variable in query_string to force browser to get page from server instead of cache... --> &lt;% dt = System.currentTimeMillis; %> &lt;input type="hidden" name="dt&lt;%= dt %>" value="&lt;%= dt %>"> &lt;input type="hidden" name="posted" value="true"> &lt;input type="hidden" name="tableName" value="todo"> &lt;table class="ivory" align="center" border="0" cellspacing="0" cellpadding="16"> &lt;TBODY> &lt;tr> &lt;td>&lt;b>Description:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="todo_description" size="127" value="&lt;%=todoDescription%>">&lt;/td> &lt;/tr> &lt;tr> &lt;td>&lt;b>Priority:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="todo_priority" size="127" value="&lt;%=todoPriority%>">&lt;/td> &lt;/tr> &lt;tr> &lt;td>&lt;b>Status:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="todo_status" size="127" value="&lt;%=todoStatus%>">&lt;/td> &lt;/tr> &lt;tr> &lt;td>&lt;b>Date due:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="todo_datedue" size="127" value="&lt;%=todoDatedue%>">&lt;/td> &lt;/tr> &lt;tr> &lt;td> &lt;/td>&lt;td> &lt;div > &lt;input type="submit" name="submit" value="Submit"> &lt;input type="reset" name="clear" value="Reset"> &lt;/div> &lt;/td> &lt;/tr> &lt;/table> &lt;br>&lt;br> &lt;/form> &lt;/nobr> &lt;/div> &lt;br>&lt;br>&lt;br>&lt;br> &lt;/body> &lt;/html> &lt;% } // end try catch ( SQLException ex ) { out.println ( "&lt;pre>" ); out.println ( "---" ); out.println ( "--                      FATAL ERROR IN SQL" ); out.println ( "---" ); out.println ( "-- " ); while ( ex != null ) { out.println ("-- SQLState: " + ex.getSQLState ); out.println ("-- Message: " + ex.getMessage ); out.println ("-- Vendor:  " + ex.getErrorCode ); ex = ex.getNextException ; out.println ( "-- " ); } 		out.println ( "---" ); } // end catch catch ( java.lang.Exception ex ) { /* 		 * Got some other type of exception. Dump it. */ 		out.println ( "&lt;pre>" ); out.println ( "---" ); ex.printStackTrace ; out.println("exception: " + ex.getMessage ); } // end catch finally { // No action for now } // end finally %>

Sometimes we need to think about more than just what need to get done, e.g. when is an item due? Let's look at the details! Here is a screen shot of the View (To Do List) Item page.



Here is the code. &lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.io.*" import="java.sql.*" import="java.util.*" import="java.util.Properties" errorPage="" %> &lt;%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> &lt;% /* * ToDoView.jsp * * Copyright (c) 2013 Alfred Wheeler * All rights reserved. * * This software is the proprietary * information of Alfred Wheeler * */ /**  * The purpose of this application is to remove a record from the table * * SYNTAX *  ToDoView.jsp * * @author      8/22/2013 created by Alfred Wheeler. * * @version     0.1 * * @see         ToDoList, ToDoAdd, ToDoEdit, ToDoRemove * */ /*  * Database : demonstration, Table : todo *  * field name                        data type * ---  ---  * id                                integer * description                      character varying(255) * priority                         character varying(63) * status                           character varying(63) * datedue                          timestamp without time zone * sourceinsert                     character varying(63) * dateinsert                       timestamp without time zone * sourceupdate                     character varying(63) * dateupdate                       timestamp without time zone */ /* * Initialize some variables */ String message = ""; long dt = 0; String title = null; Connection conn = null; DatabaseMetaData dbmd = null; Statement st = null; ResultSet rs = null; ResultSetMetaData rsmd = null; String sql = ""; Integer columns = 0; int column = 0; String s = null; // miscellaneous utility variable String fields = null; /* * Get a date time stamp. Set a page title, if needed... */ dt = System.currentTimeMillis; title = "ToDo - View Item"; /* * Get the database connection values, etc... from the properties file * ( This eventually will be externalized to reduce code clutter... ) */ String p = application.getRealPath("/") + "properties/Demo.properties"; InputStream propsFile; Properties appProp = new Properties; try { propsFile = new FileInputStream(p); appProp.load(propsFile); propsFile.close; } catch (IOException ioe) { out.println("&lt;PRE>"); out.println("I/O Exception."); ioe.printStackTrace; out.println("&lt;/PRE>"); } String dbDriver = "" + appProp.getProperty("dbDriver"); String dbUrl   = "" + appProp.getProperty("dbUrl"); String dbUid   = "" + appProp.getProperty("dbUid"); String dbUpw   = "" + appProp.getProperty("dbUpw"); String css     = "" + appProp.getProperty("css"); /* * Open the database */ try { Class.forName(dbDriver); conn = DriverManager.getConnection(dbUrl, dbUid, dbUpw); st = conn.createStatement; %> &lt;!DOCTYPE html> &lt;HTML> &lt;HEAD> &lt;link rel="stylesheet" type="text/css" href="&lt;%=css%>"> &lt;TITLE>&lt;%=title%>&lt;/TITLE> &lt;SCRIPT LANGUAGE="JavaScript" SRC="angular.js">&lt;/SCRIPT> &lt;SCRIPT LANGUAGE="JavaScript" SRC="jquery.js">&lt;/SCRIPT> &lt;/HEAD> &lt;BODY> &lt;H1>&lt;%=title%>&lt;/H1> &lt;br>&lt;br>&lt;br>&lt;br> &lt;div class="centered"> &lt;nobr> &lt;form action="ToDoList.jsp" name=f> &lt;input name=btnG type=submit value=" Return to ToDo List "> &lt;/form> &lt;/nobr> &lt;/div> &lt;br> &lt;% fields = "id, description, priority, status, datedue"; // will implement this later... sql = "SELECT " + fields + " FROM " + "todo" + " " + "WHERE id = " + request.getParameter( "todo_id" ) + " "; //out.print("\n\nsql = " + sql + "\n\n"); rs = st.executeQuery(sql); rsmd = rs.getMetaData; columns = rsmd.getColumnCount; rs = st.executeQuery(sql); if (rs.next) { %> &lt;div class="centered"> &lt;FORM NAME="form1" METHOD="POST" ACTION="ToDoList.jsp"> &lt;!--Get time and pass as hidden variable in query_string to force browser to get page from server instead of cache... --> &lt;% dt = System.currentTimeMillis; %> &lt;input type="hidden" name="dt&lt;%= dt %>" value="&lt;%= dt %>"> &lt;table class="ivory" border="0" cellspacing="0"> &lt;TBODY> &lt;tr>&lt;th>Field&lt;/th>&lt;th>Value&lt;/th>&lt;/tr> &lt;% for( column=1; column&lt;=columns ; column++ ) { out.println ( "&lt;tr align=\"left\">" ); out.println ( "&lt;td>&lt;b>" + rsmd.getColumnName( column ) + ":&lt;/B>&lt;/td>" ); out.println ( "&lt;td>" + rs.getString( rsmd.getColumnName( column ) ) + "&lt;/td>" ); out.println ( "&lt;/tr>" ); } %> &lt;tr align="left"> &lt;td> &lt;/td>&lt;td> &lt;div > &lt;input type="submit" name="submit" value=" Okay "> &lt;/div> &lt;/td> &lt;/tr> &lt;/table> &lt;br>&lt;br> &lt;/form> &lt;/div> &lt;% } // end if for result set handling } // end try catch ( SQLException ex ) { out.println ( "&lt;pre>" ); out.println ( "---" ); out.println ( "--                      FATAL ERROR IN SQL" ); out.println ( "---" ); out.println ( "-- " ); while ( ex != null ) { out.println ("-- SQLState: " + ex.getSQLState ); out.println ("-- Message: " + ex.getMessage ); out.println ("-- Vendor:  " + ex.getErrorCode ); ex = ex.getNextException ; out.println ( "-- " ); } 	out.println ( "---" ); } // end catch catch ( java.lang.Exception ex ) { /* 	 * Got some other type of exception. Dump it. */ 	out.println ( "&lt;pre>" ); out.println ( "---" ); ex.printStackTrace ; out.println("exception: " + ex.getMessage ); } // end catch finally { // No action for now } // end finally %> &lt;/body> &lt;/html>

Hopefully, at some point we can update the status of some of our projects  to mark progress or even completion. Here is a screen shot of the Edit (To Do List item) page.



Here is the code. &lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.io.*" import="java.sql.*" import="java.util.*" import="java.util.Properties" errorPage="" %> &lt;%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> &lt;% /* * ToDoEdit.jsp * * Copyright (c) 2013 Alfred Wheeler * All rights reserved. * * This software is the proprietary * information of Alfred Wheeler * */ /**  * The purpose of this application is to edit a record of table "todo" * * SYNTAX *  ToDoEdit.jsp * * @author      8/20/2013 created by Alfred Wheeler. * * @version     0.1 * * @see         ToDoList, ToDoAdd, ToDoView, ToDoRemove * */ /*  * Database : demonstration, Table : todo *  * field name                        data type * ---  ---  * id                                integer * description                      character varying(255) * priority                         character varying(63) * status                           character varying(63) * datedue                          timestamp without time zone * sourceinsert                     character varying(63) * dateinsert                       timestamp without time zone * sourceupdate                     character varying(63) * dateupdate                       timestamp without time zone */ /* * Initialize some variables */ String message = ""; long dt = 0; String title = null; Connection conn = null; Statement st = null; ResultSet rs = null; String sql = ""; String posted = "false"; boolean populated = true; boolean recordExists = true; boolean duplicate = false; boolean updated = false; int records = 0; int errors = 0; //String tableName = null; String todoId = ""; String editToDoDescription = ""; String editToDoPriority = ""; String editToDoStatus = ""; String editToDoDateDue = ""; String s = null; // miscellaneous utility variable /* * Get a date time stamp. Set a page title, if needed... */ dt = System.currentTimeMillis; title = "ToDo - Edit Item"; /* * Get the database connection values, etc... from the properties file * ( This should be externalized to reduce code clutter... ) */ String p = application.getRealPath("/") + "properties/Demo.properties"; InputStream propsFile; Properties appProp = new Properties; try { propsFile = new FileInputStream(p); appProp.load(propsFile); propsFile.close; } catch (IOException ioe) { out.println("&lt;PRE>"); out.println("I/O Exception."); ioe.printStackTrace; out.println("&lt;/PRE>"); } String dbDriver = "" + appProp.getProperty("dbDriver"); String dbUrl   = "" + appProp.getProperty("dbUrl"); String dbUid   = "" + appProp.getProperty("dbUid"); String dbUpw   = "" + appProp.getProperty("dbUpw"); String css     = "" + appProp.getProperty("css"); //out.println("&lt;PRE>"); //out.println(dbDriver); //out.println(dbUrl); //out.println(dbUid); //out.println(dbUpw); //out.println("&lt;/PRE>"); /* * Open the database */ try { Class.forName(dbDriver); conn = DriverManager.getConnection(dbUrl, dbUid, dbUpw); st = conn.createStatement; /* 	 * Get the request values */ 	if ( request.getParameter( "posted" ) == null ) { posted = "false"; } 	else { posted = request.getParameter( "posted" ); } 	if ( posted.equals("true") ) { /* 		 * 1. Check that the entries are not all blanked out (we don't want to erase any records...) * 2. Check that the entries are valid for their kind (a moot point, for this particular application...) * 3. Check that the significant (primary key) changes do not duplicate any other record... * 3. Make sure the record exists and, ideally, lock it, during the update * 4. Apply the change(s) * 5. Return to list */ 		/* 		 * Are the fields populated? */ 		todoId = request.getParameter( "todo_id" ); editToDoDescription = request.getParameter( "editToDoDescription" ); editToDoPriority = request.getParameter("editToDoPriority"); editToDoStatus = request.getParameter("editToDoStatus"); editToDoDateDue = request.getParameter("editToDoDatedue"); populated = true; if ( (request.getParameter( "editToDoDescription" )).equals( "" ) ) { message = "Description is a required field. Please enter something."; errors++; } 		if ( (request.getParameter( "editToDoPriority" )).equals( "" ) ) { //			message = "Priority is required. Please select a value."; //			errors++; } 		/* 		 * Does record "still" exist? */ 		recordExists = true; if ( populated ) { sql = "SELECT COUNT(*) AS records " + "FROM " + "todo" + " " + // It may make sense to use a variable for table_name at some point... "WHERE id = " + request.getParameter( "todo_id" ) ; //			out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { records = Integer.parseInt( rs.getString("records") ); if ( records &lt; 1 ) { recordExists = false; message = "Record does not exist. You may have removed by some other means or another page."; errors++; } 			} 		} 		/* 		 * Would the change cause an "exact" duplicate? */ 		duplicate = false; if ( populated ) { sql = "SELECT COUNT(*) AS records " + "FROM " + "todo" + " " + // It may make sense to use a variable here at some point... "WHERE description = '" + request.getParameter( "editToDoDescription" ) + "' " + "AND id != " + request.getParameter( "todo_id" ) ; //			out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { records = Integer.parseInt( rs.getString("records") ); if ( records > 0 ) { duplicate = true; message = "Record already exists. Duplicate records not allowed. Please check your entries."; errors++; } 			} 		} 		/* 		 * If no error, save data, clear fields, display form */ 		/* 		 * Save data... */ 		if ( errors == 0 ) { // This should be a call to a stored procedure... /* 			 * 1. Check that the entries are not all blanked out (we don't want to erase any records...) * 2. Check that the entries are valid for their kind * 3. Check that the significant (primary key) changes do not duplicate any other record... * 3. Make sure the record exists and, ideally, lock it, during the update * 4. Apply the change(s) * 5. Return to list */ 			// a) This should be a call to a stored procedure... b) change datedue to varchar sql = "UPDATE todo SET " + "description = '" + request.getParameter( "editToDoDescription" ) + "', " + "priority = '" + request.getParameter( "editToDoPriority" ) + "', " + "status = '" + request.getParameter( "editToDoStatus" ) + "', " + "datedue = '" + "NOW" + "', " + "sourceupdate = '" + "WEBUSER" + "', " + "dateupdate = " + "NOW" + " " + "WHERE id = '" + request.getParameter( "todo_id" ) + "' "; //out.println( "sql = " + sql); st.execute( sql ); /* 			 * Return to list.... */ %> &lt;HTML> &lt;HEAD>&lt;TITLE>&lt;/TITLE>&lt;/HEAD> &lt;BODY onload="document.form1.submit"> &lt;div> &lt;form name="form1" method="POST" action="ToDoList.jsp?&lt;%=System.currentTimeMillis%>"> &lt;input type="image" src="images/dots/clear.gif" alt="submit" value="Continue"> &lt;/form> &lt;/div> &lt;% updated = true; } 	} 	else { // This is the first time here, so get the values from the database table /* 		 * Must work out automating getting (or just editing) only the fields that are relevant, e.g. 		 * the timestamps are generally not that relevant to data entry persons * 		 * id                                integer * description                      character varying(255) * priority                         character varying(63) * status                           character varying(63) * datedue                          timestamp without time zone * sourceinsert                     character varying(63) * dateinsert                       timestamp without time zone * sourceupdate                     character varying(63) * dateupdate                       timestamp without time zone */ 		sql = "SELECT " + // consider adding an id field to possibly simplify things... "id AS todo_id, " + "description AS todo_description, " + "priority AS todo_priority, " + "status AS todo_status, " + "datedue AS todo_datedue " + "FROM todo " + "WHERE id = " + request.getParameter( "todo_id" ) + " "; //		out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { editToDoDescription = rs.getString("todo_description"); editToDoPriority = rs.getString("todo_priority"); editToDoStatus = rs.getString("todo_status"); editToDoDateDue = rs.getString("todo_datedue"); } 	} 	if ( updated == false ) { %> &lt;!DOCTYPE html> &lt;HTML> &lt;HEAD> &lt;link rel="stylesheet" type="text/css" href="&lt;%=css%>"> &lt;TITLE>&lt;%=title%>&lt;/TITLE> &lt;SCRIPT LANGUAGE="JavaScript" SRC="angular.js">&lt;/SCRIPT> &lt;SCRIPT LANGUAGE="JavaScript" SRC="jquery.js">&lt;/SCRIPT> &lt;/HEAD> &lt;BODY> &lt;H1>&lt;%=title%>&lt;/H1> &lt;br>&lt;br>&lt;br>&lt;br> &lt;div class="centered"> &lt;nobr> &lt;form action="ToDoList.jsp" name=f> &lt;input name=btnG type=submit value=" Return to ToDo List "> &lt;/form> &lt;/nobr> &lt;/div> &lt;br> &lt;p class="centered">&lt;%=message%>&lt;/p> &lt;div class="centered"> &lt;FORM NAME="form1" METHOD="POST"> &lt;!--Get time and pass as hidden variable in query_string to force browser to get page from server instead of cache... --> &lt;% dt = System.currentTimeMillis; %> &lt;input type="hidden" name="dt&lt;%= dt %>" value="&lt;%= dt %>"> &lt;input type="hidden" name="posted" value="true"> &lt;input type="hidden" name="todo_id" value="&lt;%= rs.getString("todo_id") %>"> &lt;table border="1"> &lt;TBODY> &lt;tr align="left"> &lt;td>&lt;b>Description:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="editToDoDescription" size="127" value="&lt;%= editToDoDescription%>">&lt;/td> &lt;/tr> &lt;tr align="left"> &lt;td>&lt;b>Priority:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="editToDoPriority" size="127" value="&lt;%= editToDoPriority%>">&lt;/td> &lt;/tr> &lt;tr align="left"> &lt;td>&lt;b>Status:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="editToDoStatus" size="127" value="&lt;%= editToDoStatus%>">&lt;/td> &lt;/tr> &lt;tr align="left"> &lt;td>&lt;b>Date due:&lt;/B>&lt;/td>&lt;td>&lt;input type="text" name="editToDoDateDue" size="127" value="&lt;%= editToDoDateDue%>">&lt;/td> &lt;/tr> &lt;tr align="left"> &lt;td> &lt;/td>&lt;td> &lt;div > &lt;input type="submit" name="submit" value="Submit"> &lt;input type="reset" name="clear" value="Reset"> &lt;/div> &lt;/td> &lt;/tr> &lt;/table> &lt;br>&lt;br> &lt;/form> &lt;/div> &lt;% } // end if for result set handling } // end try catch ( SQLException ex ) { out.println ( "&lt;pre>" ); out.println ( "---" ); out.println ( "--                      FATAL ERROR IN SQL" ); out.println ( "---" ); out.println ( "-- " ); while ( ex != null ) { out.println ("-- SQLState: " + ex.getSQLState ); out.println ("-- Message: " + ex.getMessage ); out.println ("-- Vendor:  " + ex.getErrorCode ); ex = ex.getNextException ; out.println ( "-- " ); } 	out.println ( "---" ); } // end catch catch ( java.lang.Exception ex ) { /* 	 * Got some other type of exception. Dump it. */ 	out.println ( "&lt;pre>" ); out.println ( "---" ); ex.printStackTrace ; out.println("exception: " + ex.getMessage ); } // end catch finally { // No action for now } // end finally %> &lt;/body> &lt;/html>

Rarely, we need to be able to remove an item from our "To Do" list, but rarely is not never... Here is a screen shot of the "To Do Remove Item" page.



Here is the code.

&lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.io.*" import="java.sql.*" import="java.util.*" import="java.util.Properties" errorPage="" %> &lt;%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> &lt;% /* * ToDoRemove.jsp * * Copyright (c) 2013 Alfred Wheeler * All rights reserved. * * This software is the proprietary * information of Alfred Wheeler * */ /**  * The purpose of this application is to remove a record from table WebLink * * SYNTAX *  ToDoRemove.jsp * * @author      8/22/2013 created by Alfred Wheeler. * * @version     0.1 * * @see         ToDoList, ToDoAdd, ToDoView, ToDoEdit * */ /*  * Database : development, Table : todo *  * field name                        data type * ---  ---  * id                                integer * description                      character varying(255) * priority                         character varying(63) * status                           character varying(63) * datedue                          timestamp without time zone * sourceinsert                     character varying(63) * dateinsert                       timestamp without time zone * sourceupdate                     character varying(63) * dateupdate                       timestamp without time zone */ /* * Initialize some variables */ String message = ""; long dt = 0; String title = null; Connection conn = null; DatabaseMetaData dbmd = null; Statement st = null; ResultSet rs = null; ResultSetMetaData rsmd = null; String sql = ""; String posted = "false"; boolean populated = true; boolean recordExists = true; boolean duplicate = false; int records = 0; int errors = 0; //String tableName = null; Integer columns = 0; int column = 0; String fields = null; String s = null; // miscellaneous utility variable /* * Get a date time stamp. Set a page title, if needed... */ dt = System.currentTimeMillis; title = "ToDo - Remove Item"; /* * Get the database connection values, etc... from the properties file * ( This eventually will be externalized to reduce code clutter... ) */ String p = application.getRealPath("/") + "properties/Demo.properties"; InputStream propsFile; Properties appProp = new Properties; try { propsFile = new FileInputStream(p); appProp.load(propsFile); propsFile.close; } catch (IOException ioe) { out.println("&lt;PRE>"); out.println("I/O Exception."); ioe.printStackTrace; out.println("&lt;/PRE>"); } String dbDriver = "" + appProp.getProperty("dbDriver"); String dbUrl   = "" + appProp.getProperty("dbUrl"); String dbUid   = "" + appProp.getProperty("dbUid"); String dbUpw   = "" + appProp.getProperty("dbUpw"); String css     = "" + appProp.getProperty("css"); /* * Open the database */ try { Class.forName(dbDriver); conn = DriverManager.getConnection(dbUrl, dbUid, dbUpw); st = conn.createStatement; /* 	 * Get the request values */ 	if ( request.getParameter( "posted" ) == null ) { posted = "false"; } 	else { posted = request.getParameter( "posted" ); } 	if ( posted.equals("true") ) { /* 		 * 1. Make sure the record exists and, ideally, lock it, during the removal * 2. Remove the record * 3. Return to list */ 		/* 		 * Does record "still" exist? */ 		recordExists = true; if ( populated ) { sql = "SELECT COUNT(*) AS records " + "FROM " + "todo" + " " + // It may make sense to use a variable for table_name at some point... "WHERE id = " + request.getParameter( "todo_id" ) ; //			out.print("sql = " + sql + " \n"); rs = st.executeQuery(sql); if (rs.next) { records = Integer.parseInt( rs.getString("records") ); if ( records &lt; 1 ) { recordExists = false; message = "Record does not exist. You may have removed by some other means or another page."; errors++; } 			} 		} 		/* 		 * If no error, delete the record and then return to list */ 		if ( errors == 0 ) { sql = "DELETE FROM todo " + "WHERE id = " + request.getParameter( "todo_id" ) + " "; //			out.println( "sql = " + sql); st.execute( sql ); %> &lt;BODY onload="document.form1.submit"> &lt;div> &lt;form name="form1" method="POST" action="ToDoList.jsp?&lt;%=System.currentTimeMillis%>"> &lt;input type="image" src="images/dots/clear.gif" alt="submit" value="Continue"> &lt;/form> &lt;/div> &lt;% } 	} // End - if ( posted ... ) /* 	 * If we got this far, then either we arrived from another page or there was some error... */ 	fields = "id, description, priority, status, datedue"; // will implement this later... sql = "SELECT " + fields + " FROM " + "todo" + " " + "WHERE id = " + request.getParameter( "todo_id" ) + " "; //	out.print("\n\nsql = " + sql + "\n\n"); rs = st.executeQuery(sql); rsmd = rs.getMetaData; columns = rsmd.getColumnCount; rs = st.executeQuery(sql); if (rs.next) { %> &lt;!DOCTYPE html> &lt;HTML> &lt;HEAD> &lt;link rel="stylesheet" type="text/css" href="&lt;%=css%>"> &lt;TITLE>&lt;%=title%>&lt;/TITLE> &lt;SCRIPT LANGUAGE="JavaScript" SRC="angular.js">&lt;/SCRIPT> &lt;SCRIPT LANGUAGE="JavaScript" SRC="jquery.js">&lt;/SCRIPT> &lt;/HEAD> &lt;BODY> &lt;H1>&lt;%=title%>&lt;/H1> &lt;br>&lt;br>&lt;br>&lt;br> &lt;div class="centered"> &lt;nobr> &lt;form action="ToDoList.jsp" name=f> &lt;input name=btnG type=submit value=" Return to ToDo List "> &lt;/form> &lt;/nobr> &lt;/div> &lt;br> &lt;p class="centered">&lt;%=message%>&lt;/p> &lt;div class="centered"> &lt;FORM NAME="form1" METHOD="POST"> &lt;!--Get time and pass as hidden variable in query_string to force browser to get page from server instead of cache... --> &lt;input type="hidden" name="dt&lt;%= dt %>" value="&lt;%=System.currentTimeMillis%>"> &lt;input type="hidden" name="posted" value="true"> &lt;input type="hidden" name="todo_id" value="&lt;%=request.getParameter( "todo_id" )%>"> &lt;table class="ivory" border="0" cellspacing="0"> &lt;TBODY> &lt;tr>&lt;th>Field&lt;/th>&lt;th>Value&lt;/th>&lt;/tr> &lt;% for( column=1; column&lt;=columns ; column++ ) { out.println ( "&lt;tr align=\"left\">" ); out.println ( "&lt;td>&lt;b>" + rsmd.getColumnName( column ) + ":&lt;/B>&lt;/td>" ); out.println ( "&lt;td>" + rs.getString( rsmd.getColumnName( column ) ) + "&lt;/td>" ); out.println ( "&lt;/tr>" ); } %> &lt;tr align="left"> &lt;td> &lt;/td>&lt;td> &lt;div > &lt;input type="submit" name="submit" value=" Confirm "> &lt;/div> &lt;/td> &lt;/tr> &lt;/table> &lt;br>&lt;br> &lt;/form> &lt;/div> &lt;% } // end if for result set handling } // end try catch ( SQLException ex ) { out.println ( "&lt;pre>" ); out.println ( "---" ); out.println ( "--                      FATAL ERROR IN SQL" ); out.println ( "---" ); out.println ( "-- " ); while ( ex != null ) { out.println ("-- SQLState: " + ex.getSQLState ); out.println ("-- Message: " + ex.getMessage ); out.println ("-- Vendor:  " + ex.getErrorCode ); ex = ex.getNextException ; out.println ( "-- " ); } 	out.println ( "---" ); } // end catch catch ( java.lang.Exception ex ) { /* 	 * Got some other type of exception. Dump it. */ 	out.println ( "&lt;pre>" ); out.println ( "---" ); ex.printStackTrace ; out.println("exception: " + ex.getMessage ); } // end catch finally { // No action for now } // end finally %> &lt;/body> &lt;/html>

That's it for this application. Like I noted, it's primarily an example of dealing with a list on a database table using JSP. I may or may not develop it further. The main page could be enhanced to provide more information about the disposition of an item and maybe a search button to pull out specific records or groups of records. Anyway, HTH