JSP使用javabean出错:package dbbean does not exist 或者cannot resolve symbol

lona 2004-11-24 05:59:26
书上原封代码出错,是不是设置得问题?:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 14 in the jsp file: /useBeanJsp.jsp
Generated servlet error:
[javac] Compiling 1 source file

D:\tomcat-jwsdp-1.4\work\Catalina\localhost\dbBean3\org\apache\jsp\useBeanJsp_jsp.java:58: package dbbean does not exist
dbbean.dbBean dbBean = null;
^
An error occurred at line: 14 in the jsp file: /useBeanJsp.jsp

Generated servlet error:
D:\tomcat-jwsdp-1.4\work\Catalina\localhost\dbBean3\org\apache\jsp\useBeanJsp_jsp.java:60: package dbbean does not exist
dbBean = (dbbean.dbBean) _jspx_page_context.getAttribute("dbBean", PageContext.SESSION_SCOPE);

An error occurred at line: 14 in the jsp file: /useBeanJsp.jsp

Generated servlet error:
D:\tomcat-jwsdp-1.4\work\Catalina\localhost\dbBean3\org\apache\jsp\useBeanJsp_jsp.java:62: package dbbean does not exist
dbBean = new dbbean.dbBean();
^
3 errors
/////////////////////////////////////////////////////////////
我把包都去了,把类直接放在class文件夹下,代码也改后,错误变成

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

An error occurred at line: 14 in the jsp file: /useBeanJsp.jsp

Generated servlet error:
[javac] Compiling 1 source file

D:\tomcat-jwsdp-1.4\work\Catalina\localhost\dbBean2\org\apache\jsp\useBeanJsp_jsp.java:58: cannot resolve symbol
symbol : class DbBean
location: class org.apache.jsp.useBeanJsp_jsp
DbBean Bean = null;
^
An error occurred at line: 14 in the jsp file: /useBeanJsp.jsp

Generated servlet error:
D:\tomcat-jwsdp-1.4\work\Catalina\localhost\dbBean2\org\apache\jsp\useBeanJsp_jsp.java:60: cannot resolve symbol
symbol : class DbBean
location: class org.apache.jsp.useBeanJsp_jsp
Bean = (DbBean) _jspx_page_context.getAttribute("Bean", PageContext.PAGE_SCOPE);
^
An error occurred at line: 14 in the jsp file: /useBeanJsp.jsp

Generated servlet error:
D:\tomcat-jwsdp-1.4\work\Catalina\localhost\dbBean2\org\apache\jsp\useBeanJsp_jsp.java:62: cannot resolve symbol
symbol : class DbBean
location: class org.apache.jsp.useBeanJsp_jsp
Bean = new DbBean();
^
3 errors
////////////////////////////////////////////////////selectTable.htm
<html>
<head>
<title>选择数据表名网页</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<p align="center"><a href="useBeanJsp.jsp?tableName=studentbase">学生基本信息表</a></p>
<p align="center"><a href="useBeanJsp.jsp?tableName=studentaddress">学生地址表</a></p>
<p align="center"><a href="useBeanJsp.jsp?tableName=studentclass">选课信息表</a></p>
</body>
</html>
//////////////////////////////////////////////////useBeanJsp.jsp
<%@ page contentType="text/html; charset=GBK" %>
<%
/**
* Title: JSP页面使用JavaBean连接数据库
* Description: 教学示范
* Copyright: Copyright (c) 2003
* Company: 北京师范大学计算机系
* @author 孙一林
* @version 1.0
*/
%>
<html>
<%@ page import="java.sql.*"%>
<jsp:useBean id="dbBean" scope="session" class="dbbean.dbBean"/> <%/*使用dbBean的实例*/%>
<head>
<%
String tableName = request.getParameter("tableName");
%>
<title><%=tableName%>表中数据</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<%
if (tableName.equals("studentbase"))
{
out.println("<h2 align=center>学生基本信息表中的数据</h2>");
}
else if (tableName.equals("studentaddress"))
{
out.println("<h2 align=center>学生地址表中的数据</h2>");
}
else
{
out.println("<h2 align=center>选课信息表中的数据</h2>");
}
ResultSet rs = dbBean.getTableData(tableName); //获取指定表的数据的结果集
ResultSetMetaData rsData = rs.getMetaData(); //获取结果集信息
out.println("<table width=75% border=1 align=center><tr>");
for(int i=1; i<=rsData.getColumnCount(); i++) //输出字段名
{
out.println("<td>" + rsData.getColumnLabel(i) + "</td>");
}
out.println("</tr>");
while(rs.next()) //输出表中数据
{
out.println("<tr>");
for(int i=1; i<=rsData.getColumnCount();i++)
{
out.println("<td>" + rs.getString(i) + "</td>");
}
out.println("</tr>");
}
out.println("</table>");
%>
</body>
</html>
/////////////////////////////////////////////////////dbBean.java
package dbbean;

/**
* Title: JSP页面使用JavaBean连接数据库
* Description: 教学示范
* Copyright: Copyright (c) 2003
* Company: 北京师范大学计算机系
* @author 孙一林
* @version 1.0
*/

import java.io.*;
import java.sql.*;
import java.util.*;

public class dbBean {

private Connection connection = null; //定义与数据库进行连接的Connection对象
private Statement statement = null; //定义查询数据库的Statement对象
private ResultSet rs = null; //定义数据库查询的结果集

public dbBean() {
}

public ResultSet getTableData(String tableName) //根据用户指定的表名取出表中数据并返回
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //指定与数据库连接使用JDBC-ODBC桥驱动程序
String url = "jdbc:odbc:student"; //指定数据源名
connection = DriverManager.getConnection(url); //与数据源建立连接
String sql = "select * from " + tableName; //创建取出用户指定表中所有数据的SQL语句
Statement statement = connection.createStatement(); //创建Statement接口实例
ResultSet rs = statement.executeQuery(sql); //将数据存入结果集中
return rs;
}
catch(SQLException ex){ //捕捉异常
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null) {
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
catch(Exception ex ) {
ex.printStackTrace();
}
return null;
}
}

dbBean.java放在class文件夹中得dbbean文件夹中!
...全文
210 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yumeiren 2004-11-24
  • 打赏
  • 举报
回复
dbBean.java改成DbBean.java
类名都要大写的
public class DbBean
别的没仔细看,你先试试吧
lona 2004-11-24
  • 打赏
  • 举报
回复
在我同学得机器上好用,是不是需要配置什么地方!
环境变量好像没有错误呀!

81,094

社区成员

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

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