Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当我尝试强制转换session.getAttribute时,我得到一个classcast异常?_Java_Jsp - Fatal编程技术网

Java 当我尝试强制转换session.getAttribute时,我得到一个classcast异常?

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

当我尝试将session.getAttribute强制转换为lessonselection bean时,我遇到一个classcast异常,以下是我的工作:

bean类:

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(“课程”)
的实际类型以及您试图将其转换为错误类型的原因。您很可能需要更改代码中某些元素的类型。

我觉得某个地方出现了一个问题