You probably want to do something like this (just done it myself):

Enumeration params = req.getParameterNames();
StringBuffer pref = new StringBuffer();
while(params.hasMoreElements()) { // scroll through params and append coded
letter to buffer when param is "ON"
        String name  = (String)params.nextElement();
        String value = req.getParameter(name);
        if(value.equals("ON")) {pref.append((char)(65+Integer.parseInt(name)));}
}

Hope this helps,
Mike W.

-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Tom
Kochanowicz
Sent: 10 May 2002 16:25
To: [EMAIL PROTECTED]
Subject: Re: Using the getParameterValues


Yes,

        I think this is what I am looking for. Many thanks to those who
responded.

Tom Kochanowicz


-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of
Graham, Billy
Sent: Friday, May 10, 2002 3:44 AM
To: [EMAIL PROTECTED]
Subject: Re: Using the getParameterValues


Hi,

I'm no expert Java programmer but I do something similar to allow users to
plot laboratory Quality Control results graphically. I have included a few
snippets of my code below.
The user fires off the first servlet that queries my (MS Access) database
and returns all valid parameters to the user as (multiple-selectable)
Combo-boxes in an HTML Form.
The user selects any combination from these Combo boxes, hits "submit" and
the parameters are submitted to a second servlet that builds the SQL code
(using the code below). The user can make any combination of selections from
the (4) combo boxes and the same code will always handle it (for clarity I
have cut out all non-relevant code).

Hope this helps.

Regards,   Billy.



//Define required variables to store multiple choices...

String[] userDepartments;
String[] userAnalysers;
String[] userControls;
String[] userTests;
=========================

//Load multiple choices (from HTML Form) into arrays...

userDepartments = req.getParameterValues("D");
userAnalysers = req.getParameterValues("A");
userControls = req.getParameterValues("C");
userTests = req.getParameterValues("T");

D, A, C and T contain the values returned from the HTML multiple-choice
combo-boxes
================================

//Build up the SQL string from (any number of) returned parameters...

userDepartmentsNo = userDepartments.length;
userAnalysersNo = userAnalysers.length;
userControlsNo = userControls.length;
userTestsNo = userTests.length;

String DeptsSQL = "";
String AnalsSQL = "";
String ControlsSQL = "";
String TestsSQL = "";


for(int a=0; a<userDepartmentsNo; a++){
if(a==(userDepartmentsNo-1)){DeptsSQL = DeptsSQL + "'" + userDepartments[a]
+ "'";}
  else{DeptsSQL = DeptsSQL + "'" + userDepartments[a] + "',";}
}
DeptsSQL = " AND ([Results].[Dept] in (" + DeptsSQL + "))";


for(int a=0; a<userAnalysersNo; a++){
if(a==(userAnalysersNo-1)){AnalsSQL = AnalsSQL + "'" + userAnalysers[a] +
"'";}
  else{AnalsSQL = AnalsSQL + "'" + userAnalysers[a] + "',";}
}
AnalsSQL = " AND ([Results].[Anal] in (" + AnalsSQL + "))";


for(int a=0; a<userControlsNo; a++){
if(a==(userControlsNo-1)){ControlsSQL = ControlsSQL + "'" + userControls[a]
+ "'";}
  else{ControlsSQL = ControlsSQL + "'" + userControls[a] + "',";}
}
ControlsSQL = " AND ([Results].[Material] in (" + ControlsSQL + "))";


for(int a=0; a<userTestsNo; a++){
if(a==(userTestsNo-1)){TestsSQL = TestsSQL + "'" + userTests[a] + "'";}
  else{TestsSQL = TestsSQL + "'" + userTests[a] + "',";}
}
TestsSQL = " AND ([Results].[Test] in (" + TestsSQL + "))";


=============================

//Append the SQL part-statements into final SQL statement...

mysqlStatement = "SELECT [Dept], [Anal], [Material], [Date], [Time], " +
                 "[Test], [Result], format(Results.[Date],'dd'), " +
                 "[Id], [CtrlBatchNo], [ReagentBatchNo], [TargetValue],
[SD], [Units], " +
                 "format(Results.[Date],'dd/mm/yy'), format(Results.[Time],
'hh:mm'), " +
                 "format(Results.[Date],'mm'), format(Results.[Date],'yy'),
[Decimals], [MaterialDescription] FROM [Results] " +
                 "WHERE ([Results].[Date] between #" + tDateFrom + "# and #"
+ tDateTo + "#) AND ([Results].[Exclude] = false) " +
                  DeptsSQL + AnalsSQL + ControlsSQL + TestsSQL;

//Then execute your SQL, get your result set returned and process as
required.


================END======================




-----Original Message-----
From: Tom Kochanowicz [mailto:[EMAIL PROTECTED]]
Sent: 10 May 2002 08:03
To: [EMAIL PROTECTED]
Subject: Re: Using the getParameterValues


Yes,

        What I am doing is setting up a web enabled data warehouse to study
pancreatic cancer patients. The mission is to find characteristics that are
common in these patients and to see if their is a pattern (e.g. sex, race,
demographics, etc.) that shows a higher probability of getting pancreatic
.....

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to