usebean id=... type=.... 报错,求解决
在servlet里创建了javabean对象,并且保存到session里,代码如下
Lefttopbean lt=new Lefttopbean();
session.setAttribute("lefttopbean",lt);
在jsp页面上引用javabean,代码如下
<jsp:useBean id="lefttopbean" type="user.yourbean.Lefttopbean" scope="session" />
结果上面这句话报错,报错如下
注意,有的人可能会说,把type换成class属性就没事了,我试过了,如果换成class属性,运行没错,但是bean对象是jsp页面执行时新创建的,不是在servlet里创建的,所以jsp页面获取的bean的方法的数据会有问题,不合逻辑
HTTP Status 500 - An exception occurred processing JSP page /lefttopback.jsp at line 4
--------------------------------------------------------------------------------
type Exception report
message An exception occurred processing JSP page /lefttopback.jsp at line 4
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /lefttopback.jsp at line 4
1: <%@ page import="user.yourbean.Lefttopbean" %>
2: <html>
3: <%@ page contentType="text/html; charset=utf-8" %>
4: <jsp:useBean id="lefttopbean" type="user.yourbean.Lefttopbean" scope="session" />
5: <body>
6: <jsp:getProperty name="lefttopbean" property="information" />
7: <%
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handle
JspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
user.yourservlet.Lefttop.doPost(Lefttop.java:88)
user.yourservlet.Lefttop.doGet(Lefttop.java:91)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
root cause
javax.servlet.ServletException:
java.lang.InstantiationException: bean lefttopbean not found within scope
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.lefttopback_jsp._jspService(lefttopback_jsp.java:105)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
user.yourservlet.Lefttop.doPost(Lefttop.java:88)
user.yourservlet.Lefttop.doGet(Lefttop.java:91)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)