初写javabean时遇到的问题

moyancn 2003-04-07 11:14:36
demo.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>客户信息调查</title>
</head>
<body>
<p><b>客户信息调查</b></p>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="DB" scope="page" class="DBconn"/>
<%
ResultSet rs=DB.executeQuery("select * from EG_TASK order by id");
while (rs.next()){
out.print("<LI>"+rs.getString("TASK_NAME")+"<LI>");
out.print("<LI>"+rs.getInt("TASK_LEVEL")+"<LI>");
out.print("<LI>"+StartTime=rs.getDate("TASK_STARTTIME")+"<LI>");
}
rs.close();
%>
</body>
</html>
学习调用javaBean,可是有问题,不知为何?
import java.sql.*;
public class DBconn{
String DBdrive="public PreparedStatement getUpdatedPstmt()";
String ConnStr="jdbc:oracle:thin:@192.168.0.8:1521:develop";
Connection Conn=null;
ResultSet Rs=null;
public DBconn(){
try{
Class.forName(DBdrive);
}catch(ClassNotFoundException e){
System.out.println("DBconn():"+e.getMessage());
}
}
public ResultSet executeQuery(String sql){
Rs=null;
try{
Conn = DriverManager.getConnection(ConnStr, "szhr", "szhr123");
Statement stmt=Conn.createStatement();
Rs=stmt.executeQuery(sql);
}catch(SQLException e){
System.out.println(e.getMessage());
}
return Rs;
}
}
文件的位置都没放错,jsp在tomcat的example下,javabean在web-inf的classes中,可是tomcat提示org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 8 in the jsp file: /demo.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\demo_jsp.java:54: cannot resolve symbol
symbol : class DBconn
location: class org.apache.jsp.demo_jsp
DBconn DB = null;
^



An error occurred at line: 8 in the jsp file: /demo.jsp

Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\demo_jsp.java:56: cannot resolve symbol
symbol : class DBconn
location: class org.apache.jsp.demo_jsp
DB = (DBconn) pageContext.getAttribute("DB", PageContext.PAGE_SCOPE);
^



An error occurred at line: 8 in the jsp file: /demo.jsp

Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\demo_jsp.java:59: cannot resolve symbol
symbol : class DBconn
location: class org.apache.jsp.demo_jsp
DB = (DBconn) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "DBconn");
^



An error occurred at line: 9 in the jsp file: /demo.jsp

Generated servlet error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\examples\demo_jsp.java:74: cannot resolve symbol
symbol : variable StartTime
location: class org.apache.jsp.demo_jsp
out.print(""+StartTime=rs.getDate("TASK_STARTTIME")+"");
^
4 errors
为什么呢,搞不懂,希望高手指点!
...全文
45 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
struggle007csdn 2003-04-07
  • 打赏
  • 举报
回复
你这样调用的话。JAVABEAN这个文件一定要放在一个包下。
zez 2003-04-07
  • 打赏
  • 举报
回复
bean有没有设置包 ?
就是package ...
没有建议加上,包名自定...
我没遇到过类似问题,不过见别人讨论过,好像必须要用包的...
jcq 2003-04-07
  • 打赏
  • 举报
回复
建议你将你的class加一句:
package就是使用一个包,然后再试试,还有就是你的StartTime没有定义

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧