jsp连接数据库tomcat在用usebean时异常!求救!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

patriotlml 2006-02-28 08:14:39
我做了个jsp连接数据库的例子来测试我的tomcat服务器,用了javabean,但抛出了异常,错误如下:
希望大虾指教,谢谢哦。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a type

An error occurred at line: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a type

An error occurred at line: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a type


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
Apache Tomcat/5.5.9
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
其中jsp代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="jdbc" scope="page" class="Driver.jdbc"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>我要usebean!</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<% Connection con = jdbc.getConn() ;
Statement stmt = con.createStatement();
String strSQL = "select * from user";
ResultSet rs = stmt.executeQuery(strSQL);
while(rs.next())
{
String id = rs.getString("1");
String name = rs.getString("2");
%>
<tr>
<td width="95%" class="A">id=<%=id%> name=<%=name%>
<hr></td>

</tr>
<%

}
%>
</body>
</html>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

其中jdbc.class我放在了ub(本项目在webapps下)的\WEB-INF\classes\Driver下,即
C:\Tomcat 5.5\webapps\ub\WEB-INF\classes\Driver下
但不用usebean方式却可以正常访问,也可以调用数据库。

不管怎样,谢谢阅读。
...全文
77 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
patriotlml 2006-02-28
另:这是我拷的别人的东西,直接来用的,就是想测试下,才出的这个问题;

谢谢大家了!!
回复
hanhongmin 2006-02-28
...
回复
patriotlml 2006-02-28
已搞定:
第一:包和bean的名字最好用小写;
第二:在jsp中写对路径。
回复
doway 2006-02-28
Driver.jdbc

楼主的 JAVA 是哪里学地?包名全小写,类名首字大写,这是最一般的编码规范。

但这好像不足以引发异常。

不管怎么说,楼主先改一下,看上去真别扭。
回复
usherlight 2006-02-28
你在Server.xml中是如何配置你的应用的?
回复
ymfhcn 2006-02-28
错误报得很清楚啊
Driver.jdbc cannot be resolved or is not a type
Driver.jdbc是不能识别的符号或不是对应的类型
回复
ReViSion 2006-02-28
jf
回复
patriotlml 2006-02-28
其中我的bean 的写法:

package Driver;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.Date;

public class jdbc {

Connection conn = null ;
String re = "" ;
String dbip = "127.0.0.1" ;
String use = "root" ;
String pass = "root" ;
String dbName = "test" ;
public jdbc(){}
public java.sql.Connection getConn(){
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://"+dbip+":3306/"+dbName+"?user="+use+"&password="+pass+"&useUnicode=true&characterEncoding=gb2312" ;
conn= DriverManager.getConnection(url);

}
catch(Exception e){
e.printStackTrace();
}
return this.conn ;
}

public String ex_chinese(String s){
if(s==null){
s = "" ;
}
else{
try {
s = new String(s.getBytes("iso-8859-1"),"gb2312") ;
}
catch (Exception exception) {
}
}
return s ;
}

public String getTime()
{
String s = "";
try
{
SimpleDateFormat simpledateformat = new SimpleDateFormat("yyyy-M-d HH:ss");
Date date = new Date();
s = simpledateformat.format(new Date());
}
catch(Exception exception) { }
return s;
}

//public static void main(String[] args) {
//UntitledDao dao = new UntitledDao();
//ResultSet rs = dao.executeQuery("select * from jobs");
//dao.closedb();
//}

}
回复
相关推荐
JSP注释分类 <%--
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2006-02-28 08:14
社区公告
暂无公告