Hi Milt (& Pierre-Yves & others),
[This is the 4th time I've sent this e-mail - it keeps getting returned for
being too large > 300 lines, so I've been compressing the code shown at
bottom (but now less readable)]
Just to ensure that I had indeed checked the Global variable aspect
previously, as I was fairly sure I had done, I moved the 3 variables
entirely to the local method (doGet) and removed the 'Synchronized' keyword
from my code. Unfortunately the original problem returned. I have since left
the 3 variables in the local method anyway, as you suggested, and reinstated
the 'Synchronized' zone - everything works! I still don't know what is going
on. However, stepping back from the problem once again - I have one servlet
being requested one time (in theory anyway), therefore even if my variables
were not local they should not be getting changed by another thread as there
is no other thread (again sticking to my test situation - I realise in a
live environment there would be). This is why I suspect, as detailed in my
first e-mail, that something is going on with the server (and Pierre-Yves
seems to be thinking this way too) and/or my other
user-requirement-gathering servlet that is calling this main servlet.
My smaller servlet (see below) simply draws and populates an HTML form,
gathers user parameters for the main servlet queries and then sends these
parameters to the main servlet via a GET call. As listed in my first e-mail
there appears to be 2 GETs being echoed back in the Server console when this
first servlet is calling the second servlet, but I cannot understand why.
Again any suggestions would be most welcome. (By the way the HTML form is
very basic for testing purposes only, so please excuse my lack of visual
design here - it will look absolutely beautiful in the final product - if I
can get the bleeding thing to work!!! - where's that chainsaw (brrmmm!!!)).
Kind regards, Billy.
Please excuse any delay in me replying to e-mails today as I am attending a
few meetings, but I will respond sometime today (GMT).
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import java.util.*;
public class RequestScreen extends HttpServlet
{
public void ProcessHeader(java.io.PrintWriter out){
out.println("<html><head><title>Contents of the QSee Database</title>");
//Function to get Client document width and height
out.println("<SCRIPT language=\"javascript\">");
out.println("function getDims(Dim) {");
out.println("var height, width;");
out.println("if (document.all) height = document.body.offsetHeight, width
= document.body.offsetWidth;");
out.println("else if (document.layers) height = window.innerHeight, width
= window.innerWidth;");
out.println("if (Dim=='H') return height; else return width;");
out.println("}");
out.println("</SCRIPT></head><body>");
out.println("<center><h3>Please make your selection from the lists
supplied</h3></center>");
out.println("<FORM ACTION=\"http://localhost/servlet/QSee4\"
METHOD=\"GET\">");
// Get Client screen Width and Height
out.println("<SCRIPT>document.write('<INPUT TYPE=\"hidden\" NAME=\"sw\"
VALUE=\"' + getDims(\"W\") + '\">');</SCRIPT>");
out.println("<SCRIPT>document.write('<INPUT TYPE=\"hidden\" NAME=\"sh\"
VALUE=\"' + getDims(\"H\") + '\">');</SCRIPT>"); }
public void ProcessFooter(java.io.PrintWriter out){
//get the required order
out.println("<center><table WIDTH=\"40%\">");
out.println("<tr ALIGN=\"LEFT\"><td WIDTH=\"40%\">Department</td><td>");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o1\" VALUE=\"1\" CHECKED>");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o1\" VALUE=\"2\">");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o1\" VALUE=\"3\">");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o1\"
VALUE=\"4\"></td></tr></table></center><BR>");
out.println("<center><table WIDTH=\"40%\"><tr ALIGN=\"LEFT\"><td
WIDTH=\"40%\">Analyser</td><td>");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o2\" VALUE=\"1\">");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o2\" VALUE=\"2\" CHECKED>");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o2\" VALUE=\"3\">");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o2\"
VALUE=\"4\"></td></tr></table></center><BR>");
out.println("<center><table WIDTH=\"40%\"><tr ALIGN=\"LEFT\"><td
WIDTH=\"40%\">Control</td><td>");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o3\" VALUE=\"1\">");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o3\" VALUE=\"2\">");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o3\" VALUE=\"3\" CHECKED>");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o3\"
VALUE=\"4\"></td></tr></table></center><BR>");
out.println("<center><table WIDTH=\"40%\"><tr ALIGN=\"LEFT\"><td
WIDTH=\"40%\">Test</td><td>");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o4\" VALUE=\"1\">");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o4\" VALUE=\"2\">");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o4\" VALUE=\"3\">");
out.println("<INPUT TYPE=\"RADIO\" NAME=\"o4\" VALUE=\"4\"
CHECKED></td></tr></table></center><BR>");
//get the required dates
out.println("<center><table border>");
out.println("<tr><td>");
out.println("From: <INPUT TYPE=\"TEXT\" NAME=\"from\" SIZE=\"12\"
MAXLENGTH=\"12\">");
out.println("</tr><td>");
out.println("To: <INPUT TYPE=\"TEXT\" NAME=\"to\" SIZE=\"12\"
MAXLENGTH=\"12\">");
out.println("</td></tr><td>");
out.println("Values: <INPUT TYPE=\"TEXT\" NAME=\"values\" VALUE=\"31\"
SIZE=\"12\" MAXLENGTH=\"12\">");
out.println("</td></tr></table></center>");
out.println("<INPUT TYPE=\"submit\" VALUE=\"Submit\">");
out.println("</FORM></body></html>");
out.flush(); }
public void ProcessResults(java.io.PrintWriter out, ResultSet myResultSet,
String myTableType){
//format and present results
try
{ /* If there is data in the ResultSet, get the ResultSet's metadata,
e.g. number of columns, column labels, etc. */
if(myResultSet.next()){
ResultSetMetaData rsmd = myResultSet.getMetaData();
int colCount = rsmd.getColumnCount();
//set up an HTML table
out.println("<center><table border><tr><td>");
//obtain and print the database fields column labels
out.println("<th>" + rsmd.getColumnLabel(1) +"</th></td>");
String myListValue;
String myListName;
boolean OneSelected = false;
//obtain and print out each record of the database
out.println("<td><SELECT MULTIPLE SIZE=\"5\" NAME=\"" + myTableType +
"\">");
do{if (myTableType=="Tests"){
myListValue = myResultSet.getString(1);
myListName = myResultSet.getString(2) + " (" + myListValue + ")";}
else{
myListValue = myResultSet.getString(1);
myListName = myListValue;}
if (OneSelected){out.println("<OPTION VALUE=\"" + myListValue + "\">"
+ myListName);}
else {out.println("<OPTION SELECTED VALUE=\"" + myListValue + "\">" +
myListName);
OneSelected = true;}
}while(myResultSet.next());
out.println("</SELECT></td></tr>");
//close the HTML table
out.println("</table></center>");
}
else{//if there are no records in the database
out.println("No records could be found"); }
}
catch(Exception e)
{out.println(e);}
}
public void doGet (HttpServletRequest req, HttpServletResponse resp)
throws ServletException, java.io.IOException
{//set content type of the response and set no caching
resp.setContentType("text/html");
resp.setHeader("Cache-Control", "no-cache");
resp.setHeader("Pragma", "no-cache");
//create PrintWriter to write the HTML results page
java.io.PrintWriter out = new java.io.PrintWriter(resp.getOutputStream());
//create the SQL querys
String DepartmentsQ = "SELECT [Department] from [Departments] GROUP by
[Department]";
String AnalysersQ = "SELECT [AnalyserName] from [Analysers]";
String ControlsQ = "SELECT [CtrlName] from [Controls] GROUP BY [CtrlName]";
String TestsQ = "SELECT [Analyte], [Description] from [AnalyteDetails] GROUP
BY [Analyte], [Description]";
//specify that the JDBC-ODBC bridge is being used
String driverName ="com.ms.jdbc.odbc.JdbcOdbcDriver";
//identify the QSee database as the connectionURL
String connectionURL ="jdbc:odbc:QSee";
//initialise connection, statement and result set variables
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
//connect to the database, pose the query and obtain the results
try
{ Class.forName(driverName).newInstance();
con = DriverManager.getConnection(connectionURL);
stmt = con.createStatement();
ProcessHeader(out);
rs = stmt.executeQuery(DepartmentsQ);
ProcessResults(out, rs, "Departments");
rs = stmt.executeQuery(AnalysersQ);
ProcessResults(out, rs, "Analysers");
rs = stmt.executeQuery(ControlsQ);
ProcessResults(out, rs, "Controls");
rs = stmt.executeQuery(TestsQ);
ProcessResults(out, rs, "Tests");}
catch (Exception e){out.println(e);}
ProcessFooter(out);
try{if (con != null){con.close();}}
catch(Exception e) {out.println(e);}}
}//end
*****************************************************************
This email has been Virus Scanned.
Privileged/Confidential Information and/or Copyright Material may
be contained in this e-mail. The information and Material is
intended for the use of the intended addressee. If you are not
the intended addressee, or the person responsible for delivering
it to the intended addressee, you may not copy or deliver it to
anyone else or use it in any unauthorised manner. To do so is
prohibited and may be unlawful. If you receive this e-mail by
mistake, advise the sender immediately by using the reply
facility in your e-mail software.
Thank you.
Information Technology Department
Belfast City Hospital Trust
*****************************************************************