Hey guys.. I'm working on one project which is in directory -
C:\Tomcat 6\webapps\ROOT\cart
This is the code in file called shop.jsp
<%@ page language = "java" contentType = "text/html"
import = "ShoppingBasket, Product, java.sql.*"
errorPage = "errorpage.jsp" %>
<html>
<head> <title>Welcome to Shop</title></head>
<body>
<table width = "385" border="0" cellspacing="0">
<tr>
<td colspan="4">More Books from me</td>
</tr><tr>
<td colspan="4" align ="right">
<a href = "<%=response.encodeURL("shop-basket.jsp") %>"> View Basket </a></td>
</tr><tr>
<td><b>Ref</b></td><b>Title</b></td>
<td><b>Price</b></td></td></tr>
<%
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection connection = null;
connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "rahul");
Statement stmt = null;
ResultSet RS = null;
stmt = connection.createStatement();
RS = stmt.executeQuery("select * from items");
int rowCounter = 0;
while(RS.next())
{
String item_id = RS.getString("id");
String title = RS.getString("title");
String desc = RS.getString("desc");
String price = RS.getString("price");
rowCounter=rowCounter+1;
String bg= (rowCounter % 2 !=0) ?"#C0C0C0":"#ffffff";
%>
<tr bgcolor = <%=bg%>">
<td><%=item_id%></td>
<td><b><%=title %></b><br/><%=desc%></td>
<td><b><%=price %></b></td>
<td>
<a href =" <% response.encodeURL("shop-products.jsp?title="+title+"&item_id="+item_id+"&price="+price); %> "> Add to Cart </a></td>
</tr>
<% } RS.close(); connection.close(); %>
</table>
<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>
I've to include class files named ShoppingBasket and Product but somehow I'm not getting where to put those class files so that my JSP file will automatically include them.
As the classes are not included, I'm getting errors like
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 6 in the generated java file
The import ShoppingBasket cannot be resolved
An error occurred at line: 7 in the generated java file
The import Product cannot be resolved
Please help me :)
Thanks,
Rahul