at com.csbook.documentsystem.UserMan.userExist(UserMan.java:70)这里指示你,在运行时,UserMan.java的第70行出现空指针异常,你对一个为空的对象调用了方法
要学会看异常信息

解决方案 »

  1.   

    UserMan的70行,有个变量,没有引用实例。代码贴出来。
      

  2.   

    package com.csbook.documentsystem;/**
     * <p>Title: </p>
     * <p>Description: </p>
     * <p>Copyright: Copyright (c) 2003</p>
     * <p>Company: </p>
     * @author not attributable
     * @version 1.0
     */import javax.naming.*;
    import javax.sql.*;
    import java.sql.*;
    import java.util.*;public class UserMan
    {
      Context ctx=null;
      DataSource ds=null;
      SysLog log=null;
    //构造函数
      public UserMan()
      {
        //从连接池中获取数据库连接
        try{
          ctx = new InitialContext();
          ds = (DataSource)ctx.lookup("documents");
        }
        catch(NamingException e){
          e.printStackTrace();
        }
        //建立一个日志类的实例
       log=new SysLog();
      }  //删除用户
      //operator为执行删除操作的人员,userId为要删除的用户ID
      public void removeUser(String operator,String userId){
        Connection con = null;
        PreparedStatement ps = null;
        try {
          String sqlupdate = "delete from users where id=?";
          con=ds.getConnection();
          ps=con.prepareStatement(sqlupdate);
          ps.setString(1,userId);
          ps.executeUpdate();
          log.addLog(operator,"remove user"+userId,"users");
        }
        catch(SQLException e){
        e.printStackTrace();
        }
        finally{
           if (ps != null)  try {ps.close();}
                   catch (SQLException ignore) {}
           if (con != null)   try {con.close();}
                   catch (SQLException ignore) {}
         }
      }  //检查指定的用户是否存在
      //userId为要检查的用户ID
      public boolean userExist(String userId){
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs=null;
        boolean occupied=true;
        try{
         String sqlquery="select * from users where id=?";
         con=ds.getConnection();
         ps=con.prepareStatement(sqlquery);
         ps.setString(1,userId);
         rs=ps.executeQuery();
         if(!rs.next())
             occupied=false;
         }
         catch(SQLException e){
          e.printStackTrace();
          }
          finally{
              if (rs != null)   try {rs.close();}
                   catch (SQLException ignore) {}
                if (ps != null)  try {ps.close();}
                   catch (SQLException ignore) {}
                if (con != null)   try {con.close();}
                   catch (SQLException ignore) {}
        }
        return occupied;
      }  //验证用户是否为合法用户
      //user为用户ID,pwd为登陆用户提交的密码
      public boolean isValidUser(String user,String pwd)
      {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs=null;
        boolean isValid=false;
        try{
         String sqlquery="select * from users where id=? and password=?";
         con=ds.getConnection();
         ps=con.prepareStatement(sqlquery);
         ps.setString(1,user);
         ps.setString(2,pwd);
         rs=ps.executeQuery();
         if(rs.next())
             isValid=true;
         }
         catch(SQLException e){
          e.printStackTrace();
          }
          finally{
              if (rs != null)   try {rs.close();}
                   catch (SQLException ignore) {}
                if (ps != null)  try {ps.close();}
                   catch (SQLException ignore) {}
                if (con != null)   try {con.close();}
                   catch (SQLException ignore) {}
        }
        return isValid;
      }  //添加用户
      //operator为执行添加的操作员,userId为添加的用户ID,pri指定所添加的用户的种类(1为管理员,0为普通用户)
      public void addUser(String operator,String userId, int pri){
        Connection con = null;
        PreparedStatement ps = null;
        try{
          String sqlInsert = "insert into users(id,privilege) values(?,?)";
          con=ds.getConnection();
          ps=con.prepareStatement(sqlInsert);
          ps.setString(1,userId);
          ps.setInt(2,pri);
          ps.executeUpdate();
          log.addLog(operator,"add user "+userId,"user");
         }
         catch(SQLException e){
          e.printStackTrace();
          }
        finally{
          if (ps != null)  try {ps.close();}
                   catch (SQLException ignore) {}
          if (con != null)   try {con.close();}
                   catch (SQLException ignore) {}
         }
        }    //获取用户的种类(特权级别)
        //user为指定的用户
        public int getUserPri(String user)
        {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs=null;
        int pri=0;
        try{
         String sqlquery="select privilege from users where id=?";
         con=ds.getConnection();
         ps=con.prepareStatement(sqlquery);
         ps.setString(1,user);
         rs=ps.executeQuery();
         if(rs.next())
             pri=rs.getInt("privilege");
         }
         catch(SQLException e){
          e.printStackTrace();
          }
        finally{
            if (rs != null)   try {rs.close();}
                   catch (SQLException ignore) {}
            if (ps != null)  try {ps.close();}
                   catch (SQLException ignore) {}
            if (con != null)   try {con.close();}
                   catch (SQLException ignore) {}
        }
        return pri;
        }    //检查用户是否为系统中某个档案库的管理员,如"是",返回true,否则,返回false
        //user为指定的用户
        public boolean isAdmin(String user)
        {
          Connection con = null;
          PreparedStatement ps = null;
          ResultSet rs=null;
          boolean admin=false;
          try{
          String sqlQuery="select * from docBase where admin=?";
          con=ds.getConnection();
          ps=con.prepareStatement(sqlQuery);
          ps.setString(1,user);
          rs=ps.executeQuery();
          if(rs.next())
                  admin=true;
          }
          catch(SQLException e){
          e.printStackTrace();
          }
          finally{
              if (rs != null)   try {rs.close();}
                    catch (SQLException ignore) {}
              if (ps != null)  try {ps.close();}
                    catch (SQLException ignore) {}
              if (con != null)   try {con.close();}
                    catch (SQLException ignore) {}
         }
         return admin;
        }    //获取系统中所有用户的列表
        public Vector getUserList()
        {
          Connection con = null;
          PreparedStatement ps = null;
          ResultSet rs=null;
          Vector users=new Vector();
          try{
          String sqlQuery="select id from users";
          con=ds.getConnection();
          ps=con.prepareStatement(sqlQuery);
          rs=ps.executeQuery();
          while(rs.next())
                  users.add(rs.getString("id"));
          }
          catch(SQLException e){
          e.printStackTrace();
          }
          finally{
              if (rs != null)   try {rs.close();}
                     catch (SQLException ignore) {}
              if (ps != null)  try {ps.close();}
                     catch (SQLException ignore) {}
              if (con != null)   try {con.close();}
                     catch (SQLException ignore) {}     }
         return users;
        }   //获取系统中所有用户的详细信息,供用户管理界面(userMan.jsp)使用
        public Vector getUserInfo()
        {
          Connection con = null;
          PreparedStatement ps = null;
          ResultSet rs=null;
          Vector users=new Vector();
          try{
          String sqlQuery="select * from users";
          con=ds.getConnection();
          ps=con.prepareStatement(sqlQuery);
          rs=ps.executeQuery();
          String temp="";
          while(rs.next()){
                  temp=rs.getString("id")+" "+rs.getString("privilege");
                  users.add(temp);
                }
          }
          catch(SQLException e){
          e.printStackTrace();
          }
          finally{
              if (rs != null)   try {rs.close();}
                    catch (SQLException ignore) {}
              if (ps != null)  try {ps.close();}
                    catch (SQLException ignore) {}
              if (con != null)   try {con.close();}
                    catch (SQLException ignore) {}
         }
         return users;
        }
    }
      

  3.   

    问题好象出在这段
    public boolean isValidUser(String user,String pwd)
      {
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs=null;
        boolean isValid=false;
        try{
         String sqlquery="select * from users where id=? and password=?";
         con=ds.getConnection();
         ps=con.prepareStatement(sqlquery);
         ps.setString(1,user);
         ps.setString(2,pwd);
         rs=ps.executeQuery();
         if(rs.next())
             isValid=true;
         }