在登录页面填写好用户名密码后,点击提交这时候,MyEclipse就会被调出来说是要debug,然后就提示
 =》request.setCharacterEncoding("gb2312");这句话有问题,提示:Multiple er at this line
 -Line breakpoint :Login[line:32]-doGet(HttpServletRequest,HttpServletResponse)
 -Debug Current Instruction Pointer
不知这是什么原因啊?如果我把request.setCharacterEncoding("gb2312");注释掉,有提示下一句
 HttpSession mySession = request.getSession(true);有问题。

解决方案 »

  1.   

    package servlet;/*
     * This product includes software developed by the
     * Apache Software Foundation (http://www.apache.org/).
     */
    import java.io.*;
    //import java.util.Hashtable;
    import java.sql.*;import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;//import ch04.*;/**
     * 针对登录页面的Servlet
     * @author ShenYK
     * @version 1.0
     */
    public class Login extends Common
    {
        public void doGet ( HttpServletRequest request, 
                            HttpServletResponse response )
            throws ServletException, IOException
        {
            //设置提交表单的中文编码
           // request.setCharacterEncoding("gb2312");
            HttpSession mySession = request.getSession(true);
            
            //清空错误消息
            mySession.setAttribute("errMsg","");
            
            //是否进入默认页面
            if ( !request.getParameterNames().hasMoreElements() )
            {
                response.sendRedirect("../index.jsp");
                return;
            }
            
            //得到用户输入信息
            String sUsername = request.getParameter("username");
            String sPassword = request.getParameter("password");
            //String sRole = request.getParameter("role");        //如果用户是提交表单
            if ( sUsername != null && sUsername.length() > 0 )
            {
                //校验用户输入信息
                String sRealname = getUserRealname( sUsername, sPassword);
                
               if ( sRealname == null )
                {
                    //出错了设置变量并重新显示
                    mySession.setAttribute( "errMsg", "登录失败!请重新输入相关信息!" );
                    mySession.setAttribute( "username", sUsername );
                    //mySession.setAttribute( "role", sRole );
                    response.sendRedirect("../failure.jsp");
                    return;
                }
                else
                {
                    mySession.setAttribute( "username", sUsername );
                    mySession.setAttribute( "realname", sRealname );
                    //根据用户角色的不同决定迁移到哪个页面
                   /* if ( sRole.equals( "0" ) )
                    {
                        //学生角色则迁移到选课一览页面
                        response.sendRedirect( "../servlet/ChooseCourse" );
                    }
                    else
                    {
                        //教师角色则迁移到选课结果一览页面
                        response.sendRedirect( "../servlet/CourseList" );
                    }*/
                    response.sendRedirect( "../WebRoot/success.jsp" );
                    return;
                }
            }
            //如果用户非法进入这个页面
            else
            {
                response.sendRedirect("../index.jsp");
                return;
            }
        }
        
        public void doPost ( HttpServletRequest request, 
                               HttpServletResponse response )
            throws ServletException, IOException 
        {
            doGet( request, response );
        }
        
        private String getUserRealname(String sUsername, String sPassword)
        {
            //获得数据库连接
            Connection conn = this.getDBConnection();
            if ( conn == null )
            {
                return null;
            }
            Statement stmt = null;
            ResultSet rs = null;
            
            try
            {
                stmt = conn.createStatement();
                //执行SQL语句
                String sQuery = "select * from admin where name='" + sUsername + "' "
                              + "and password='" + sPassword +"'";
                rs = stmt.executeQuery( sQuery );
                String sRealname = null;
                if ( rs.next() )
                {
                    sRealname = rs.getString( "realname" );
                }
                return sRealname;
            }
            catch(Exception e)
            {
                e.printStackTrace();
                return null;
            }
            finally
            {
                try
                {
                    rs.close();
                    stmt.close();
                    conn.close();
                }catch(Exception ex)
                {
                }
            }
        }
    }
      

  2.   


    以下是登录信息填写页面:<%@ page contentType="text/html;charset=gbk" language="java"
    import="java.util.*"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
    + request.getServerName() + ":" + request.getServerPort()
    + path + "/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
    <head>
    <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <style type="text/css">
    body {
    background: url(img/stray.jpg);
    background-position: center;
    background-repeat: no-repeat;
    }
    </style> </head> <body>
    <h2 align="center">
    Book Management System
    </h2>
    <br />
    <br />
    <form action="servlet/Login" method="post">
    <table align="center"> <tr>
    <td>
    Username:
    </td>
    <td>
    <input type="text" size="19" name="username" />
    </td>
    </tr>
    <tr>
    <td>
    Password:
    </td>
    <td>
    <input type="password" size="20" name="password" />
    </td>
    </tr>
    <tr>
    <td align="center">
    <input type="submit" value="submit" />
    </td>
    <td align="center">
    <input type="reset" value="reset&nbsp;" />
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>
      

  3.   

    你跑的是不是debug模式阿。看看你的模式。如果正常的模式是不会到debug里面去的
      

  4.   

    页面编码是GBK 后面又是gb2312你全部写成GBK试试···
      

  5.   

    我跑的肯定是enterprise模式啊。我运行程序的时候就是在myeclipse 中启动tomcat6,然后在浏览器里面输入http://localhost:8080/,这有什么不对吗?
      

  6.   

    Common是什么东西 没看出来
      

  7.   


    public class Login extends Common
    {
    这个common是什么类啊?
      

  8.   

    改了以后还是会提示this kind of lanuch is configured to open the debug perspective when it suspends
      

  9.   

    以下是Common类:
    package servlet;/*
     * This product includes software developed by the
     * Apache Software Foundation (http://www.apache.org/).
     */import java.sql.*;import javax.servlet.http.*;/**
     * 针对一些共通处理的父类
     * @author ShenYK
     * @version 1.0
     */
    public class Common extends HttpServlet
    {
        public Connection getDBConnection()
        {
            //尝试连接数据库
            try
            {
                //载入MySQL的JDBC驱动类
                Class.forName( "com.mysql.jdbc.Driver" );
                //获得数据库连接
                Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost/book?user=root&password=891014" );
                
                return conn;
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
                return null;
            }
        }
    }
      

  10.   

    window->preferences 然后找到你的tomcat所在的目录,打开launch窗口,然后修改tomcat lanuch mode为Run mode。然后点击Apply,最后点击OK. 
    这样设置之后,以后服务器就是在run mode下运行了  
      

  11.   

    然后找到你的tomcat所在的目录,我找不着啊,同时,我运行是肯定是程序有问题啊,这与tomcat运行模式应该没有太大关系吧?
      

  12.   

    你报的错误就是你启动tomcat它默认走的debug了 然后有问题后 它就听了 先改成run再看你报错信息
      

  13.   

    还有 你不知道你tomcat装在哪里吗??杯具很
      

  14.   

    我当然知道装在哪里啊,在c盘programs files里,你说windows->preference 难道你不是说让我在这里面找吗?打开launch窗口lauch窗口在哪里啊?
      

  15.   

    我用的开发工具是Myeclipse,但是找不到你所说的launch窗口啊/
      

  16.   

    那你就百度 myeclipse里设置tomcat启动类型 我机子上没myeclipse 给你演示不了
      

  17.   

    我更改了launch mode,但是为什么我正确的输入了用户名密码,却直接跳转到了filure.jsp那个页面了呢?这次肯定是程序有问题了吧我的数据库中有一个用户名为:Bonnie 密码123
      

  18.   

    这个问题还真不是代码的问题是我忘记吧驱动加到lib里面了。非常感谢以上给位的回答。
    但是我还是想问问tomcat启动方式中debug mode与run mode有什么区别吗?
      

  19.   

    你好好看看你的程序 要不把源码打个包发过来 包括数据库的建表语句  [email protected]
      

  20.   

    以上问题应该解决了,我就是想问问tomcat不是有两种launch mode(debug 和run )吗?这两种方式有什么不同吗?谢谢!回答完了就结贴
      

  21.   


    debug就是让你用来调试程序的
      

  22.   

    debug模式时候 你要是再程序中打了断点 那么它走到断点住就会停下来 进入debug模式 然后手动往下执行
    run模式是直接全部编译一边 除非程序有问题 不然不会停