Hi, I'm trying my first program using servlets and JSP and would appreciate any help or advice about a problem I'm having.
In my servlet I'm connecting to the database and displaying all the records in there. I'm then trying to add data to a JavaBean so that I can click a button and get the attributes from the JavaBean in the JSP. This is the servlet code (just the relevant bits - the query to get data executes fine):
out.println("<form action=\"viewAllViewJSP_kv003302.jsp\" method=\"post\">");
out.print("<table>");
out.print("<tr>");
Vector<customerBean_kv003302> custs = new Vector<customerBean_kv003302>();
while (rs.next())
{
out.println("<tr" + (ctr++ % 2 == 0 ? " class=\"shaded\"" : "") + ">");
out.println("<td>" + rs.getInt(1) + "</td>");
out.println("<td>" + rs.getString(2) + " " + rs.getString(4) + " " + rs.getString(3) + "</td>");
out.println("<td>" + rs.getString(5) + ", " + rs.getString(6) + "</td>");
out.println("<td><input type=\"submit\" name=\"viewDetails\" value=\"View Details\">");
out.println("</tr>");
customerBean_kv003302 cust = new customerBean_kv003302();
cust.setName(rs.getString(3));
custs.add(cust);
}
request.setAttribute("CustomerCollection", custs);
out.println("</table>");
out.println("</form");
In my .jsp file, this is the code I was using (I know how to display it I just need help getting the attributes in the first place)
<% java.util.Vector collection =
(java.util.Vector)request.getAttribute("CustomerCollection");
if (collection != null)
{
// Iterate through data & put it in a table
// Then display all in HTML
%>
<%
}
else
{
throw new javax.servlet.jsp.JspException(
"Collection View could not be found");
}
%>
Any help would be greatly appreciated as I am very stuck!