骨折处鼓起是骨痂吗:在JSP中调用JavaBean访问数据库,出现的问题?

来源:百度文库 编辑:神马品牌网 时间:2024/03/29 07:46:35
conn_db.jsp为:

<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" import="java.sql.*"%>
<jsp:useBean id="connDbBean" scope="page" class="student.conn"/>
<html>
<head>
<title>test db connection</title>
</head>
<body bgcolor="#FFFFFF">
<div align="center">
<table width="60%" border="1">
<tr bgcolor="#CCCCFF">
<td width="50%">
<div align="center"><font color="#FF0033"><b>姓名</b></font></div>
</td>
<td width="25%">
<div align="center"><font color="#FF0033"><b>性别</b></font></div>
</td>
<td width="25%">
<div align="center"><font color="#FF0033"><b>分数</b></font></div>
</td>
</tr>
<%
ResultSet RS_result = connDbBean.executeQuery("select * from table1");
String studentName="";
String studentSex="";
int studentScore=0;
while(RS_result.next())
{
studentName = RS_result.getString("name");
studentSex = RS_result.getString("sex");
studentScore = RS_result.getInt("score");
%>
<tr>
<td width="50%" bgcolor="#FFFFFF">
<div align="center"><%=studentName%></div>
</td>
<td width="25%">
<div align="center"><%=studentSex%></div>
</td>
<td width="25%">
<div align="center"><%=studentScore%></div>
</td>
</tr>
<%
}
RS_result.close();
%>
</table>
</body>
</html>

错误为:
exception

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

An error occurred at line: 2 in the jsp file: /JSP-08/conn_db.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\Tomcat\work\Standalone\localhost\myjsp\JSP-08\conn_db_jsp.java:44: package student does not exist
student.conn connDbBean = null;
^

An error occurred at line: 2 in the jsp file: /JSP-08/conn_db.jsp

Generated servlet error:
C:\Tomcat\work\Standalone\localhost\myjsp\JSP-08\conn_db_jsp.java:46: package student does not exist
connDbBean = (student.conn) pageContext.getAttribute("connDbBean", PageContext.PAGE_SCOPE);
^

An error occurred at line: 2 in the jsp file: /JSP-08/conn_db.jsp

Generated servlet error:
C:\Tomcat\work\Standalone\localhost\myjsp\JSP-08\conn_db_jsp.java:49: package student does not exist
connDbBean = (student.conn) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "student.conn");
^
3 errors
org.apache.jasper.JasperException: /xsgl/shop/viewCategory.jsp(1,0) This absolute uri (http://java.sun.com/jstl/core) cannot be resolved in either web.xml or the jar files deployed with this application
这是什么错误呢

你没有导入你bean的那个包

student.conn找不到这个类

<%@page import="student.conn"%>

先导包试试

如果还不行,可能是BEAN在服务器中的部署出现了问题

提示找不到student.conn包,看你的WEB-INF/classes/student/conn.class文件存在否?还有新建项目(我们用Eclipse)时,源和输出文件夹是否都已指定。
如果你有用JSTL的话,在JSP页面加入<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>!