首页 > The value for the useBean class attribute *** is invalid.

The value for the useBean class attribute *** is invalid.

tomcat报错如下:
HTTP Status 500 - /WebRoot/news.jsp (line: 9, column: 0) The value for the useBean class attribute dao.UserDAO is invalid.

type Exception report

message /WebRoot/news.jsp (line: 9, column: 0) The value for the useBean class attribute dao.UserDAO is invalid.

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


news.jsp的代码为:

<%@ page language="java" import="java.util.*" pageEncoding="utf-8" session="True"%>
<%@ page import="java.sql.*" %>
<%@ page import="dao.UserDAO" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<jsp:useBean id="mybean" class="dao.UserDAO"></jsp:useBean>
<jsp:setProperty name="user" property="*"></jsp:setProperty>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <base href="<%=basePath%>">  
    <title>新闻</title>
    <link href="<%=request.getContextPath()%>/WebRoot/css/news.css" type="text/css" rel="stylesheet"/>
  </head>
  <body>
  </body>
</html>

UserDAO.java的代码为:

package dao;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.Statement;

import com.mysql.jdbc.PreparedStatement;

public class UserDAO {

    Connection con = null;
    Statement stat = null;
    PreparedStatement pstat = null;
    ResultSet rs = null;

    public UserDAO() {}
    //取得数据连接
    public Connection GetConn() {
        try{
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            String url = "jdbc:mysql://localhost:3306/spassage";
            con = DriverManager.getConnection(url,"root","to123day");
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return con;
    }

    //执行数据库查询并返回查询结果
    public ResultSet query(String sql){
        try{
            con = GetConn();
            stat = con.createStatement();
            rs = stat.executeQuery(sql);
        }catch(Exception ex){
            ex.printStackTrace();
        }
        return rs;
    }

    //关闭数据库连接
    public void close(){
        try{
            if (rs != null)rs.close();
            if (stat != null)stat.close();
            if (pstat != null)pstat.close();
            if (rs != null)rs.close();          
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
}

D:\apache-tomcat-8.0.24\webapps\tsnews\WebRoot\WEB-INF\classes\dao目录下UserDAO.class已经存在
哪里出问题了?


找到原因了,因为com.mysql.jdbc.PreparedStatement的包没有放在WEB-INF\lib下,运行的时候没有正确导入,导致dao.UserDAO无效。

【热门文章】
【热门文章】