高手帮我看下JSP调用BEAN里的get()有啥错误
错误提示如下escription The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /studentInfo.jsp at line 39
36: {
37: //Teacher teacher=(Teacher)request.getAttribute("teacher");
38: Teacher teacher=(Teacher)session.getAttribute("teacher");
39: Teaching_class teaching_class=(Teaching_class)session.getAttribute("teacher");
40: String str="";
41: String str1="";
42: str+="<tr><td> 教师编号:"+teacher.getTeId()+"</td></tr>";
--------------------编程问答-------------------- session里的teacher是用户登录获取到的参数 --------------------编程问答-------------------- 意思就是通过获取用户登录的session然后获取该用户的信息,以及该用户所在教学班的信息 --------------------编程问答-------------------- 38: Teacher teacher=(Teacher)session.getAttribute("teacher");
39: Teaching_class teaching_class=(Teaching_class)session.getAttribute("teacher");
同样的用teacher参数名去取,为什么可以转成不同的java类,你有没有看看你的session.getAttribute("teacher");这个teacher是后台是存放的什么类型的变量,系统报错的是39行,你看看比对一下
--------------------编程问答-------------------- 38: Teacher teacher=(Teacher)session.getAttribute("teacher");
39: Teaching_class teaching_class=(Teaching_class)session.getAttribute("teacher");
很显然,你的session.getAttribute("teacher");类型是Teacher类型的,39行你把它转成Teaching_class 是要报错的
--------------------编程问答-------------------- 如果看不到错误,在后台模拟获取
Teaching_class teaching_class=(Teaching_class)session.getAttribute("teacher");
看是否报classcastException。
3楼4楼都是正确的:
Teaching_class 估计是你的另外一个“班级和老师的对应表”所生成的BEAN对象。
根据你的代码,猜想你的后台取得"teacher"参数,然后组装的是Teacher 对象,传到前台页面上。
你组装成Teacher 类型就只能用Teacher 类型来接收。
--------------------编程问答-------------------- 我觉得这个明显的问题,楼主应该自己找找的,太浪费分了啊 --------------------编程问答--------------------
那我Teaching_class也想获得当前登录用户的id怎么弄呢 --------------------编程问答--------------------
Teacher teacher=(Teacher)session.getAttribute("teacher");
39: Teaching_class teaching_class=new Teaching_class();
teaching_class.setTeccherId(teacher.getid()); --------------------编程问答-------------------- 恩 你把类里面的2个属性定义成一样了 导致了数据装换错误
补充:Java , Web 开发