I am still new to servlets and JDBC stuff and would like some help on the following code:
try{
String selectSQL = "select * from product_list where category = '"+category+"'";
Statement stmt = conn.createStatement();
ResultSet rs1 = stmt.executeQuery(selectSQL);
ArrayList<Float> idList = new ArrayList<Float>();
out.println("<table border=\"1\"><tr><th>Item_ID</th><th>Item_name</th><th>Title</th><th>Category</th><th>Image_name</th><th>Price</th><th>Stock_Count</th></tr>");
while(rs1.next()){
out.println("<tr><td>"+ rs1.getFloat("item_id") + "</td>");
out.println("<td>" + rs1.getString("item_name") + "</td>");
out.println("<td>"+"<a href =\"ItemDetail\">" + rs1.getString("title")+"</a>" + "</td>");
out.println("<td>" + rs1.getString("category") + "</td>");
out.println("<td>" + rs1.getString("image_name") + "</td>");
out.println("<td> " + rs1.getFloat("price") + "</td>");
out.println("<td> " + rs1.getFloat("stock_count") + "</td>");
out.println("</tr>");
HttpSession session = request.getSession(true);
idList.add(rs1.getFloat("recording_id"));
session.setAttribute("id", idList);
}
out.println("</table>");
conn.close();
} catch(SQLException se) {
System.err.println(se);
}
What I want to do is that it will store every single item_id in the session but only display the details of the one where its title's link is clicked by the user(every title has the same hyperlink) in another servlet, I have attempted to store all the ids in a array list but nothing is showing on the other servlet that is meant to have received the array list, is there something I done wrong there, any help would be appreciated.
Here is the code used in a different servlet to receive the attribute from the above table
HttpSession session = request.getSession(true);
ArrayList<Float> id = (ArrayList<Float>) session.getAttribute("id");