jsp的问题 java.lang.ClassCastException: java.util.HashMap
<%@pagecontentType="text/html;charset=gb2312"language="java"import="java.util.*,xxx.*...
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.* , xxx.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
var are=document.table.shan;
function fun(){
//var b=false;
var x=document.table.shan1;
if(x.checked==true){
for(var l=0;l<are.length;l++){
are[l].checked=true;
}
}else{
for(var l=0;l<are.length;l++){
are[l].checked=false;
}
}
}
function fun1(){
if(confirm("确定要删除吗?")){
location.href="shanxuan.jsp";
}
}
function fun2(){
if(confirm("确定要删除吗?")){
location.href="shanchu.jsp";
}
}
function one(id){
if(confirm("确定要删除吗?")){
location.href="one.jsp?goodsid="+id;
}
}
</script>
</head>
<body>
<form name="table" action="shanxuan.jsp" method="post">
<table border="1">
<tr><td> <input type="checkbox" name="shan1" value="1" onClick="fun()"></td><td>商品名称</td><td>商品数量</td><td>修改</td><td>删除</td></tr>
<%
request.setCharacterEncoding("gb2312");
ArrayList list=(ArrayList)session.getAttribute("shop");这句话出问题了
Iterator it=list.iterator();
for(int i=0;i<list.size();i++){
Goods g=(Goods)list.get(i);
String s3=g.getName();
int s4=g.getCnt();
out.print("<tr>");
%>
<td><input type="checkbox" name="shan" value="<%=i%>" ></td>
<%
out.print(" <td>" + s3 + "</td>");
out.print(" <td>" + s4 + "</td>");
%>
<td><a href="gouxiu.jsp?goodid=<%= i%>">修改</a></td>
<td><a href="javascript:one(<%=i%>)">删除</a></td>
<%
out.print("</tr>");
}
%>
</table>
<input type="submit" value="删除选中" onClick="fun1()">
</form>
<a href="gou.html">返回</a>
<a href="javascript:fun2()">全部删除</a>
</body>
</html>
谁能告诉我到底是哪错了?
java.lang.ClassCastException: java.util.HashMap
org.apache.jsp.gouwu_jsp._jspService(gouwu_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 展开
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script language="javascript">
var are=document.table.shan;
function fun(){
//var b=false;
var x=document.table.shan1;
if(x.checked==true){
for(var l=0;l<are.length;l++){
are[l].checked=true;
}
}else{
for(var l=0;l<are.length;l++){
are[l].checked=false;
}
}
}
function fun1(){
if(confirm("确定要删除吗?")){
location.href="shanxuan.jsp";
}
}
function fun2(){
if(confirm("确定要删除吗?")){
location.href="shanchu.jsp";
}
}
function one(id){
if(confirm("确定要删除吗?")){
location.href="one.jsp?goodsid="+id;
}
}
</script>
</head>
<body>
<form name="table" action="shanxuan.jsp" method="post">
<table border="1">
<tr><td> <input type="checkbox" name="shan1" value="1" onClick="fun()"></td><td>商品名称</td><td>商品数量</td><td>修改</td><td>删除</td></tr>
<%
request.setCharacterEncoding("gb2312");
ArrayList list=(ArrayList)session.getAttribute("shop");这句话出问题了
Iterator it=list.iterator();
for(int i=0;i<list.size();i++){
Goods g=(Goods)list.get(i);
String s3=g.getName();
int s4=g.getCnt();
out.print("<tr>");
%>
<td><input type="checkbox" name="shan" value="<%=i%>" ></td>
<%
out.print(" <td>" + s3 + "</td>");
out.print(" <td>" + s4 + "</td>");
%>
<td><a href="gouxiu.jsp?goodid=<%= i%>">修改</a></td>
<td><a href="javascript:one(<%=i%>)">删除</a></td>
<%
out.print("</tr>");
}
%>
</table>
<input type="submit" value="删除选中" onClick="fun1()">
</form>
<a href="gou.html">返回</a>
<a href="javascript:fun2()">全部删除</a>
</body>
</html>
谁能告诉我到底是哪错了?
java.lang.ClassCastException: java.util.HashMap
org.apache.jsp.gouwu_jsp._jspService(gouwu_jsp.java:91)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802) 展开
1个回答
展开全部
ArrayList list=(ArrayList)session.getAttribute("shop");
异常抛得是类型转换错误,也就是说从session取到的值不是List类型的.
但是你给出的异常java.lang.ClassCastException: java.util.HashMap.
却是Map的转换异常,能否把全部的异常都给出的.
建议在代码中加入 try . 将所有的异常都打出来好调试.
异常抛得是类型转换错误,也就是说从session取到的值不是List类型的.
但是你给出的异常java.lang.ClassCastException: java.util.HashMap.
却是Map的转换异常,能否把全部的异常都给出的.
建议在代码中加入 try . 将所有的异常都打出来好调试.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询