2015-04-19 17 views
0

這是我從mysql數據庫中刪除數據的代碼,並且出現此錯誤。jsp_mysql_HTTP狀態500 - 內部服務器錯誤

<%@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> 

後,我選擇的名稱,並嘗試submit..it給了我這個錯誤

HTTP狀態500 - 內部服務器錯誤

類型異常報告

messageInternal服務器錯誤

description服務器遇到阻止它的內部錯誤 履行此要求。

例外

org.apache.jasper.JasperException:java.lang.NumberFormatException: 空根源

java.lang.NumberFormatException:空注意 異常及其根完整的堆棧跟蹤原因在GlassFish Server Open Source Edition 4.1日誌中可用。

回答

0

您正在解析std參數作爲整數,但可能它爲空。在使用之前,您應該檢查此參數是否爲空,而不僅僅是參數submit

+0

那我該怎麼做.....? –