日期:2014-05-18  浏览次数:20764 次

JSP中使用JavaBean问题?
小弟我刚开始使用JSP+JavaBean开发,之前是做纯Java开发的,在使用JavaBean的问题上遇到了问题!
问题是着样的
我的工作空间是K:\Apache   Software   Foundation\Tomcat   5.0\webapps\ROOT\Hawkins_JSP
在该空间下有K:\Apache   Software   Foundation\Tomcat   5.0\webapps\ROOT\Hawkins_JSP\WEB-INF\classes\test用于存放java的class文件
我的环境变量classpath   :;K:\Apache   Software   Foundation\Tomcat   5.0\webapps\ROOT\Hawkins_JSP\WEB-INF\classes
我在K:\Apache   Software   Foundation\Tomcat   5.0\webapps\ROOT\Hawkins_JSP目录下建了一个JSP文件TestBean.jsp内容是

<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN "   "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 无标题文档 </title>
</head>

<body>
<center>
<%@   page   import= "test.TestBean "   %>
<%  
TestBean   testBean=new   TestBean( "This   is   a   test   java   bean. ");  
%>
Java   bean   name   is:   <%=testBean.getName()%>
</center>
</body>
</html>

然后我在K:\Apache   Software   Foundation\Tomcat   5.0\webapps\ROOT\Hawkins_JSP\WEB-INF\classes下建了一个java文件TestBean.java
内容是
package   test;  
public   class   TestBean
{  
private   String   name   =   null;  
public   TestBean(String   strName_p)
{
this.name=strName_p;  
}    
public   void   setName(String   strName_p)
{  
this.name=strName_p;  
}  
public   String   getName()
{  
return   this.name;  
}    
}

然后我在dos   下   K:\Apache   Software   Foundation\Tomcat   5.0\webapps\ROOT\Hawkins_JSP\WEB-INF\classes\test目录下输入
javac   TestBean.java编译完成后我启动了Tomcat5.0

在输入http://localhost:8080/Hawkins_JSP/TestBean.jsp后结果是

HTTP   Status   500   -  

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

type   Exception   report

message  

description   The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

exception  

org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP

Generated   servlet   error:
K:\Apache   Software   Foundation\Tomcat   5.0\work\Catalina\localhost\_\org\apache\jsp\Hawkins_005fJSP\TestBean_jsp.java:7:   软件包   test   不存在
import   test.TestBean;
                        ^


An   error   occurred   at   line:   12   in   the   jsp   file:   /Ha