質問が 5 つしかないオンライン試験用の 3 層 Web アプリケーションを作成しています。html を使用し、「test」という名前の mysql データベースにデータを投稿するサーブレットを設計しました。テーブルは「st1」です。MyEclipse Tomcat 6.0.13 が組み込まれている MyEclipse Blue 8.6.1 を使用しています。doPost() メソッドでのサーブレットのコーディングは次のとおりです。
try
{
String url="jdbc:mysql://localhost:3306/test";
Class.forName("com.mysql.jdbc.Driver");
connect=DriverManager.getConnection(url,"root","root");
message="Connection Sucessfull";
}
catch(ClassNotFoundException cnfex){
cnfex.printStackTrace();
}
catch(SQLException sqlex){
sqlex.printStackTrace();
}
catch(Exception excp){
excp.printStackTrace();
}
seat_no=request.getParameter("Seat_No");
name=request.getParameter("Name");
ans1=request.getParameter("group1");
ans2=request.getParameter("group2");
ans3=request.getParameter("group3");
ans4=request.getParameter("group4");
ans5=request.getParameter("group5");
if(ans1.equals("True"))
Total+=2;
if(ans2.equals("False"))
Total+=2;
if(ans3.equals("True"))
Total+=2;
if(ans4.equals("False"))
Total+=2;
if(ans5.equals("False"))
Total+=2;
try
{
Statement stmt=connect.createStatement();
String query="INSERT INTO st1("+"seat_no,name,marks"+")VALUES('"+seat_no+"','"+name+"','"+Total+"')";
stmt.executeUpdate(query);
stmt.close();
}
アプリケーションをコンパイルすると、次のような例外が発生し続けます。
HTTP Status 500 -
type Exception report
message:
description The server encountered an internal error () that prevented it from fulfilling this request.
exception :
java.lang.NullPointerException
s3.doPost(s3.java:52)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note :The full stack trace of the root cause is available in the Apache Tomcat/6.0.13 logs
しかし、MyEclipse Tomcat 6.0.13 で使用できるログは見つかりませんでした。この例外を克服するのを手伝ってくれる人はいますか? その私の学術プロジェクトです!前もって感謝します !!