java.lang.ClassCastException: Bll.EquipmentBll cannot be cast to Modul.Equ 
这行显示你EquipmentBll的类型跟Equ的类型之间不能做类型转换。你看一下你那两个东西是怎么定义的

解决方案 »

  1.   

    package Bll;
    import util.DataBase;
    import java.sql.*;
    public class EquipmentBll {
    public EquipmentBll()
    {

    }
    public ResultSet Query(String strWhere)
    {
     java.sql.ResultSet rt = null;
     try
    {
      DataBase db = new DataBase();
      String strSql = "  select * from Equipment  a left join js_Dept b on a.xsid=b.D_ID where a.Flag=1 ";
      if(strWhere!=null&&strWhere!="")
      {
        strSql = strSql+strWhere;
      }
      rt = db.Query(strSql);
    }
    catch(Exception ee )
    {
    System.out.println("connect db error:"+ee.getMessage());
    return null;
    }
       return rt;     
    }

    public boolean InsertEqu(Modul.Equ Equ)
    {
    try
    {
     DataBase db = new DataBase();
    String strSql="insert into Equipment(EquName,Place,House,Port,Factory,EmpName,xsid,Flag)values( "+
                 " '"+Equ.getEquName()+"','"+Equ.getPlace()+"','"+Equ.getHouse()+"',"+Equ.getPort()+",'"+Equ.getFactory()+"' "+
                 ",'"+Equ.getEmpName()+"','"+Equ.getxsid()+"','1')";
    db.execute(strSql);
    }
    catch(Exception ee )
    {
    System.out.println("connect db error:"+ee.getMessage());
    return false;
    }
    return true;
    }  


    public boolean UpdateEqu(Modul.Equ Equ,String strID)
    {
    try
    {
     DataBase db = new DataBase();
    String strSql="Update Equipment set EquName='"+Equ.getEquName()+"',Place='"+Equ.getPlace()+"',House='"+Equ.getHouse()+"',"+
                  "Port="+Equ.getPort()+",Factory='"+Equ.getFactory()+"',EmpName='"+Equ.getEmpName()+"',"+
                  "xsid='"+Equ.getxsid()+"', where EquID='"+strID+"'"; db.execute(strSql);

    }
    catch(Exception ee )
    {
    System.out.println("connect db error:"+ee.getMessage());
    return false;
    }
    return true;



    public boolean DeleteEqu(String strID)
    {
    try
    {
     DataBase db = new DataBase();
     String strSql=" update Equipment set Flag=0 where EquID in ("+strID+")";
         db.execute(strSql);
    }
    catch(Exception ee )
    {
    System.out.println("connect db error:"+ee.getMessage());
    return false;
    }
    return true;


    }
    package Modul;public class Equ {
        private String EquName;
        private String Place;
        private String House;
        private String Port;
        private String Factory;
        private String EmpName;
        private String CreateDate;
        private String xsid;
            public Equ()
        {
        
        }
        
        public void setEquName(String strEquName)
        {
          this.EquName = strEquName;
        }
        public String getEquName()
        {
         return this.EquName;
        }
        
        public void setPlace(String strPlace)
        {
          this.Place = strPlace;
        }
        public String getPlace()
        {
         return this.Place;
        }
        
        public void setHouse(String strHouse)
        {
          this.House = strHouse;
        }
        public String getHouse()
        {
         return this.House;
        }
        
        public void setPort(String strPort)
        {
          this.Port = strPort;
        }
        public String getPort()
        {
         return this.Port;
        }
        
        public void setFactory(String strFactory)
        {
          this.Factory = strFactory;
        }
        public String getFactory()
        {
         return this.Factory;
        }
        
        public void setEmpName(String strEmpName)
        {
          this.EmpName = strEmpName;
        }
        public String getEmpName()
        {
         return this.EmpName;
        }
        
        public void setCreateDate(String strCreateDate)
        {
          this.CreateDate = strCreateDate;
        }
        public String getCreateDate()
        {
         return this.CreateDate;
        }
        
        public void setxsid(String strxsid)
        {
         this.xsid = strxsid;
        }
        public String getxsid()
        {
         return this.xsid;
        }
    }
    就是这两个类我没有对他们做类型转换。。只是在Bll类中用到了Equ类。。
      

  2.   

    <%@page pageEncoding="GB2312"%> 
    <%@page contentType="text/html; charset=gb2312"%> 
    <%request.setCharacterEncoding("GB2312");%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>Insert title here</title>
    </head>
    <body>
      <jsp:useBean id="Equ"  scope="application" class="Modul.Equ"/>
        <jsp:useBean id="Equipment"  scope="application" class="Bll.EquipmentBll"/> <% Equ.setEquName(request.getParameter("strEquname"));
     Equ.setPlace(request.getParameter("strPlace"));
     Equ.setHouse(request.getParameter("strHouse"));
     Equ.setPort(request.getParameter("strPort"));
     Equ.setFactory(request.getParameter("strFactory"));
     Equ.setEmpName(request.getParameter("strEmpName"));
     Equ.setCreateDate(request.getParameter("strCreateDate"));
     Equ.setxsid(request.getParameter("select"));
    if(Integer.parseInt(request.getParameter("Op"))==2) //修改
      { 
        if(Equipment.UpdateEqu(Equ,request.getParameter("ID")))
        {
                out.print("<script>");
                 out.print("alert('修改成功!');");
                 out.print("history.back();");
                 out.print("</script>");  
        }
        else
        {
                   out.print("<script>");
                 out.print("alert('修改失败!');");
                 out.print("history.back();");
                 out.print("</script>"); 
        }
      }
      else
      {
        if(Equipment.InsertEqu(Equ))
        {
                     out.print("<script>");
                 out.print("alert('保存成功!');");
                 out.print("history.back();");
                 out.print("</script>");  
        }
        else
        {
                 out.print("<script>");
                 out.print("alert('保存失败!');");
                 out.print("history.back();");
                 out.print("</script>"); 
        }
      } %>
    </body>
    </html>这个就是报错的jsp页面。
      

  3.   

     <jsp:useBean id="Equipment"  scope="application" class="Bll.EquipmentBll"/>  
    这两个怎么能转换呢?
      

  4.   

    那应该怎么写????id不是只是一个名字而已吗?对不起,我以前是做.net的。。刚自学写jsp...里面都有很多.net的痕迹。
      

  5.   

    <jsp:useBean id="EquipmentBll"  scope="application" class="Bll.EquipmentBll"/>    我改成这样了。。依然报上面的错误。。
      

  6.   

    去掉<jsp:useBean id="Equipment"  scope="application" class="Bll.EquipmentBll"/>
      

  7.   

    Equipment。是我要用到的方法,怎么能去掉。。去掉它也报错。去掉Equ不报错还有谁帮我看一下问题没有。。