You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by yilmaz <yi...@hwajet.com.tw> on 2002/04/12 09:37:45 UTC
Problem with shopping cart JSP :( Help :(
Hi everyone,
hope i can find a solution from you Gurus.
I wrote a simple shopping cart JSP file that makes use of session attributes and Hastables to store temporary user data. Don't know why, it insists on not to working properly, throwing classCastException : java.util.Vector
at org.apache.jsp._0002fs_0002dcart_0002fshpcart_jsp._jspService(_0002fs_0002dcart_0002fshpcart_jsp.java:71)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
......
...
I am sure many of you , too, had faced damn this problem.
Although i am not using vectors in my code, i am having exception regarding to Vectors. Can somebody please tell me what is wrong with this before i got crazy , whole afternoon i have been working on this, trying to figure out what the hell problem is.
Here are some hints for those willing to help me:
win 2000
tomcat 4.0.1
my code :
<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html; charset=Big5" %>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=Big5">
<title>Shopping cart</title>
</head>
<%
Hashtable Pnames,Prices,Quantity;
Enumeration items=null;
Integer price=null; int pr=0;
Integer qnt=null; int quant=1;
int total=0;
Integer prodno=null;
String pname="";
Pnames=(Hashtable)session.getAttribute("cart.items");
if (Pnames==null) {
Pnames = new Hashtable();
Prices=new Hashtable();
Quantity=new Hashtable();
} else {
Prices=(Hashtable)session.getAttribute("cart.prices");
Quantity=(Hashtable)session.getAttribute("cart.quantity");
}
if (request.getParameter("pname")!=null) {
Pnames.put(new Integer(Integer.parseInt(request.getParameter("prodno"))),request.getParameter("pname"));
Prices.put(new Integer(Integer.parseInt(request.getParameter("prodno"))), new Integer(Integer.parseInt(request.getParameter("price"))));
Quantity.put(new Integer(Integer.parseInt(request.getParameter("prodno"))), new Integer(Integer.parseInt(request.getParameter("qnt"))));
}
session.setAttribute("cart.items",Pnames);
session.setAttribute("cart.prices",Prices);
session.setAttribute("cart.quantity",Quantity);
%>
<body background="images/bg.jpg">
<p></p>
<center><h1>
The items in your Shopping cart:
</h1>
<p></p>
<table border="1" cellpadding="0" cellspacing="2" width="466">
<tr>
<th>
<div align="center">
<b>itemno</b></div>
</th>
<th>
<div align="center">
<b>item </b></div>
</th>
<th><b>unitprice<br>
(NT)</b>
</th>
<th>
<div align="center">
<b>quantity </b></div>
</th>
<th>
<div align="center">
<b>totalprice<br>
(NT)</b></div>
</th>
<th>
<div align="center">
<b>remove</b></div>
</th>
</tr>
<%
if ( Pnames.keys()==null){ %>
There are no items in your shopping cart
<% } else {
items= Pnames.keys();
while (items.hasMoreElements()) {
prodno=(Integer)items.nextElement();
pname=(String)Pnames.get(prodno);
price=(Integer)Prices.get(prodno); pr=price.intValue();
qnt=(Integer)Quantity.get(prodno); quant=qnt.intValue();
total+=pr*quant;
%>
<tr>
<td><i><%=prodno.intValue()%></i></td>
<td><i><%=pname%></i></td>
<td><i><%=pr%></i></td>
<td><i><%=qnt%></i></td>
<td><i><%=quant*pr%></i></td>
<td>
<a href="remove.jsp?prodno=<%=prodno%>"><i>rem</i></a>
</td>
</tr>
<% } // end of while loop%>
</table>
<p><b>Total price :</b> <i><%=total%></i>
<p><% }//end of if loop %></p>
<table border="1" cellpadding="0" cellspacing="2" width="302">
<tr>
<th><a href="checkout.jsp">Check Out</a></th>
<th><a href="javascript:history.go(-1)">Go to Previous Page</a></th>
<th><a href="remove.jsp">Empty Shopping Cart</a></th>
</tr>
</table>
<p></p>
</center>
</body>
</html>
Re: Problem with shopping cart JSP :( Help :(
Posted by David Rault <to...@free.fr>.
hi
the ClassCastException _only_ occurs when _you_ try to cast an object to a
type it does not belong to
so i guess you have to check that all your
"Pnames=(Hashtable)session.getAttribute("cart.items");"
refer to object that _really_ are hashtables (they may even be null, that's
no problem)
where do you put them in your user's session ?
and how ?
----- Original Message -----
From: "yilmaz" <yi...@hwajet.com.tw>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Friday, April 12, 2002 9:37 AM
Subject: Problem with shopping cart JSP :( Help :(
Hi everyone,
hope i can find a solution from you Gurus.
I wrote a simple shopping cart JSP file that makes use of session attributes
and Hastables to store temporary user data. Don't know why, it insists on
not to working properly, throwing classCastException : java.util.Vector
at
org.apache.jsp._0002fs_0002dcart_0002fshpcart_jsp._jspService(_0002fs_0002dc
art_0002fshpcart_jsp.java:71)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
......
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>