是一个非常简单的查询、删除、和修改的ejb例子,在ejb组件中有4个类文件:UserHome.class(Home interface) User.class (Remote interface) UserEJB.class(Bean class)还有一个LoginPassword.class(验证口令用的)
在web组件中有1个class文件2个html文件和6个jsp文件,都写出来太多了,我想知道,这个异常可能是有什么原因引起的,可能会在什么文件中出错,我感觉是jsp文件,但jsp文件找不到什么毛病?
下面是我的web组件中的class文件
package user.javabean;
import user.ejb.*;
import java.util.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.ejb.*;
import java.sql.*;
import javax.sql.*;public class UserData{
   private String id=null;
   private String password=null;
   private String name=null;
   UserHome userhome=null;
  
   public UserData() throws SQLException{
    try{     Context initial=new InitialContext();
     Object objref=initial.lookup("ejb/UserEJB");    userhome=(UserHome)PortableRemoteObject.narrow(objref, UserHome.class);
    }catch(Exception ex){
       throw new SQLException(ex.toString());
       }
    }
   public void updateUser() throws SQLException{
     try{
         User user=userhome.findByPrimaryKey(id);
         user.setUserData(name,password);
        }catch(Exception ex){
          throw new SQLException("更改失败!");
          }
      }
   public void insertUser() throws SQLException{
      try{
          User user=userhome.create(id,name);
          password=user.getPassword();
          }catch(DuplicateKeyException dupkeyex){
            throw new SQLException("id:"+id+"已经存在");
          }catch(CreateException ex){
            throw new SQLException("id:"+id+"添加失败");
          }catch(Exception ex){
          }
      }
    public void deleteUser() throws SQLException{
       try{
          User user=userhome.findByPrimaryKey(id);
          user.remove();
          }catch(Exception ex){
            throw new SQLException("删除失败!");
            }
        }
    public boolean isMember() throws Exception{
       try{
          User user=userhome.findByPrimaryKey(id);
             if(user.getPassword().equals(password)){
              name=user.getName();
              return true;
              }
           }catch(ObjectNotFoundException notfoundex){
              return false;
           }catch(Exception ex){
              throw ex;
           }
              return false;
           }
    public void setId(String id){
         this.id=id;
         }
    public String getId(){
        return id;
        }
    public void setPassword(String password){
        this.password=password;
        }
    public String getPassword(){
        return password;
        }
    public void setName(String name){
        this.name=name;
         }
    public String getName(){
         return name;
         }
}
 

解决方案 »

  1.   

    这个BEAN没问题,可能出现在JSP页中,把JSP页贴出来看看!
      

  2.   

    登录
    login.jsp:<%@ page 
    language="java" errorPage="userErr.jsp"
    import="java.sql.*,
            user.javabean.*"
    contentType="text/html; charset=GB2312" %><jsp:useBean id="userTbl" scope="page" class="user.javabean.UserData">
    <jsp:setProperty name="userTbl" property="id" param="id"/>
    <jsp:setProperty name="userTbl" property="password" param="password"/>
    </jsp:useBean>
    <% if(!userTbl.isMember()) throw new Exception("你不是会员!");
    %>
    <html>
    <head></head>
    <body bgcolor=#cccccc>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <div align=center>
    <b><font size=7>欢迎光临!</font></b></div>
    </body>
    </html>查询
    query.jsp:<%@ page language="java" errorPage="userErr.jsp" import="java.sql.*, user.javabean.*" contentType="text/html,charset=GB2312"%>
    <jsp:useBean id="userTbl" scope="page" class="user.javabean.UserData">
    <jsp:setProperty name="userTbl" property="id" param="id"/>
    <jsp:setProperty name="userTbl" property="password" param="password"/>
    </jsp:useBean>
    <%if(!userTbl.isMember()) throw new Exception("你不是会员!");
    %>
    <html>
    <head></head>
    <body bgcolor=#cccccc>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <div align=center>
    <p><b>
    <font size=7>查询会员资料</font></b></p>
    <form name=querForm action=update.jsp>
    <p><font size=4>账号:<%=userTbl.getId()%><input type="hidden" name="id" value='<%=userTbl.getId()%>'>
    名字:<input type=text name=name maxlength=8 value='<%=userTbl.getName()%>'>
    密码:<input type=text name=password maxlength=8 value='<%=userTbl.getPassword()%>'>
    </font></p>
    <p>
    <input type=submit name=Submit value="更改">
    <a href=index.html>回首页</a></p>
    </form>
    <p>&nbsp;</p>
    </div>
    </body>
    </html>