Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Bean Problem  RSS feed

 
Donna Harrington
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Jeffrey Hunter
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget, all your beans should be inside a package. This may resolve your problem.



And on the JSP:


[ May 28, 2004: Message edited by: Jeffrey Hunter ]
 
Donna Harrington
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanx ;-)

But i'm still getting the error. do i just type say 'package myBeans' on my 'CartBean' class or must i do something else..cos i did what u said and its still bringing up the error.thanx
 
Jeffrey Hunter
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To package a class, yes, all you need do is define the package at the beginning of your source file (as in the previous example).

The directory structure for your class files should follow this convention:

CATALINE_HOME/webapps/myApp/WEB-INF/classes/packageName/KidneyBean.class

Tomcat (I'm assuming you're using Tomcat), will look in the WEB-INF/classes directory and attempt to resolve the package name, so you should have a directory beneath classes with the appropriate name (whatever the name of your package is).
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!