日期:2014-05-20  浏览次数:20821 次

关于JavaBean的问题
CSDN在干什么?昨天发的帖子,怎么不见贴出来,只好再贴一遍!
——————————————————————————————

初次试JavaBean,但不行,费了很多劲,每找出原因,诸位请多帮助。
——————————————————————————————
我用eclipse+lomboz,在JspTest/src目录下的JspBean.java文件:

public   class   JspBean   {
private   String   str= " ";
public   JspBean(){}
public   String   getStr()   {return   str;}
public   void   setStr(String   str)   {this.str   =   str;}
}
————————————————————————————————
在JspTest/WebContent/的index.jsp:

<%@   page   language= "java "   contentType= "text/html;   charset=GB18030 "
pageEncoding= "GB18030 "%>
<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN "   "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<jsp:useBean   id= "BeanID "   class= "JspBean "   />
<jsp:setProperty   name= "BeanID "   property= "* "   />
<meta   http-eqxuiv= "Content-Type "   content= "text/html;   charset=GB18030 ">
<title> Insert   title   here </title>
</head>
<body>
<h2> JSP和JavaBean测试页面 </h2>
今天是: <%=new   java.util.Date()   %>
<br/> Bean字符串是: <!jsp:getProperty   name= "BeanID "   property= "Str "   />
</body>
</html>
————————————————————————————————
服务器Tomcat   5.5,运行主要有这样错误:

2007-3-11   21:00:33   org.apache.catalina.core.StandardWrapperValve   invoke
严重:   Servlet.service()   for   servlet   jsp   threw   exception
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

An   error   occurred   at   line:   6   in   the   jsp   file:   /index.jsp
Generated   servlet   error:
JspBean   cannot   be   resolved   to   a   type

到底是什么原因呢,生成的JspBean.class我分别放在JspTest/build/classes,JspTest/WebContent,JspTest/WebContent/WEB-INF下都试过,一样的错误,不知道问题在哪里。

------解决方案--------------------
JavaBean需要放在一个package下面
------解决方案--------------------
1. Put your bean class in a package.


package test;

import...........


2. Put the .class file in web-inf/classes/test/testBean.class

3. Specify the fully qualified name of the class in the useBean declaration.


<jsp:useBean class= "test.testBean " .../>


------解决方案--------------------
呵呵··我以前也遇到过,。。用PACKAGE就没问题了··
------解决方案--------------------
没有写包 JSP中也没import
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html