【问题标题】:jsp_mysql_HTTP Status 500 - Internal Server Errorjsp_mysql_HTTP 状态 500 - 内部服务器错误
【发布时间】:2015-04-21 09:46:51
【问题描述】:

这是我从 mysql 数据库中删除数据的代码,我收到了这个错误。

<%@page import='java.sql.*'%>    
<% Class.forName("com.mysql.jdbc.Driver"); %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
         <%! 
        public class student{
        String URL="jdbc:mysql://localhost:3306/project";
       String USERNAME="root";
       String PASSWORD="xxxx";
       Connection con=null;
       PreparedStatement select,deleteA=null;
       ResultSet resultSet=null;

       public student(){               
           try{
           con=DriverManager.getConnection(URL,USERNAME,PASSWORD);           
           select=con.prepareStatement("select id,first_name,last_name from student");
            deleteA=con.prepareStatement("delete from student where id = ? ");             
           }
           catch(SQLException e)
           {
               e.printStackTrace();               
           }                         
       }
       public ResultSet getstudent(){
       try{           
       resultSet=select.executeQuery();           
       }catch(SQLException e)
       {
           e.printStackTrace();
       }
       return resultSet;
       }  

       public int deleteA(Integer id)
        {
        int result=0;
        try{
       deleteA.setInt(1, id);
        result=deleteA.executeUpdate();            
    }
        catch(SQLException e)
        {
            e.printStackTrace();
        }
        return result;
        }
        }  
        %>
        <%
        int result=0;
        student std=new student();
        ResultSet stds=std.getstudent();
        Integer sid=new Integer(0);
        if(request.getParameter("submit")!=null){
        sid=Integer.parseInt(request.getParameter("std"));
        result=std.deleteA(sid);            
        }            
        %>
        <form name="myform" action="delete.jsp" method="POST">
            <table border="0">                    
               <tbody>
                    <tr>
                        <td>name:</td>
                        <td><select name="student">
                                <% while(stds.next()){%>
                                <option value="<%= stds.getInt("id")%>"> <%= stds.getString("first_name")%> <%= stds.getString("last_name")%></option>
                            <% } %>
                            </select></td>
                    </tr>
                </tbody>
            </table>

            <input type="submit" value="submit" name="submit" />                
        </form>
    </body>
</html>

在我选择名称并尝试提交之后..它给了我这个错误

HTTP 状态 500 - 内部服务器错误

输入异常报告

消息内部服务器错误

描述服务器遇到阻止它的内部错误 完成此请求。

异常

org.apache.jasper.JasperException: java.lang.NumberFormatException: 零根本原因

java.lang.NumberFormatException: null note 完整的堆栈跟踪 GlassFish 中提供了异常及其根本原因 Server Open Source Edition 4.1 日志。

【问题讨论】:

    标签: jsp


    【解决方案1】:

    您正在将std 参数解析为整数,但它可能为空。使用前应检查该参数是否为空,而不仅仅是submit参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-24
      • 2019-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多