session传对象的问题

binhai1980 binhai1980 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我在开始页面中把col是Collection类型的对象 放在session中
session.setAttribute("product",col);

在另一个页面中
Collection coll =session.getAttribute("product");
编译时有错
我改成
Collection coll=(Collection)session.getAttribute("pruduct");
Iterator it=coll.iterator();
while(it.hasNext()){
ProductInfo pi=(ProductInfo)it.next();
。。。。
。。。
编译通过
但运行时ProductInfo pi=(ProductInfo)it.next();这句话有异常
ApplicationDispatcher[/demo]: Servlet.service() for servlet debugjsp threw exception

java.lang.ClassCastException

at org.apache.jsp.search_0005fresult$jsp._jspService(search_0005fresult$jsp.java:72)
...全文
评论 6
收藏 已收藏
分享
返回顶部
binhai1980
Web 开发 81,108 成员 341,721 内容