首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

eclipse 使用 javabean 出错,该如何处理

2012-01-26 
eclipse 使用 javabean 出错我自己在做一个新闻发布系统,不太会用eclipse错误信息为:/WebRoot/index.jsp(3

eclipse 使用 javabean 出错
我自己在做一个新闻发布系统,不太会用eclipse
错误信息为:
/WebRoot/index.jsp(3,0)   The   value   for   the   useBean   class   attribute   com.DBcon   is   invalid.
我的index页面为:
<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "     errorPage= " "%>
<%@   page   import= "java.sql.* "%>
<jsp:useBean   id= "db "   class= "com.DBcon "/>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN ">
<html>
    <head>
       
        <title> 新闻发布 </title>
       
<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 ">

    </head>
   
    <body>
        <table   align= "center "   bgcolor= "#ffff80 ">
        <tr>
        <td> 新闻标题
        </td>
        <td> 发布人
        </td>
        <td> 发布时间
        </td>
        <td>
        </td>
        </tr>
  <%
  String   sql= "select   *   from   newspub ";
  ResultSet   rs=db.executeQuery(sql);
  %>
  <%
  String   title=rs.getString( "newsTitle ");
  String   content=rs.getString( "newsContent ");
    %>
<tr>
        <td>
        <%=title%>
        </td>
        <td>
        <%=content%>
        </tr>
        </table>
        <%db.closeCon();%>
    </body>
</html>
我的bean是:
package   com;

import   java.sql.*;

public   class   DBcon   {
String   Dbdriver   =   "com.microsoft.jdbc.sqlserver.SQLServerDriver ";

String   strcon   =   "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=newspub ";

Connection   con   =   null;

Statement   stmt   =   null;

ResultSet   rs   =   null;

String   user   =   "sa ";

String   password   =   " ";

public   DBcon()   {
try   {
Class.forName(Dbdriver);
}   catch   (ClassNotFoundException   e)   {


//   TODO   Auto-generated   catch   block
e.printStackTrace();
}

}

public   ResultSet   executeQuery(String   strSQL)   {
try   {
con   =   DriverManager.getConnection(strcon,   user,   password);
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}
try   {

Statement   stmt   =   con.createStatement();
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}
try   {
rs   =   stmt.executeQuery(strSQL);
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}
return   rs;
}

public   void   executeUpdate(String   strSQL)   {
try   {
con   =   DriverManager.getConnection(strcon,   user,   password);
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}
try   {
stmt   =   con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}
try   {
stmt.executeUpdate(strSQL);
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}

}

public   void   closeCon()   {
if   (con   !=   null)   {
try   {
con.close();
}   catch   (SQLException   e)   {
//   TODO   Auto-generated   catch   block
e.printStackTrace();
}
}
}
}
大哥们快快帮忙   啊!!!

[解决办法]
错误为com.DBcon类未找到
确保该类已经编译成功并放在classpath下
路径为com.DBcon
如果为编译成功查看构建路径,看看里面有没有问题
[解决办法]
<jsp:useBean id= "db " class= "com.DBcon "/>

当你敲 "com. "的时候看有没有智能提示DBCon, 如果没有那肯定找不到拉

如果找到了也出现上述错误的话,那就是RP问题了

[解决办法]
我也正在做这个论文

[解决办法]
在DBcon这个类里有db这个属性吗?

热点排行