有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Servlet代码错误:http 500内部服务器错误

我试图运行以下代码,但它总是导致“http 500内部服务器错误”

有人能帮我调试这个错误吗

我刚开始学习servlet和JSP。。如果我遗漏了问题中的任何细节,请原谅。查看MYSQL数据库错误日志,我发现以下条目:

Aborted connection 44 to db: 'sakila' user: 'root' host: 'localhost' (Got an error reading communication packets)

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();
    final String DB_URL="jdbc:mysql://localhost:3306/sakila";
    final String user="root";
    final String password="pass1234";
    Statement stmt=null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        out.println("Cannot load driver");
    }
    Connection conn=null;

    try {
        conn=DriverManager.getConnection(DB_URL,user,password);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        out.println("Cannot Connect to Database");
    }

    //out.print("Connected to Database");
    out.println("<html>");
    out.println("<body>");
    String str= "SELECT actor_id, first_name last_name FROM temp where actor_id='1';";

    try {
        ResultSet rs=stmt.executeQuery(str);
        while(rs.next()){
            out.println(rs.getString("actor_id"));

        }

    } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }       
    /*
    try {
        ResultSet rs;
        rs = stmt.executeQuery(str);
        while(rs.next()){
            int i=rs.getInt("actor_id");
            String fn= rs.getString("first_name");
            String ln=rs.getString("last_name");

            out.print(i+"::");
            out.print(fn+"::");
            out.print(ln+"::");
        }
    } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    */
    out.print("hkshfdkhfakfshdkha");




    try {
        conn.close();
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    out.println("</body>");
    out.println("</html>");


}

共 (0) 个答案