【发布时间】:2016-06-17 21:50:27
【问题描述】:
在下面的代码中,learning 是一个我想保存到 http 会话的 Learning 实例
learning = new Learning(learningContext);
HttpSession webSession = request.getSession();
webSession.setAttribute("learning", learning);
Learning learnTest = webSession.getAttribute("learning");
当我运行下面的代码时,我得到:
Incompatible types
Learning learnTest = webSession.getAttribute("learning")
required: Learning
found: Object
我可以将非通用对象保存到会话中吗?还有其他方法可以实现吗?
【问题讨论】:
-
您是否尝试过任何解决方法,例如 .toString() 或强制转换?
标签: java session tomcat servlets