调试一个jsp+javabean+sql的代码
出现以下异常
exception org.apache.jasper.JasperException: Unable to compile class for JSP: 
An error occurred at line: 19 in the jsp file: /School/admin/intro.jsp
Conn cannot be resolved to a type
16:       <td width="66" bgcolor="#943839"><span class="white">删除</span></td>
17:     </tr>
18: <% 
19:  Conn con=new Conn();
20:  ResultSet rs=con.getRs("SELECT * FROM tb_intro");
21:  boolean flag=false;
22:  while(rs.next()){
An error occurred at line: 19 in the jsp file: /School/admin/intro.jsp
Conn cannot be resolved to a type
16:       <td width="66" bgcolor="#943839"><span class="white">删除</span></td>
17:     </tr>
18: <% 
19:  Conn con=new Conn();
20:  ResultSet rs=con.getRs("SELECT * FROM tb_intro");
21:  boolean flag=false;
22:  while(rs.next()){
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.jsp代码如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%>
<%@ page import="com.bwm.db.Conn"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../css/style.css" rel="stylesheet">
</head>
<body>
<br>
<table width="600" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#ffffff" bordercolordark="#943839" bordercolorlight="#FFFFFF" >
    <tr align="center" bgcolor="#6699FF" class="shadow">
      <td width="159" height="27" bgcolor="#943839"><a href="addintro.jsp" class="style1">添加专业名称</a></td>
      <td width="108" bgcolor="#943839"><span class="shadow">学年制</span></td>
      <td width="106" bgcolor="#943839"><span class="white">费用</span></td>
      <td width="149" bgcolor="#943839"><span class="white">专业介绍</span></td>
      <td width="66" bgcolor="#943839"><span class="white">删除</span></td>
    </tr>
<% 
Conn con=new Conn();
ResultSet rs=con.getRs("SELECT * FROM tb_intro");
boolean flag=false;
while(rs.next()){
flag=true;
String Specialth=rs.getString(1);
%>
    <tr align="center">
      <td width="159" height="22" align="center"><%=Specialth%></a></td>
      <td width="108" height="22" align="center"><%=rs.getInt(2)%></td>
      <td width="106" align="center"><%=rs.getFloat(3)%></td>
      <td align="center"><%=rs.getString(4)%></td>
      <td width="66" align="center"><a href="delintro.jsp?Specialth=<%=Specialth%>">删除</a></td>
    </tr>
<%
}
con.close();
if(!flag){
%>
    <tr align="center">
      <td height="22" colspan="5">没有添加专业名称</td>
    </tr>
<%
}
%>
</table>
</body>
</html>数据库操作的javabean如下:
/*
 * Created on 2004-9-18
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package com.bwm.db;import java.sql.*;/**
 *class explain:Database connection<br>
 *set up name: crazyadept<br>
 *set up time: 11/22/2004
 */
public class Conn {
private static Connection con;
private Statement  stmt;
private ResultSet  rs;
private PreparedStatement pstmt;
private static int CON_COUNT=0; /**
     *method explain: Auto Connection DataBase<br>
 *set up name: crazyadept<br>
 *change time: 12/20/2004
 */
public static synchronized Connection getCon()throws Exception{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:School","","");
CON_COUNT++;
return con;
}catch(SQLException e){
System.err.println(e.getMessage());
throw e;
}
} /**
 *return value: in order select in SQL<br>
 *set up name: crazyadept<br>
 *change time: 12/20/2004
 */
public Statement getStmtread(){
try{
con=getCon();
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
return stmt;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
} /**
 *return value: Data<br>
 *parameter: SQL select sentence<br>
 *set up name: crazyadept<br>
 *change time: 11/29/2004
 */
public ResultSet getRs(String sql){
try{
stmt=getStmtread();
rs=stmt.executeQuery(sql);
return rs;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
} /**
 *return value: not in order select in str SQL<br>
 *set up name: crazyadept<br>
 *set up time: 11/29/2004<br>
 *change time: 11/29/2004
 */
public Statement getStmt(){
try{
con=getCon();
stmt=con.createStatement();
return stmt;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
} /**
 *return value: Connection count<br>
 *set up name: crazyadept<br>
 *change time: 12/01/2004
 */
public int getConcount(){
return CON_COUNT;
} /**
 *return value: DataBase pretreatment sentense<br>
 *parameter: like as SQL sentence<br>
 *set up name: crazyadept<br>
 *set up time: 11/29/2004<br>
 *change time: 11/29/2004
 */
public PreparedStatement getPstmt(String sql){
try{
con=getCon();
pstmt=con.prepareStatement(sql);
return pstmt;
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
return null;
} /**
 *method explain: Close DataBase Connection<br>
 *set up name: crazyadept<br>
 *set up time: 11/29/2004<br>
 *change time: 11/29/2004
 */
public synchronized void close(){
try{
if(rs!=null){
rs.close(); rs=null;
}
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
try{
if(stmt!=null){
stmt.close(); stmt=null;
}
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
try{
if(con!=null){
con.close(); con=null; CON_COUNT--;
}
}catch(Exception e){
System.err.println(e.getMessage());
e.printStackTrace();
}
}
}
希望哪位大哥大姐帮帮忙,指点以下小弟。。

解决方案 »

  1.   

    19: Conn con=new Conn(); 
    问题处在这里,改成
    19: 你的包名.Conn con=new 你的包名.Conn(); 
      

  2.   

    我改过后发现出了这样的错误
    org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP
      

  3.   

    莫名其妙我重启Tomcat后变成了The value for the useBean class attribute com.bwm.db.Conn.class is invalid.不知道怎么回事?
      

  4.   

    Conn cannot be resolved to a type 
    从这个信息可以看出在编译的时候没有找到此类的包,所以在你的JSP页面中只要导入Conn类的包就能解决这个问题.