Thanks so much for your informative response! I would value your advice and direction
to correct the structure of the code, but I am a very methodical person and first must
complete the prototype in JSP before I go on to the next step of applying the MVC
structure to correct the inefficiencies. (Also, it will be invaluable to the learning
process be able to compare the two.) Just as in learning Math, you must learn the long
way of problem solving before you apply the sophisticated, less error prone, and more
structured approach.
I have a sort that works pefectly, and displays only the records that have "checks" in
the checkboxes. By unchecking the checkbox for individual records, (and then pressing
the Sort/Select button), the sort is re-run using only the ID's of records that have
been "checked."
When ADD TO CART is pressed, I want to pass the ID's from the displayed records to a
persistent session variable. And then when "DISPLAY CART" is pressed, I want to
view a sort page EXACTLY like the original sort page, except the variable holding the
diplayed records IS the persistent session variable. I'm not sure how to add only
unique ID's to the session variable?
I'd appreciate any assistance to complete this step, so I can go on and develop the
MVC structure.
Thank you again.
---------------------------------------------------------------------
<%@page language="java" import="java.sql.*"%>
<%@ include file="../Connections/connBeachwear.jsp" %>
<%@page language="java" import="java.sql.*,java.util.*"%><%//ADDED 12/14 %>
<%
//INCLUDE CHECKED ITEMS IN SORT:
String rsBeachwear__varCheckbox = "1";
if (request.getParameter ("valueCheckbox") !=null) {rsBeachwear__varCheckbox =
(String)request.getParameter ("valueCheckbox") ;}
%>
<%
String rsBeachwear__name = "ID";//default sort value
if (request.getParameter ("order") !=null) {rsBeachwear__name =
(String)request.getParameter ("order");}
String rsBeachwear__sort = "ASC";//default sort value
if (request.getParameter ("sort") !=null) {rsBeachwear__sort =
(String)request.getParameter ("sort");}
String rsBeachwear__orderby ="ID";//default value
if (request.getParameter ("order") !=null) {rsBeachwear__orderby =
(String)request.getParameter("order");}
String rsBeachwear__sortby ="ASC";//default value
if (request.getParameter ("sort") !=null) {rsBeachwear__sortby =
(String)request.getParameter("sort");}
%>
<%
Driver DriverrsBeachwear =
(Driver)Class.forName(MM_connBeachwear_DRIVER).newInstance();
Connection ConnrsBeachwear =
DriverManager.getConnection(MM_connBeachwear_STRING,MM_connBeachwear_USERNAME,MM_connBeachwear_PASSWORD);
String chkValues[]=request.getParameterValues("valueCheckbox");
session.setAttribute("chkValues2",chkValues); //IS THIS THE CORRECT WAY TO ADD ID'S
TO A SESSION VARIABLE?
StringBuffer prepStr=new StringBuffer("SELECT ID, Item, Color, Size FROM Beachwear
WHERE ID=");
for(int x = 0; x < chkValues.length; ++x) {
prepStr.append(chkValues[x]);
if((x+1)<chkValues.length){
prepStr.append(" OR ID=");
}//end if
}//end for loop
prepStr.append(" ORDER BY " + rsBeachwear__name + " " + rsBeachwear__sort ); //NEW
SQL SORT CODE:
PreparedStatement
StatementrsBeachwear=ConnrsBeachwear.prepareStatement(prepStr.toString());
ResultSet rsBeachwear = StatementrsBeachwear.executeQuery();
Object rsBeachwear_data;
%>
<title>Beachwear Title</title>
<body bgcolor="#FFFFFF">
<p align="center"><b><font size="4">DETAIL PAGE</font></b></p>
<form name="form1" method="get" action="Detail2.jsp">
<table width="75%" border="1">
<tr>
<td width="20%">
<div align="center">Sort Parameter </div>
</td>
<td width="19%">
<div align="center">Sort 1</div>
</td>
<td width="25%">
<div align="center">Sort 2</div>
</td>
<td width="36%">
<div align="center">Add Records to Cart:</div>
</td>
<td width="36%">
<div align="center">
<div align="center">View Cart</div>
</div>
</td>
</tr>
<tr>
<td width="20%">
<div align="center">
<input type="submit" value="Sort /Select" name="submit">
</div>
</td>
<td width="19%">
<div align="center">
<select name="order" size="1">
<option value="ID" <% if (rsBeachwear__orderby.equals("ID"))
{out.print("selected"); } %> >ID</option>
<option value="Item" <% if (rsBeachwear__orderby.equals("Item"))
{out.print("selected"); } %> >Item</option>
<option value="Color" <% if (rsBeachwear__orderby.equals("Color"))
{out.print("selected"); } %> >Color</option>
<option value="Size" <% if (rsBeachwear__orderby.equals("Size"))
{out.print("selected"); } %> >Size</option>
</select>
</div>
</td>
<td width="25%">
<div align="center">
<select name="sort" size="1">
<option value="ASC" <% if (rsBeachwear__sortby.equals("ASC"))
{out.print("selected"); } %>>Ascending</option>
<option value="DESC" <% if (rsBeachwear__sortby.equals("DESC"))
{out.print("selected"); } %>>Descending</option>
</select>
</div>
</td>
<td width="36%">
<div align="center">
<input type="submit" name="Submit" value="Add to Cart">
</div>
</td>
<td width="36%">
<div align="center">
<div align="center">
<input type="button" name="butViewCart" value="View Cart"
onClick="window.location='../jserv/Cart2.jsp'">
</div>
</div>
</td>
</tr>
</table>
<p> </p>
<%while(rsBeachwear.next()){%>
<table width="75%" border="1">
<tr>
<td width="17%">ID:</td>
<td width="58%"><%=(((rsBeachwear_data = rsBeachwear.getObject("ID"))==null ||
rsBeachwear.wasNull())?"":rsBeachwear_data)%></td>
<td width="25%">
<div align="center">Include in Sort:
<input type="checkbox" name="valueCheckbox" value="<%=(((rsBeachwear_data =
rsBeachwear.getObject("ID"))==null || rsBeachwear.wasNull())?"":rsBeachwear_data)%>"
checked>
</div>
</td>
</tr>
<tr>
<td width="17%">ITEM:</td>
<td colspan="3"><%=(((rsBeachwear_data = rsBeachwear.getObject("Item"))==null ||
rsBeachwear.wasNull())?"":rsBeachwear_data)%></td>
</tr>
<tr>
<td width="17%">COLOR:</td>
<td colspan="3"><%=(((rsBeachwear_data = rsBeachwear.getObject("Color"))==null
|| rsBeachwear.wasNull())?"":rsBeachwear_data)%></td>
</tr>
<tr>
<td width="17%">SIZE:</td>
<td colspan="3"><%=(((rsBeachwear_data = rsBeachwear.getObject("Size"))==null ||
rsBeachwear.wasNull())?"":rsBeachwear_data)%></td>
</tr>
<tr>
<td width="17%" bgcolor="#00FFFF" bordercolor="#FFFFFF">
<div align="left"></div>
</td>
<td colspan="3" bgcolor="#00FFFF" bordercolor="#FFFFFF"> </td>
</tr>
</table>
<%
}
%>
<p> </p>
</form>
<%
rsBeachwear.close();
ConnrsBeachwear.close();
%>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com