// BizVizWiz0.java // // CREATED: ABS 2012.11.08 copied from NewsletterTest.java; did page layout // MODIFIED: ABS 2012.11.09 chopped away spurious code, debugged, built out // MODIFIED: ABS 2012.11.14 added doc, safetyCheck(); added source code upload // MODIFIED: ABS 2012.11.15 built out & debugged // MODIFIED: ABS 2012.11.16 tested against server upgrade // MODIFIED: ABS 2012.11.17 added Green Bay data as default // MODIFIED: ABS 2012.11.18 added dummy key & annotations // To Do: // [/] measure HTML table sizes in browsers // [X] make debug follow links // [_] use prev values as defaults // [_] input into array // [_] adaptive input screen (width & height) // [/] input CSV // [/] select params // [X] create HTML: all rows // [X] re-add radio buttons // [_] see drawn spec // [X] default values in inputs // [X] bullet-proof // import java.io.*; import java.util.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import javax.mail.*; import javax.mail.event.*; import javax.mail.internet.*; import javax.activation.*; public class BizVizWiz0 extends HttpServlet { String trueString = "true"; String debug; ///////////////////////////////////////////////////////////////////////////////////// // // // doGet // // // ///////////////////////////////////////////////////////////////////////////////////// public void doGet ( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { String requestType = req.getParameter("requestType"); HttpSession session = req.getSession(true); res.setContentType("text/html"); PrintWriter out = res.getWriter(); debug = req.getParameter("debug"); if (debug != null) { session.setAttribute("debug", debug); } else { session.setAttribute("debug",""); } if (trueString.equals(session.getAttribute("debug"))) { session.setAttribute("debugString0","?debug=true"); session.setAttribute("debugString","&debug=true"); } else { session.setAttribute("debugString0",""); session.setAttribute("debugString",""); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %% // input_data %% // %% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if (requestType == null || requestType.equals("input_data")) { printHead(out, "BizVizWiz0 - input data"); printNavBar(out, 1, false, session); printStepsHighlighted(out, session, 1); if (trueString.equals(session.getAttribute("debug"))) { printDebug(out, "input_data page"); } safetyCheck(out, session); printInput_dataForm(out, session); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %% // set_params %% // %% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% else if (requestType.equals("set_params")) { printHead(out, "BizVizWiz0 - set params"); printNavBar(out, 1, false, session); printStepsHighlighted(out, session, 2); if (trueString.equals(session.getAttribute("debug"))) { printDebug(out, "set_params page"); } safetyCheck(out, session); printSet_paramsForm(out, session); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %% // view_results %% // %% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% else if (requestType.equals("view_results")) { printHead(out, "BizVizWiz0 - view results"); printNavBar(out, 2, true, session); printStepsHighlighted(out, session, 3); if (trueString.equals(session.getAttribute("debug"))) { printDebug(out, "view_results page"); } safetyCheck(out, session); { int i_row, i_col; String[][] my_third_array = new String[2][3]; my_third_array = (String[][])session.getAttribute( "myArray"); if (trueString.equals(session.getAttribute("debug"))) { printDebug(out, "my_third_array length: " + my_third_array.length); for (i_row = 0; i_row < 3; i_row++) { for (i_col = 0; i_col < 2; i_col++) { printDebug(out, "my_third_array[" + i_row + "][" + i_col + "]: " + my_third_array[i_row][i_col]); } } } } /************************************** HINKY h = session.getAttribute("h"); w = session.getAttribute("w"); h = "32"; w = "32"; **************************************/ out.println("
"); out.println("
0 | 1 | 2 | 3 | "); out.println("||||||
---|---|---|---|---|---|---|---|---|---|
a | "); // HINKY out.println("" + dec_to_hex((String)session.getAttribute("a0"), 0) + " | "); out.println("" + dec_to_hex((String)session.getAttribute("a1"), 0) + " | "); out.println("" + dec_to_hex((String)session.getAttribute("a2"), 0) + " | "); out.println("" + dec_to_hex((String)session.getAttribute("a3"), 0) + " | "); out.println("|||||
b | "); // HINKY out.println("" + dec_to_hex((String)session.getAttribute("b0"), 0) + " | "); out.println("" + dec_to_hex((String)session.getAttribute("b1"), 0) + " | "); out.println("" + dec_to_hex((String)session.getAttribute("b2"), 0) + " | "); out.println("" + dec_to_hex((String)session.getAttribute("b3"), 0) + " | "); out.println("|||||
c | "); // HINKY out.println("" + dec_to_hex((String)session.getAttribute("c0"), 0) + " | "); out.println("" + dec_to_hex((String)session.getAttribute("c1"), 0) + " | "); out.println("" + dec_to_hex((String)session.getAttribute("c2"), 0) + " | "); out.println("" + dec_to_hex((String)session.getAttribute("c3"), 0) + " | "); } else { out.println("a | "); // HINKY out.println("" + " " + " | "); out.println("" + " " + " | "); out.println("" + " " + " | "); out.println("" + " " + " | "); out.println("
b | "); // HINKY out.println("" + " " + " | "); out.println("" + " " + " | "); out.println("" + " " + " | "); out.println("" + " " + " | "); out.println("|||||
c | "); // HINKY out.println("" + " " + " | "); out.println("" + " " + " | "); out.println("" + " " + " | "); out.println("" + " " + " | "); } out.println("
"); out.println("
"); out.println("
");
out.println(" 56 " + session.getAttribute("units_string") + ""); out.println(" | ");
out.println(" "); out.println(" "); out.println(" | "); out.println("");
out.println(" 80 " + session.getAttribute("units_string") + ""); out.println(" | ");
out.println(" "); out.println(" "); out.println(" | "); out.println("");
out.println(" 104 " + session.getAttribute("units_string") + ""); out.println(" | ");
out.println("
"); out.println(" | "); out.println(""); out.println(" | "); out.println(""); out.println(" | "); out.println(""); out.println(" | "); out.println(""); out.println(" | "); out.println("
"); out.println("
"); out.println(session.getAttribute("notes_string")); out.println("
"); out.println("Here is the data used:"); // HINKEY printDataTable(out, session); } } // end of doGet() ///////////////////////////////////////////////////////////////////////////////////// // // // doPost // // // ///////////////////////////////////////////////////////////////////////////////////// public void doPost ( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { HttpSession session = req.getSession(true); res.setContentType("text/html"); PrintWriter out = res.getWriter(); String postType = req.getParameter("postType"); debug = req.getParameter("debug"); if (debug != null) { session.setAttribute("debug", debug); } else { session.setAttribute("debug",""); } if (trueString.equals(session.getAttribute("debug"))) { session.setAttribute("debugString0","?debug=true"); session.setAttribute("debugString","&debug=true"); } else { session.setAttribute("debugString0",""); session.setAttribute("debugString",""); } printHead(out, "BizVizWiz0 - POST"); //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| // || // null || // || //||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| if (postType == null) { // input_data post printNavBar(out, 1, false, session); if (trueString.equals(session.getAttribute("debug"))) { printDebug(out, "input_data post page"); } printStepsHighlighted(out, session, 2); session.setAttribute("a0",req.getParameter("a0")); session.setAttribute("a1",req.getParameter("a1")); session.setAttribute("a2",req.getParameter("a2")); session.setAttribute("a3",req.getParameter("a3")); session.setAttribute("b0",req.getParameter("b0")); session.setAttribute("b1",req.getParameter("b1")); session.setAttribute("b2",req.getParameter("b2")); session.setAttribute("b3",req.getParameter("b3")); session.setAttribute("c0",req.getParameter("c0")); session.setAttribute("c1",req.getParameter("c1")); session.setAttribute("c2",req.getParameter("c2")); session.setAttribute("c3",req.getParameter("c3")); { //in servlet from: // http://www.sitepoint.com/forums/showthread.php?417581-Put-arrays-in-session-variables // http://www.leepoint.net/notes-java/data/arrays/arrays-2D.html // // 2-dimensional arrays are usually represented with a row-column // "spreadsheet" style. Assume we have an array, a, with two rows // and four columns. // // int[][] a = new int[2][4]; // Two rows and four columns. int i_row, i_col; String my_array[][] = { {"00", "01"}, {"10", "11"}, {"20", "21"} }; String[][] my_other_array = new String[2][3]; session.setAttribute( "myArray", my_array ); my_other_array = (String[][])session.getAttribute( "myArray"); if (trueString.equals(session.getAttribute("debug"))) { printDebug(out, "my_array length: " + my_array.length); printDebug(out, "my_other_array length: " + my_other_array.length); for (i_row = 0; i_row < 3; i_row++) { for (i_col = 0; i_col < 2; i_col++) { printDebug(out, "my_other_array[" + i_row + "][" + i_col + "]: " + my_other_array[i_row][i_col]); } } } } out.println("
BizVizWiz0 | "); out.println("
");
out.println("
| ");
out.println("");
out.println("
| ");
out.println("");
out.println("
| ");
out.println("
"); out.println("Enter 12 numbers from 0 to 255 below."); out.println("
"); out.println("
"); out.println(""); out.println("Here is the last data entered:"); out.println("
"); printDataTable(out, session); } ///////////////////////////////////////////////////////////////////////////////////// // // // printSet_paramsForm // // // ///////////////////////////////////////////////////////////////////////////////////// public void printSet_paramsForm(PrintWriter out, HttpSession session) { out.println("
"); out.println("
"); out.println("0 | 1 | 2 | 3 | "); out.println("|
---|---|---|---|---|
a | " + session.getAttribute("a0") + " | "); out.println("" + session.getAttribute("a1") + " | "); out.println("" + session.getAttribute("a2") + " | "); out.println("" + session.getAttribute("a3") + " | "); out.println("
b | " + session.getAttribute("b0") + " | "); out.println("" + session.getAttribute("b1") + " | "); out.println("" + session.getAttribute("b2") + " | "); out.println("" + session.getAttribute("b3") + " | "); out.println("
c | " + session.getAttribute("c0") + " | "); out.println("" + session.getAttribute("c1") + " | "); out.println("" + session.getAttribute("c2") + " | "); out.println("" + session.getAttribute("c3") + " | "); out.println("
");
if (highlight == 1 || highlight == 99) {
out.println("");
}
else {
out.println("");
}
out.println("Step 1:"); out.println(""); out.println("Go the input data screen (link above) and enter twelve"); out.println("numbers from 0 to 255, then press the \"input data\" button."); out.println(" "); out.println(" | ");
// Step 2
out.println("");
if (highlight == 2 || highlight == 99) {
out.println("");
}
else {
out.println("");
}
out.println("Step 2:"); out.println(""); out.println("Go the set params screen (link above) and enter parameters"); out.println("then press the\"submit parameters\" button."); out.println(" "); out.println(" | ");
// Step 3
out.println("");
if (highlight == 3 || highlight == 99) {
out.println("");
}
else {
out.println("");
}
out.println("Step 3:"); out.println(""); out.println("Go the view results screen (link above) and see a 2D"); out.println("color plot in an HTML table."); out.println(" "); out.println(" | ");
out.println("