hey everyone!
I'm having awful trouble here. What i want to do is insert username,product id and quantity into my shopping cart table. There is no problem with quantity but i'm havin problems with username and productid because the customer has signed in previous pages before and also they have chosen a product previous pages before also...so i created a
java bean which where i would be able to get username and productid from previous pages. Here is my code for my java bean and my checkout page..where i get my username.product id and quantity and insert into cart table by sql statement.
My problem is it does not recognise my "CartBean" so gives this error
org.apache.jasper.JasperException: CartBean
org.apache.jasper.compiler.BeanRepository.getBeanType(BeanRepository.java:122)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1053)
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1079)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2180)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2230)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2236)
org.apache.jasper.compiler.Node$Root.accept(Node.java:485)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2180)
org.apache.jasper.compiler.Generator.generate(Generator.java:3255)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:456)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:553)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:305)
root cause
Here's my CartBean code:
public class CartBean {
private
String Username;
private String productId;
public CartBean(){
}
public String getUsername(){
return Username;
}
public void setUsername(String newUsername){
Username = newUsername;
}
public String getproductId(){
return productId;
}
public void setproductId(String newproductId){
productId = newproductId;
}
}
And here's my checkout.jsp --->
<%@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> Checkout</title>
</head>
<body bgcolor="#228B22">
<font face="Times New Roman,Times" size="+3"> Checkout</font>
<hr>
<
jsp:useBean id="cb" scope="session" class="CartBean"/>
<jsp:setProperty name="cb" property="Username" param="newUsername"/>
<jsp:setProperty name="cb" property="productId" param="newproductId"/>
<form method=get>
<% 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";
try{
Class.forName("com.mysql.jdbc.Driver");
c = DriverManager.getConnection(connectionURL,username, password);
st = c.createStatement();
%>
<jsp:getProperty name="cb" property="Username"/>
<jsp:getProperty name="cb" property="productId"/>
<%
String Username = request.getParameter("Username");
String productId = request.getParameter("productId");
//String PName = request.getParameter("PName");
//String price = request.getParameter("Price");
String Quantity = request.getParameter("Quantity");
//Properties product = new Properties();
PreparedStatement p = c.prepareStatement("SELECT Username FROM customerdetails WHERE Username='"+ Username +"'");
PreparedStatement p1 = c.prepareStatement("SELECT productId FROM product WHERE productId='"+ productId +"'");
PreparedStatement p2 = c.prepareStatement("INSERT INTO Cart (Username,productId,Quantity)VALUES('"+Username+"','"+productId+"','"+Quantity+"')");
p.execute();
p1.execute();
int affectedRows= p2.executeUpdate();
if (rs.next()){
Username = rs.getString(1);
System.out.println(Username);
productId = rs.getString(2);
System.out.println(productId);
Quantity = rs.getString(3);
System.out.println(Quantity);
%>
<jsp:include page = "signinsuccessful.jsp"/> <%--display this page on the current page--%>
<%
}
else{
%>
<jsp:include page = "Err.jsp"/> <%--display this page on the current page--%>
<%}
%>
<a href="http://localhost:3306/categoryList.jsp">Shop some more!</a>
<%
}
catch(Exception yu){
yu.printStackTrace();
}
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 ) { }
}
%>
</center>
</body>
</html>
Thanx for taking time to read this!