Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Help please (urgent)JSP shopping cart

843836May 19 2004 — edited May 19 2004
Hey everybody!
I really need yer help as i'm at a dead end and havent a clue what i'm doing
i need to add products to my shopping cart and i have this code so far but it does nothing.
I"m using jsp (not classes)
i'd really appreciate the help.thanx :-)
this is my addtocart screen

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import = "java.sql.*"%>
<%@page import = "java.io.*"%>
<%@page import = "java.util.Properties"%>
<%@page import = "java.io.InputStream"%>
<%@page session = "true"%>
<%@page import = "java.util.*"%>


<html>
<head><title>Add to Cart</title></head>

<BODY BGCOLOR="#228B22">
<form action="thankyou.jsp" method = "POST">






<% String notEntered = "";
String connectionURL ="jdbc:mysql://localhost:3306/petshopwebsite";
String driver= "com.mysql.jdbc.Driver";
Connection c = null;
ResultSet rs = null;
Statement st = null;
String password = "";
String username ="root";
Vector userCart;

try{
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection(connectionURL,username, password);
st = c.createStatement();

String productId = request.getParameter("productId");
String price = request.getParameter("Price");
Properties product = new Properties();

if (session.getAttribute("userCart") == null) { //no products added yet
userCart = new Vector();
}
else{
userCart = (Vector) session.getAttribute("userCart");
}


productId = rs.getString(1);
product.setProperty("productId", productId);

price = rs.getString(2);
product.setProperty("Price", price);

userCart.add(product);
session.setAttribute("userCart", userCart);



userCart = (Vector) session.getAttribute("userCart");
Iterator iter = userCart.iterator();

while (iter.hasNext()) {

Properties prod = (Properties) iter.next();
System.out.println("productId : " + prod.getProperty("productId"));
System.out.println("Price : " + prod.getProperty("Price"));
}

}
catch (Exception e) {
throw (new ServletException(e));
}
finally{
try { if( rs != null ) rs.close() ; } catch( SQLException ex ) { }
try { if( st != null ) st.close() ; } catch( SQLException ex ) { }
try { if( c != null ) c.close() ; } catch( SQLException ex ) { }
} %>

<TABLE align='center'>
<TR><TD><TD><DIV ALIGN="right"><FONT size="+2"><B><A href='categoryList.jsp'> Continue Shopping!
</A></B></FONT></DIV></TD>
<TR><TD><TD><DIV ALIGN="right"><FONT size="+2"><B><A href='checkout.jsp'> Go To Checkout
</A></B></FONT></DIV></TD>
</TR>
</TABLE>
</BODY>
</HTML>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2004
Added on May 19 2004
11 comments
135 views