shunfengfan 2010-04-20 20:19
浏览 355
已采纳

Jsp+JavaBean+MySql实现登陆及增删改查出错。The value for the useBean class attribute bean.Sql

Jsp+JavaBean+MySql实现登陆及增删改查出错。The value for the useBean class attribute bean.SqlConn is invalid.

运行环境:Tomcat6.0+jdk1.6+MyEclipse6.0

报错信息:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /ADMS/WebRoot/add.jsp(2,0) The value for the useBean class attribute bean.SqlConn is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1200)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1155)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2386)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2392)
org.apache.jasper.compiler.Node$Root.accept(Node.java:489)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2336)
org.apache.jasper.compiler.Generator.generate(Generator.java:3394)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:210)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)
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.

我的代码
1.SqlConn.java

package bean;
import java.sql.*;

public class SqlConn {
private String url = "jdbc:mysql://localhost:3036/adms";
private String user = "root";
private String password = "root";

private Connection conn = null;
private Statement stmt = null;
private ResultSet rs = null;

public SqlConn(){
    try{
        Class.forName("com.mysql.jdbc.Driver");
        }
    catch(java.lang.ClassNotFoundException e){
        System.err.println("SqlConn():"+e.getMessage());
    }
}

public ResultSet executeQuery(String sql){
    try{
        conn = DriverManager.getConnection(url,user,password);
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
        rs = stmt.executeQuery(sql);
    }catch(SQLException ex){
        System.err.println("SqlConn.executeQuery:"+ex.getMessage());

    }
    return rs;
}
public void executeUpdate(String sql){
    try{
        conn = DriverManager.getConnection(url,user,password);
        stmt = conn.createStatement();
        stmt.executeUpdate(sql);
        stmt.close();
        conn.close();
    }catch(SQLException ex){
        System.err.println("SqlConn.executeUpdate:"+ex.getMessage());
    }
}

public void closeStmt(){
    try{
        stmt.close();
    }catch(SQLException e){
        e.printStackTrace();
    }
}

public void closeConn(){
    try{
        conn.close();
    }catch(SQLException e){
        e.printStackTrace();
    }
}
public static void main(String[] args) {
    // TODO Auto-generated method stub

}

}
2.login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%--使用SqlConn.class--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


My JSP 'login.jsp' starting page
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->





















用户名
密码

用户
   
管理员
 
  



3.loginto.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


My JSP 'loginto.jsp' starting page
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->



<%
String username = request.getParameter("username").trim();
String password = request.getParameter("password").trim();
String role = request.getParameter("role").trim();
try{
if(role.equals("0"))
{
String sql = "select * from admin where admin_id='"+username+"'and admin_psw='"+password+"'";
ResultSet rs = sqlbean.executeQuery(sql);
if(rs.next())
response.sendRedirect("adms.jsp");
else
out.println("错误的用户名或密码!");
}
else if(role.equals("1"))
{
String sql = "select * from user where user_id='"+username+"'and user_psw='"+password+"'";
ResultSet rs = sqlbean.executeQuery(sql);
if(rs.next())
out.println("您好,"+username);
else
out.println("错误的用户名或密码!");
}
}catch(Exception ee){
ee.printStackTrace();
}
%>


还有添加,删除,修改,查找等jsp页面。
我用JSP页面直接连接就能运行,没有错。只要是有JavaBean,就会报错。希望大家多多指教。
这个问题出现好久了,不仅这一个项目有这样的问题,所有的导入和新建的web project 只要有JavaBean都会有这样的错误。
搞不清是什么原因。数据库是SQLServer2000的时候也是这样的错误。
  • 写回答

3条回答 默认 最新

  • llyzq 2010-04-22 19:50
    关注

    我用你的源文件部署了,没有问题

    我在SqlConn的构造函数里加了
    System.out.println("sqlconn~~~");
    日志能看到结果

    检查一下你的TOMCAT的\webapps\ADMS\WEB-INF\classes\bean
    目录下有没有SqlConn.class

    应该是你的应用部署有问题

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 射频功率问题,解答者有酬谢!
  • ¥80 构建降雨和积水的预测模型
  • ¥15 #Qt Transform setTransform()在鼠标拖动移动视角是一致在原地不动,无法变换视角(细微观察似乎视图有在原地抖动),无法变换视角(细微观察似乎视图有在原地抖动)
  • ¥50 如何利用无人机拍摄的数码照片测量鸟卵的长短径
  • ¥100 github贡献者给与奖励
  • ¥15 使用DS18B20+ESP8266获取温度数据返回-127.00
  • ¥15 odbc代码新增sqlserver数据源
  • ¥15 求一个USB指纹识别的驱动
  • ¥15 wps中工作表与工作表之间怎么汇总信息?
  • ¥50 请教Windows server 2012 R2的DCOM配置问题