我做了个jsp连接数据库的例子来测试我的tomcat服务器,用了javabean,但抛出了异常,错误如下:
希望大虾指教,谢谢哦。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
type Exception reportmessagedescription The server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a typeAn error occurred at line: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a typeAn 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方式却可以正常访问,也可以调用数据库。不管怎样,谢谢阅读。
希望大虾指教,谢谢哦。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
type Exception reportmessagedescription The server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a typeAn error occurred at line: 2 in the jsp file: /index.jsp
Generated servlet error:
Driver.jdbc cannot be resolved or is not a typeAn 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方式却可以正常访问,也可以调用数据库。不管怎样,谢谢阅读。
解决方案 »
- JSF+PrimeFaces跳转后不显示页面内容
- 大家帮我找一下关于JNDI连接的例子 详细点的
- 批处理问题!~大虾们帮帮忙!~
- javabean中的scope=application?
- 自由软件与开源软件
- 请大神讲讲现在流行缓存的技术是怎样实现的呢,谢谢!
- 哪位兄台救我啊!杀千刀的汉字转码?
- 关于一个日文显示的问题
- 找不到文件count.txt 该文件在本jsp文件目录中
- 我想用jsp做个发送邮件的程序,请问需要什么服务器?怎样配置?最好还能提供一个简单的测试程序!谢谢!
- 谁有POI传给我,急用!收到马上给分!谢谢!E-mail:[email protected]
- 急~!多谢大侠~!TOMCAT中配置JNDI
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();
//} }
Driver.jdbc cannot be resolved or is not a type
Driver.jdbc是不能识别的符号或不是对应的类型
第一:包和bean的名字最好用小写;
第二:在jsp中写对路径。