Everytime I run the jsp beow I get the following error can anybody help me
Generated servlet error:
C:\Tomcat\jakarta-tomcat-4.0.6\work\Standalone\localhost\_\shop_0002dproducts$jsp.java:188: Wrong number of arguments in constructor.
Product item = new Product(item_id, title, price);
^
1 error, 1 warning
The code
<%@ page language="java" contentType="text/html" import="ShoppingBasket
,Product, java.sql.*, java.util.*" errorPage="errorpage.jsp" %>
<html><head><title> Welcome to the Shop </title></head>
<body >
<table width="385" border="0" cellspacing="0" >
<tr> <td colspan="4">Roberts Record Store products:</td> </tr>
<tr> <td colspan="4" align="right">
//hyperlink to view basket
<a href="<%= response.encodeURL("shop-basket.jsp" %>">
<img src="images\viewbasket.gif"></a></td>
</tr>
<tr><td><b>Ref</b></td> <td><b>Title</b></td>
<td><b>Price</b></td> <td></td> </tr>
//get records from the items table in the shop database
<%
//1. Load the mySql jdbc driver
Class.forName("org.gjt.mm.mysql.Driver"
//2. open a connection to the "shop" database
java.sql.Connection connection = java.sql.DriverManager.getConnection
("jdbc:mysql://localhost/shop"
//3. create a statement object for sending SQL queries
java.sql.Statement stmt=connection.createStatement();
//4. place query results in a ResultSet object
java.sql.ResultSet RS = stmt.executeQuery("SELECT * FROM items"
//write a HTML table containing each record and assign ResultSet's column 1 to a string variable
int rowCounter = 0;
while (RS.next()) {
String item_id = RS.getString("item_id"
String title = RS.getString("title"
String description = RS.getString("description"
String price = RS.getString("price"
rowCounter++;
String bg = (rowCounter %2 !=0) ?"#C0C0C0":"#FFFFFF";
%>
<tr bgcolor="<%= bg %>">
<td><%= item_id %><td/>
<td><b><%= title %></b><br/>
<%= description %></td>
<td>£<%= price %></td>
<td>
//hyperlink to add an item to the basket
<a href="<%= response.encodeURL ("shop-products.jsp?title="+title+"&item_id="+item_id+"&price="+price) %> ">
<img src="images\addbasket.gif"></a></td>
</tr>
//6. clean up all the objects
<% } RS.close(); connection.close(); %>
</table>
// store the basket items in a Javabean instance
<jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
<% String title = request.getParameter("title"
if(title!= null)
{
String item_id = request.getParameter("item_id"
double price= Double.parseDouble(request.getParameter("price");
Product item = new Product(item_id, title, price);
basket.addProduct(item);
}
%>
</body>
</html>
Generated servlet error:
C:\Tomcat\jakarta-tomcat-4.0.6\work\Standalone\localhost\_\shop_0002dproducts$jsp.java:188: Wrong number of arguments in constructor.
Product item = new Product(item_id, title, price);
^
1 error, 1 warning
The code
<%@ page language="java" contentType="text/html" import="ShoppingBasket
,Product, java.sql.*, java.util.*" errorPage="errorpage.jsp" %>
<html><head><title> Welcome to the Shop </title></head>
<body >
<table width="385" border="0" cellspacing="0" >
<tr> <td colspan="4">Roberts Record Store products:</td> </tr>
<tr> <td colspan="4" align="right">
//hyperlink to view basket
<a href="<%= response.encodeURL("shop-basket.jsp" %>">
<img src="images\viewbasket.gif"></a></td>
</tr>
<tr><td><b>Ref</b></td> <td><b>Title</b></td>
<td><b>Price</b></td> <td></td> </tr>
//get records from the items table in the shop database
<%
//1. Load the mySql jdbc driver
Class.forName("org.gjt.mm.mysql.Driver"
//2. open a connection to the "shop" database
java.sql.Connection connection = java.sql.DriverManager.getConnection
("jdbc:mysql://localhost/shop"
//3. create a statement object for sending SQL queries
java.sql.Statement stmt=connection.createStatement();
//4. place query results in a ResultSet object
java.sql.ResultSet RS = stmt.executeQuery("SELECT * FROM items"
//write a HTML table containing each record and assign ResultSet's column 1 to a string variable
int rowCounter = 0;
while (RS.next()) {
String item_id = RS.getString("item_id"
String title = RS.getString("title"
String description = RS.getString("description"
String price = RS.getString("price"
rowCounter++;
String bg = (rowCounter %2 !=0) ?"#C0C0C0":"#FFFFFF";
%>
<tr bgcolor="<%= bg %>">
<td><%= item_id %><td/>
<td><b><%= title %></b><br/>
<%= description %></td>
<td>£<%= price %></td>
<td>
//hyperlink to add an item to the basket
<a href="<%= response.encodeURL ("shop-products.jsp?title="+title+"&item_id="+item_id+"&price="+price) %> ">
<img src="images\addbasket.gif"></a></td>
</tr>
//6. clean up all the objects
<% } RS.close(); connection.close(); %>
</table>
// store the basket items in a Javabean instance
<jsp:useBean id="basket" class="ShoppingBasket" scope="session"/>
<% String title = request.getParameter("title"
if(title!= null)
{
String item_id = request.getParameter("item_id"
double price= Double.parseDouble(request.getParameter("price");
Product item = new Product(item_id, title, price);
basket.addProduct(item);
}
%>
</body>
</html>