Bean编译后的class该放哪儿?数据库连接问题,急!解决给分

ahlazy 2002-05-12 12:17:37
我做了一个连接Acess数据库的Bean为DBconn,和数据库连接时,解决了其它问题后出现了找不到类DBconn的异常,请问写的Bean和编译后的Class该放哪里?我将JSP文件放在了webapps\ROOT目录下。用的是Apache Tomcat服务器。异常如下:

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

An error occurred at line: 9 in the jsp file: /cj.jsp

Generated servlet error:
D:\Apache Tomcat 4.0\work\localhost\_\cj$jsp.java:65: 找不到类 org.apache.jsp.DBconn。
DBconn DBconn1 = null;
^


An error occurred at line: 9 in the jsp file: /cj.jsp

Generated servlet error:
D:\Apache Tomcat 4.0\work\localhost\_\cj$jsp.java:68: 找不到类 org.apache.jsp.DBconn。
DBconn1= (DBconn)
^


An error occurred at line: 9 in the jsp file: /cj.jsp

Generated servlet error:
D:\Apache Tomcat 4.0\work\localhost\_\cj$jsp.java:73: 找不到类 org.apache.jsp.DBconn。
DBconn1 = (DBconn) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "DBconn");
^
3 个错误

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:284)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:546)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:189)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Thread.java:484)

...全文
25 点赞 收藏 13
写回复
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
ahlazy 2002-05-15
谢谢大家,我就放那里了。
给分!
回复
loes 2002-05-15
放在webapps\ROOT\WEB-INF\classes下.


回复
ephemeral 2002-05-15
还是放在那里吧。
回复
ephemeral 2002-05-13
放在webapps\ROOT\WEB-INF\classes\jsp\beans\下吧
回复
topmint 2002-05-13
bean文件夹放在webapps\ROOT\WEB-INF\classes\
工程文件放在webapps\ROOT\下任意目录
要注意要把
\mm.mysql.jdbc-1.2c.tar\mm.mysql.jdbc-1.2c\mysql_comp.jar;
\mm.mysql.jdbc-1.2c.tar\mm.mysql.jdbc-1.2c\mysql_uncomp.jar;
放到\lib下,重起tomcat


回复
ahlazy 2002-05-13
最后我把它放在examples\WEB-INF\classes\jsp\bean下,jsp文件放在examples\JSP\bean下,成功了;class放在root\web-inf\classes\bean下,
jsp文件放在root\bean下也成功了。
我还想请教各位,如果要建立一个自己的文件夹,如webapps\project,在server.xml中已经设好了这个目录的路径,要把jsp文件放这个目录下class文件怎么放?
分一定给大家。
回复
ahlazy 2002-05-12
cj.jsp如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312">
<title>班级成绩</title>
</head>
<body>
<p><b>班级成绩</b></p>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="DBconn1" scope="page" class="DBconn" />
<%
ResultSet RS=DBconn1.executeQuery("SELECT * FROM db1");
while(RS.next()){
out.print("<li>"+RS.getString("name")+"</li>");
out.print("<li>"+RS.getString("id")+"</li>");
out.print("<li>"+RS.getString("绩点")+"</li>");
}
RS.close();
%>
</body>
</html>
回复
ahlazy 2002-05-12
DBconn.java如下:
import java.sql.*;
public class DBconn {
String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String ConnStr = "jdbc:odbc:db1";
Connection conn = null;
ResultSet rs = null;
public DBconn (){
try {
Class.forName(DBDriver);
//加载数据库驱动程序
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("DBconn (): "+ e.getMessage());
}
}
public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(ConnStr);
//与DBMS建立链接
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}
回复
rigid_kid 2002-05-12
那就不是文件路径的问题了。
回复
ahlazy 2002-05-12
放在D:\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes下不行
同时放在放在webapps\ROOT\WEB-INF\classes下也不行
我原来就是放在放在webapps\ROOT\WEB-INF\classes下的
回复
Andrawu 2002-05-12
不知你放在什么地方了?
回复
rigid_kid 2002-05-12
放在 \tomcat\webapps\examples\WEB-INF\classes 目录下面,如果有package name;再classes下建 name文件夹,将你的class文件放入即可。
回复
Andrawu 2002-05-12
放在webapps\ROOT\WEB-INF\classes下.
try
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告