使用servlet提交时,数据库中没有数据

时间:2016-12-14 09:53:01

标签: java apache tomcat servlets

提交表单时,数据不会传递到数据库中。我正在使用phpMyadmin。

这是提交表单时显示的内容。 我不知道错误在哪里。

{
    "range" : {
        "deadline" : {
            "gte" : "2016-12-14",
        }
    }
}

这是我的表格:

14-Dec-2016 17:37:54.895 WARNING [http-nio-8084-exec-146] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [YIP] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.lang.Object.wait(Native Method)
 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
 com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
14-Dec-2016 17:37:55.398 INFO [http-nio-8084-exec-146] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/YIP]
14-Dec-2016 17:37:55.438 INFO [http-nio-8084-exec-153] org.apache.catalina.startup.HostConfig.deployDescriptor Deploying configuration descriptor C:\Users\user\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\YIP.xml
14-Dec-2016 17:37:55.656 INFO [http-nio-8084-exec-153] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
14-Dec-2016 17:37:55.665 INFO [http-nio-8084-exec-153] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor C:\Users\user\AppData\Roaming\NetBeans\8.1\apache-tomcat-8.0.27.0_base\conf\Catalina\localhost\YIP.xml has finished in 227 ms
14-Dec-2016 17:37:55.691 INFO [http-nio-8084-exec-147] org.apache.catalina.util.LifecycleBase.start The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/YIP]] after start() had already been called. The second call will be ignored.

这是我的servlet:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Maklumat Sekolah</title>
</head>
<body>
    <header style="height: 15%">
        <h1 style="text-align: center">Young Innovate</h1>
    </header>
    <div>
    <link rel="stylesheet" type="text/css" href="pendaftaran2.css"/>
    <form class="form-3" name="frmsekolah" action="SekolahServlet" method="POST">
        <h2 style="text-align: center">Kemaskini Maklumat Sekolah</h2>
        <table border="0">
            <tbody>
            <tr>
                <td>Id Sekolah :</td>
                <td><input type="text"id="sekolahid" name="sekolahid" size="3"/></td>
            </tr>
            <tr>
                <td>Nama Sekolah :</td>
                <td><input type="text" id="snama" name="snama" size="30"/></td>
            </tr>
            <tr>
                <td>Alamat Sekolah :</td>
                <td><input type="text" id="salamat" name="salamat" size="50"/></td>
            </tr>
            <tr>
                <td>No.Telefon Sekolah :</td>
                <td><input type="text" id="stel" name="stel" size="11"/></td>
            </tr>
            <tr>
                <td>Emel Sekolah :</td>
                <td><input type="text" id="semel" name="semel" size="30"/></td>
            </tr>
            <tr>
                <td><input type="hidden" name="action" value="edit"/></td>
            </tr>
            <tr>
                    <td class="button">
                        <button type="submit" name="submit" value="Submit"/>Submit
                    </td>
                </tr>
        </tbody>
        </table>
    </form>
    </div>
</body>
</html>

这是我的DAO

package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.SekolahDao;
import com.model.Sekolah;
public class SekolahServlet extends HttpServlet {
private static String INSERT = "/sekolahform.jsp";
private static String EDIT = "/editSekolah.jsp";
private static String LIST_SEKOLAH = "/listSekolah.jsp";
private SekolahDao dao;

public SekolahServlet() throws ClassNotFoundException{
    super ();
    dao = new SekolahDao();
}

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException{
    String forward = "";
    String action = request.getParameter("action");

    if (action.equalsIgnoreCase("delete")) {
        String sekolahid = request.getParameter("sekolahid");
        dao.deleteSekolah(sekolahid);
        forward = LIST_SEKOLAH;
        request.setAttribute("sekolah",dao.getAllUsers());
    }
    else if (action.equalsIgnoreCase("edit")) {
        forward = EDIT;
        String sekolahid = request.getParameter("sekolahid");
        Sekolah sekolahs = dao.getUserById(sekolahid);
        request.setAttribute("sekolah", sekolahs);
    }
    else if (action.equalsIgnoreCase("listSekolah")){
        forward = LIST_SEKOLAH;
        request.setAttribute("sekolah", dao.getAllUsers());
    }
    else if (action.equalsIgnoreCase("insert")){
        forward = INSERT;
    }

    RequestDispatcher view = request.getRequestDispatcher(forward);
    view.forward(request, response);
}
@Override
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

    String action = request.getParameter("action");

    Sekolah sekolahs = new Sekolah();
    sekolahs.setSekolahid(request.getParameter("sekolahid"));
    sekolahs.setSnama(request.getParameter("snama"));
    sekolahs.setSalamat(request.getParameter("salamat"));
    sekolahs.setStel(Integer.parseInt(request.getParameter("stel")));
    sekolahs.setSemel(request.getParameter("semel"));


    if (action.equalsIgnoreCase("edit"))
    {
        dao.updateSekolah(sekolahs);
    }
    else
    {
        dao.addSekolah(sekolahs);
    }

    RequestDispatcher view = request.getRequestDispatcher(LIST_SEKOLAH);
    request.setAttribute("sekolah", dao.getAllUsers());
    view.forward(request, response);
}
}

2 个答案:

答案 0 :(得分:0)

如果没有正确的代码,则无法解决此问题......

答案 1 :(得分:0)

这似乎是原因。

14-Dec-2016 17:37:55.691 INFO [http-nio-8084-exec-147] org.apache.catalina.util.LifecycleBase.start The start() method was called on component StandardEngine[Catalina].StandardHost[localhost].StandardContext[/YIP]] after start() had already been called. The second call will be ignored.

因此,被调用两次的start()方法似乎是原因。正如穆克什所说,没有代码,我们就无法提供更多帮助。