javabean求助

daishunchaoaiqiu 2011-02-27 10:06:36
有一个Bean.java类和DBConn.java类
在包com.liuyan.bean里面
在DBConn类中有这么个函数
public static ArrayList set() throws Exception{
Bean b=new Bean();
ArrayList a=new ArrayList();
ResultSet rs=getSql("select * from liuyan"); //这个函数已经写好连接rs了
while(rs.next())
{

b.setAuthor(rs.getString("author"));
b.setContent(rs.getString("content"));
b.setDate(rs.getString("time"));
a.add(b);
}
return a;
}
主页面中
<%

ArrayList a=new ArrayList();

a=DBConn.set(); //这段报错An error occurred at line: 37 in the jsp file: /index.jsp DBConn cannot be resolved


Bean b=new Bean();
Connection con=DBConn.getCon();
for(int i=0;i<a.size();i++)
{
b=(Bean)a.get(i);
out.println("<tr>");
out.println("<td>"+b.getAuthor()+"</td>");
out.println("<td>"+b.getContent()+"</td>");
out.println("<td>"+b.getDate()+"</td>");
out.println("</tr>");
}

%>

我自己写了个类能成功的,但是用在JSP页面里就出错怎么回事?
数据库驱动包导入的。
...全文
102 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhoujingzhe 2011-02-28
  • 打赏
  • 举报
回复
新手学习中 围观
sbaiss 2011-02-27
  • 打赏
  • 举报
回复
试一下楼上的方法,如果不行就重新部署一下项目,再不行就重建项目,我也遇过类似的问题,就是这样解决的,希望对你有帮助
thegodofwar 2011-02-27
  • 打赏
  • 举报
回复
引入用逗号隔开不就可以了吗,不用那么多import
JavaAlpha 2011-02-27
  • 打赏
  • 举报
回复
<%@page import="com.liuyan.bean.*" %>
这样写
JavaAlpha 2011-02-27
  • 打赏
  • 举报
回复
别这样引入。要单独的分开引入。
daishunchaoaiqiu 2011-02-27
  • 打赏
  • 举报
回复
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*" import="java.util.*" import="com.liuyan.bean.*" %>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>


<h2 align="center">留言板</h2>
<table>
<tr>
<td>
作者
</td>
<td>
留言
</td>
<td>
时间

</td>
</tr>
<%

ArrayList a=new ArrayList();
try{
a=DBConn.set();
}catch(Exception e){}
Bean b=new Bean();
Connection con=DBConn.getCon();
for(int i=0;i<a.size();i++)
{
b=(Bean)a.get(i);
out.println("<tr>");
out.println("<td>"+b.getAuthor()+"</td>");
out.println("<td>"+b.getContent()+"</td>");
out.println("<td>"+b.getDate()+"</td>");
out.println("</tr>");
}

%>
</table>

</body>
</html>
daishunchaoaiqiu 2011-02-27
  • 打赏
  • 举报
回复
原来错误蛮多的。
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:

An error occurred at line: 37 in the jsp file: /index.jsp
DBConn cannot be resolved
34:
35: ArrayList a=new ArrayList();
36: try{
37: a=DBConn.set();
38: }catch(Exception e){}
39: Bean b=new Bean();
40: Connection con=DBConn.getCon();


An error occurred at line: 39 in the jsp file: /index.jsp
Bean cannot be resolved to a type
36: try{
37: a=DBConn.set();
38: }catch(Exception e){}
39: Bean b=new Bean();
40: Connection con=DBConn.getCon();
41: for(int i=0;i<a.size();i++)
42: {


An error occurred at line: 39 in the jsp file: /index.jsp
Bean cannot be resolved to a type
36: try{
37: a=DBConn.set();
38: }catch(Exception e){}
39: Bean b=new Bean();
40: Connection con=DBConn.getCon();
41: for(int i=0;i<a.size();i++)
42: {


An error occurred at line: 40 in the jsp file: /index.jsp
DBConn cannot be resolved
37: a=DBConn.set();
38: }catch(Exception e){}
39: Bean b=new Bean();
40: Connection con=DBConn.getCon();
41: for(int i=0;i<a.size();i++)
42: {
43: b=(Bean)a.get(i);


An error occurred at line: 43 in the jsp file: /index.jsp
Bean cannot be resolved to a type
40: Connection con=DBConn.getCon();
41: for(int i=0;i<a.size();i++)
42: {
43: b=(Bean)a.get(i);
44: out.println("<tr>");
45: out.println("<td>"+b.getAuthor()+"</td>");
46: out.println("<td>"+b.getContent()+"</td>");

JavaAlpha 2011-02-27
  • 打赏
  • 举报
回复
你有这个类,就不应该出现这个错误信息了。
你看看你引入的类目录是否正确。
daishunchaoaiqiu 2011-02-27
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 liuchao1989 的回复:]
在jsp页面的上面没有导入DBConn类,所以无法使用DBConn类.
应该在jsp顶部添加<%@ page import="包名.DBConn"%>,引入DBConn类.
[/Quote]
有的
daishunchaoaiqiu 2011-02-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 javaalpha 的回复:]
你的jsp头部 引入DBConn这个类了吗?
[/Quote]
有的
daishunchaoaiqiu 2011-02-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 chenmiaoquan2008 的回复:]
在jsp中有没有包含进相关的Bean?
<%@ page import="XXX.XXX.XXX.XXX.DBConn"%>
[/Quote]
包含了
JavaAlpha 2011-02-27
  • 打赏
  • 举报
回复
你的jsp头部 引入DBConn这个类了吗?
liuchao1989 2011-02-27
  • 打赏
  • 举报
回复
在jsp页面的上面没有导入DBConn类,所以无法使用DBConn类.
应该在jsp顶部添加<%@ page import="包名.DBConn"%>,引入DBConn类.
JavaAlpha 2011-02-27
  • 打赏
  • 举报
回复
jsp出现什么错误?发异常信息看看。
chenmiaoquan2008 2011-02-27
  • 打赏
  • 举报
回复
在jsp中有没有包含进相关的Bean?
<%@ page import="XXX.XXX.XXX.XXX.DBConn"%>

81,092

社区成员

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

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