to xqw2:最后一个字段不空,谢谢关注。
to Koham:jdbc的resultset中返回的记录是从1开始的,不懂不要瞎说。

解决方案 »

  1.   

    最后一个字段是varchar或者varchar2类型吗?先看一看类型是否匹配!
      

  2.   

    package bishe;import java.io.*;
    import java.sql.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    /**
     * 此处插入类型描述。
     * 创建日期:(2002-5-20 11:43:10)
     * @author:Administrator
     */
    public class LoginServlet extends HttpServlet {
    /**
     * Process incoming HTTP GET requests 
     * 
     * @param request Object that encapsulates the request to the servlet 
     * @param response Object that encapsulates the response from the servlet
     */
     
     Hashtable user=new Hashtable();
     Hashtable feature=new Hashtable();
     Hashtable level=new Hashtable();
     String userpass=new String();
     
    /**
     * 此处插入方法描述。
     * 创建日期:(2002-5-20 12:18:09)
     * @return boolean
     * @param auth java.lang.String
     * @exception java.io.IOException 异常说明。
     */
    protected boolean allowUser(String auth) throws java.io.IOException {
        if (auth == null)
            return false;
        if (!auth.toUpperCase().startsWith("BASIC"))
            return false;
        String userpassEncoded = auth.substring(6);
        sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
        String userpassDecoded = new String(dec.decodeBuffer(userpassEncoded));
        if ("allowed"==(user.get(userpassDecoded))){
        userpass=userpassDecoded;
            return true;
        }
        else
            return false;}
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { performTask(request, response);}
    /**
     * Process incoming HTTP POST requests 
     * 
     * @param request Object that encapsulates the request to the servlet 
     * @param response Object that encapsulates the response from the servlet
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { performTask(request, response);}
    /**
     * Initializes the servlet.
     */
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        // insert code to initialize the servlet here
        
    }
    /**
     * Process incoming requests for information
     * 
     * @param request Object that encapsulates the request to the servlet 
     * @param response Object that encapsulates the response from the servlet
     */
    public void performTask(
        HttpServletRequest request,
        HttpServletResponse response) {
        // Insert user code from here.
        try {        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String url = "jdbc:odbc:lif-bishe";
            Connection con = DriverManager.getConnection(url);
            Statement stmt = con.createStatement();
            String sql = "select * from customer";
            ResultSet rs = stmt.executeQuery(sql);
            String userfeature = "unknown";
            String userlevel = "unknown";
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            while (rs.next()) {
                String userid = rs.getString(1);
                String password = rs.getString(2);
                userfeature = rs.getString(3);
                userlevel =rs.getString(4);
                user.put(userid + ":" + password, "allowed");
                feature.put(userid + ":" + password, userfeature);
                level.put(userid + ":" + password, userlevel);
                out.println(userid); 
                out.println(userfeature);
                out.println(password);
                out.println(userlevel);
            }
            //out.println(userlevel);
            String auth = request.getHeader("Authorization");
            if (!allowUser(auth)) {
                response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
                response.setHeader("WWW-Authenticate", "BASIC realm=\"user\"");
                out.println("您按了取消键,请重新登录!");
            } else {
                out.println("certificated" + "<br>");
                HttpSession session = request.getSession();
                userfeature=(String)feature.get(userpass);
                userlevel=(String)level.get(userpass);
                //out.println(userlevel);
                //out.println(userfeature); 
                // response.wait(2000);
                session.putValue("loginIsDone", "certified");
                session.putValue("userfeature", userfeature);
                session.putValue("level", userlevel);            LinkedList lsName = new LinkedList();
                LinkedList lsPrice = new LinkedList();
                LinkedList lsAmount = new LinkedList();
                LinkedList lsTotal = new LinkedList();            session.putValue("lsName", lsName);
                session.putValue("lsPrice", lsPrice);
                session.putValue("lsAmount", lsAmount);
                session.putValue("lsTotal", lsTotal);            // response.sendRedirect("../servlet/bishe.ListServlet");
                out.println("您已经成功登录,您的身份是:" + userfeature + "<br>");
                out.println("                    等级是:" + userlevel + "<br>");
                out.println("五秒钟后将自动进入订货系统");
                out.println("<meta http-equiv='refresh' content='5;url=../main.jsp'>");        }
            out.close();
            rs.close();
            stmt.close();
            con.close();    } catch (Throwable theException) {
            System.out.println("loginerror");
            // uncomment the following line when unexpected exceptions
            // are occuring to aid in debugging the problem.
            //theException.printStackTrace();
        }
    }
    }
    这是该类的原码
      

  3.   

    经本人测试第一行最后一个字段区出来的时一个空String
    也就是userlevel.equals("")==true希望有助于大家分析
      

  4.   

    你试试这样行不行:
    do{
                String userid = rs.getString(1);
                String password = rs.getString(2);
                userfeature = rs.getString(3);
                userlevel =rs.getString(4);
                user.put(userid + ":" + password, "allowed");
                feature.put(userid + ":" + password, userfeature);
                level.put(userid + ":" + password, userlevel);
                out.println(userid); 
                out.println(userfeature);
                out.println(password);
                out.println(userlevel);
            }while (rs.next()) ;
      

  5.   

    to蓝天:你那末写肯定sqlexception,原因我就不用说了吧?:)
      

  6.   

    最后一个字段什么类型?
    ================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★  浏览帖子速度极快![建议系统使用ie5.5以上]。 ★  多种帖子实现界面。 
    ★  保存帖子到本地[html格式]★  监视您关注帖子的回复更新。
    ★  可以直接发贴、回复帖子★  采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录! 
    ★  支持在线检测程序升级情况,可及时获得程序更新的信息。★★ 签名  ●  
         可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zip
    Http://www.ChinaOK.net/csdn/csdn.rar
    Http://www.ChinaOK.net/csdn/csdn.exe    [自解压]