Java 当我尝试强制转换session.getAttribute时,我得到一个classcast异常?
当我尝试将session.getAttribute强制转换为lessonselection bean时,我遇到一个classcast异常,以下是我的工作: bean类:Java 当我尝试强制转换session.getAttribute时,我得到一个classcast异常?,java,jsp,Java,Jsp,当我尝试将session.getAttribute强制转换为lessonselection bean时,我遇到一个classcast异常,以下是我的工作: bean类: public class LessonSelection implements Serializable{ private HashMap<String, Lesson> chosenLessons = new HashMap<String, Lesson>(); private int ownerID
public class LessonSelection implements Serializable{
private HashMap<String, Lesson> chosenLessons = new HashMap<String, Lesson>();
private int ownerID;
private DataSource ds = null;
private ResultSet rs = null;
private PreparedStatement st = null;
//private String LessonID;
//int counter for number of max lessons willl need to be 10.
public LessonSelection() {
}
public Set getItems() {
return chosenLessons.entrySet();
}
<c:forEach var="getAll" items="${lessons}">
<tr>
<td>
<c:out value="${getAll.value.description}"/>
</td>
<td>
<c:out value="${getAll.value.date}"/>
</td>
<td>
<c:out value="${getAll.value.startTime}"/>
</td>
<td>
<c:out value="${getAll.value.endTime}"/>
</td>
<td>
<c:out value="${getAll.value.level}"/>
</td>
查看:
public class LessonSelection implements Serializable{
private HashMap<String, Lesson> chosenLessons = new HashMap<String, Lesson>();
private int ownerID;
private DataSource ds = null;
private ResultSet rs = null;
private PreparedStatement st = null;
//private String LessonID;
//int counter for number of max lessons willl need to be 10.
public LessonSelection() {
}
public Set getItems() {
return chosenLessons.entrySet();
}
<c:forEach var="getAll" items="${lessons}">
<tr>
<td>
<c:out value="${getAll.value.description}"/>
</td>
<td>
<c:out value="${getAll.value.date}"/>
</td>
<td>
<c:out value="${getAll.value.startTime}"/>
</td>
<td>
<c:out value="${getAll.value.endTime}"/>
</td>
<td>
<c:out value="${getAll.value.level}"/>
</td>
,请给我一些帮助,我们将不胜感激。您收到的错误只意味着这行是错误的:
this.selectedLesson = session.getAttribute("lessons") == null ? new LessonSelection(getID) : (LessonSelection) session.getAttribute("lessons");
您正在尝试将
session.getAttribute(“课程”)
转换为LessonSelection
,它是java.util.HashMap$EntrySet
。您只需要查看这部分代码,即session.getAttribute(“课程”)
的实际类型以及您试图将其转换为错误类型的原因。您很可能需要更改代码中某些元素的类型。我觉得某个地方出现了一个问题