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

jsp连接Bean出错,该如何处理

2011-12-31 
jsp连接Bean出错org.apache.jasper.JasperException:/login/login_confirm.jsp(10,0)ThevaluefortheuseBea

jsp连接Bean出错
org.apache.jasper.JasperException:   /login/login_confirm.jsp(10,0)   The   value   for   the   useBean   class   attribute   DB   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)

拜托,帮忙解决下赖!
Bean的程序:package   DB;
import   java.sql.*;
public   class   DB
{
String   sDBDriver= "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String   sConnStr= "jdbc.microsoft.sqlserver ";
public   Connection   conn=null;
public   Statement   stmt;
        ResultSet   rs=null;
        String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Mythesis ";
String   user= "sa ";
String   password= "123 ";
             
  public   DB(){
  try{
  Class.forName(sDBDriver).newInstance();
  }
  catch(Exception   e){
  e.printStackTrace();
 
  }
 
  }  

 
public     ResultSet   executeQuery(String   sql)  
{
rs=null;

try{
 
  conn=DriverManager.getConnection(url,user,password);
  stmt=conn.createStatement();
  rs=stmt.executeQuery(sql);      
         
  }
 
          }

}
catch(SQLException   ex)
{
    System.out.print( "aq.executeQuery: "+e.getMessage());
         
}
return   rs;
}
public     void   executeupdate(String   sql)  
{
stmt=null;
rs=null;

try{
 
  conn=DriverManager.getConnection(url,user,password);
  stmt=conn.createStatement();
  stmt.executeQuery(sql);
  stmt.close();
  conn.close();  
}
catch(SQLException   ex)
{
    System.out.print( "aq.executeQuery: "+e.getMessage());
         


}

}

  public     void   closeStmt()   {
try{
stmt.close();
}
catch(SQLException   e){
e.printStackTrace();
}
       
  }
  public     void   closeConn()   {
try{
conn.close();
}
catch(SQLException   e){
e.printStackTrace();
}
       
  }
       
 
}
 
调用的程序:
<%@   page   contentType= "text/html;charset=gb2312 "%>
<%@   page   import= "DB.DB "%>

<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html ";charset=gb2312 ">
<title> 登录验证 </title>  
</head>
<body>
<jsp:useBean   id= "LoginBean "   scope= "page "   class= "DB ">
</jsp:useBean>
<%
String   mesg= " ";    

 
String   name1=new   String(request.getParameter( "user_name ").getBytes( "8859_1 "));
String   pwd1=new   String(request.getParameter( "password ").getBytes( "8859_1 "));
                LoginBean.setUsername(name1);
                Loginbean.setPassword(pwd1);
                out.print(name1+pwd1);

              if(LoginBean.execute()){
                  session.setAttribute( "username ",user_name);
                  session.setAttribute( "password ",pwd1);
                %>
<script   language=javascript>
    window.location "index_ok.jsp?mark=成功登录 "
</script>
<%}
else{
String   msg= "用户名或密码有误! ";
                               
%>
<jsp:forward   page= "relogin.jsp "/>
<%}%>
   
</body>
</html>

                                       




[解决办法]
javabean必须加包名。
[解决办法]
<jsp:useBean id= "LoginBean " scope= "page " class= "DB.DB ">
[解决办法]
楼上是正解,没加BEAN的包名
[解决办法]
二楼是没错的,
lz先检查下classes目录下是否存在该编译好的文件

热点排行