当前位置: 代码迷 >> Java Web开发 >> usebean id=. type=. 报错,求解决解决思路
  详细解决方案

usebean id=. type=. 报错,求解决解决思路

热度:4460   发布时间:2016-04-10 22:55:45.0
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.handleJspException(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.ServletExceptionjava.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)


root cause 

java.lang.InstantiationException: bean lefttopbean not found within scope
org.apache.jsp.lefttopback_jsp._jspService(lefttopback_jsp.java:70)
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)


note The full stack trace of the root cause is available in the Apache Tomcat/7.0.40 logs.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.40



------解决方案--------------------
我没大看明白,竟然你要在servlet里面创建对象,你直接在servlet方法里面把对象放入session里面啊,干嘛要在jsp里面写,而且你type肯定是个错的.
------解决方案--------------------
这种情况应该取出来直接用,比如用jstl输出${lefttopbean.xxxxx},而不是使用useBean.
  相关解决方案