我在jsp中創建了一個表單,並嘗試使用Spring JDBC將表單詳細信息發送到數據庫。我創建了一個JSP表單,一個servlet文件db_Servlet.java,用於從form和db_Service.java中獲取數據,並將數據發送到數據庫。無法使用Spring JDBC將jsp表單詳細信息發送到數據庫
當我使用tomcat運行項目時,它在創建db_Service類的對象時卡住了。 以下代碼是db_Servlet.java的servlet doPost方法。如果你使用Spring,然後
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("entered the servlet");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name = request.getParameter("name");
String ph = request.getParameter("phone");
long phone = Long.parseLong(ph);
String emailid = request.getParameter("emailid");
customer c= new customer(name,phone,emailid);
try {
System.out.println("entered the try block");
db_Service service = new db_Service();
int result = service.addtodb(c);
System.out.println(result);
String title = "Thank you";
String doctype = "<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(doctype +
"<html>\n" +
"<head><title>" + title + "</title></head>\n" +
"<body>" +
"Thank you for wasting your precious time"
+ " </body></html>"
);
}
finally {
out.close();
}
}
及以下是db_Service類
public class db_Service {
public void addtodb(customer c){
System.out.println("Entered the service");
ApplicationContext context =
new ClassPathXmlApplicationContext("Beans.xml");
JDBCtemplate customerJDBCtemplate =
(JDBCtemplate)context.getBean("JDBCtemplate");
customerJDBCtemplate.create(c.getName(),c.getPhone(),c.getEmailid());
}
}
註釋「中輸入服務」的評論後不顯示「進入try塊」
嘗試捕獲異常並打印出堆棧跟蹤。 – Jens
我試圖打印stacktrace,但它不打印任何東西 –
比使用調試器找出發生了什麼 – Jens