<p>&quot;public boolean insertAdmin(Admin admin) {\n\t\tboolean fale=false;\n\t\tConnection lj=DBbooks.getConnection();\n\t\tString sql=&quot;insert into admin value(?,?,?,?,?)&quot; ;\n\t\ttry {\n\t\t\tPreparedStatement pst=lj.prepareStatement(sql);\n\t\t\tpst.setInt(1,admin.getAid());\n\t\t\tpst.setString(2, admin.getUsername());\n\t\t\tpst.setString(3, admin.getName());\n\t\t\tpst.setString(4, admin.getEmail());\n\t\t\tpst.setString(5, admin.getPhone());\n\t\t\t\n\t\t\tfale=pst.executeUpdate()&gt;0?true:false;\n\t\t\tpst.close();\t\n\t\t} catch (SQLException e) {\n\t\t\t// TODO Auto-generated catch block\n\t\t\te.printStackTrace();\n\t\t}\n\t\tDBbooks.CloseConnection(lj);\n\t\treturn fale;\n\t}\n&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=UTF-8&quot;\n    pageEncoding=&quot;UTF-8&quot;%&gt;<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;<title>添加管理员</title>	&lt;script src=&quot;js/jquery-1.8.3.min.js&quot;&gt;</script>	<script>function checkForm(){\n	    var aid=&quot;#&quot; + $(&quot;#aid&quot;).val();\n	    var aidPattern= /^\d+$/;  //匹配数字</p>
<pre><code>    if(!aid.match(aidPattern)){\n	        alert(\&quot;ID必须为数字\&quot;);\n	        return false;\n	    }\n
    var username=\&quot;#\&quot; + $(\&quot;#username\&quot;).val();\n	    var usernamePattern = /^[a-zA-Z0-9]+$/;  //匹配字母和数字

    if(!username.match(usernamePattern)){\n	        alert(\&quot;账号只能包含字母和数字\&quot;);\n	        return false;\n	    }\n
    var name=\&quot;#\&quot; + $(\&quot;#name\&quot;).val();\n	    var namePattern = /^([\u4e00-\u9fa5]{2,20}|[a-zA-Z.\s]{2,20})$/;; //匹配中文和英文

    if(!name.match(namePattern)){\n	        alert(\&quot;名字只能包含字母和字符串\&quot;);\n	        return false;\n	    }\n
    var email=\&quot;#\&quot; + $(\&quot;#email\&quot;).val();\n	    var emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;  //匹配邮箱格式

    if(!email.match(emailPattern)){\n	        alert(\&quot;邮箱格式不正确\&quot;);\n	        return false;\n	    }\n
    var phone=\&quot;#\&quot; + $(\&quot;#phone\&quot;).val();\n	    var phonePattern = /^\d{10}$/;  //匹配10位数字

    if(!phone.match(phonePattern)){\n	        alert(\&quot;数字必须为10位数\&quot;);\n	        return false;\n	    }\n	    return true;\n	}\n&lt;/script&gt;&lt;/head&gt;&lt;body&gt;	&lt;form action=\&quot;insertAdminServlet\&quot; method=\&quot;post\&quot; onsubmit=\&quot;return checkForm()\&quot;&gt;&lt;br/&gt;	ID:&lt;input type=\&quot;text\&quot; id=\&quot;aid\&quot; name=\&quot;aid\&quot;/&gt;	&lt;br/&gt;	账号:&lt;input type=\&quot;text\&quot; name=\&quot;username\&quot; id=\&quot;username\&quot;/&gt;	&lt;br/&gt;	名字:&lt;input type=\&quot;text\&quot; name=\&quot;name\&quot; id=\&quot;name\&quot;/&gt;	&lt;br/&gt;	邮箱:&lt;input type=\&quot;text\&quot; name=\&quot;email\&quot; id=\&quot;email\&quot;/&gt;	&lt;br/&gt;	电话:&lt;input type=\&quot;text\&quot; name=\&quot;phone\&quot; id=\&quot;phone\&quot;/&gt;	&lt;br/&gt;	&lt;button type=\&quot;submit\&quot;&gt;提交&lt;/button&gt;	&lt;/form&gt;&lt;/body&gt;&lt;/html&gt;package books.liao.servlet;\n\nimport java.io.IOException;\n\nimport javax.servlet.ServletException;\nimport javax.servlet.http.HttpServlet;\nimport javax.servlet.http.HttpServletRequest;\nimport javax.servlet.http.HttpServletResponse;\n\nimport books.liao.dao.AdminDao;\nimport books.liao.pojo.Admin;\n\n\npublic class InsertAdminServlet extends HttpServlet{\n\tpublic void doGet(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException {\n\t\tdoPost(req,resp);\n\t}\n\tpublic void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException {\n\t\trequest.setCharacterEncoding(\&quot;UTF-8\&quot;);\n\t\tString strid=request.getParameter(\&quot;aid\&quot;);\n\t\tString username=request.getParameter(\&quot;username\&quot;);\n\t\tString name=request.getParameter(\&quot;name\&quot;);\n\t\tString email=request.getParameter(\&quot;email\&quot;);\n\t\tString phone=request.getParameter(\&quot;phone\&quot;);\n\t\t\n\t\tint aid=Integer.parseInt(strid);\n\t\t\n\t\tAdmin admin=new Admin();\n\t\tadmin.setAid(aid);\n\t\tadmin.setUsername(username);\n\t\tadmin.setName(name);\n\t\tadmin.setEmail(email);\n\t\tadmin.setPhone(phone);\n\t\t\n\t\tAdminDao dao=new AdminDao();\n\t\tboolean fale=dao.insertAdmin(admin);\n\t\tif(fale) {\n\t\t\trequest.getRequestDispatcher(\&quot;selectAdminServlet\&quot;).forward(request, response);;  //跳转到admin列表页面\n\t\t}\n\t}\n}\n\njava.sql.SQLException: Column count doesn't match value count at row 1\n\tat com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)\n\tat com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3978)\n\tat com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3914)\n\tat com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)\n\tat com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)\n\tat com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2495)\n\tat com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1903)\n\tat com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2124)\n\tat com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2058)\n\tat com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5158)\n\tat com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2043)\n\tat books.liao.dao.AdminDao.insertAdmin(AdminDao.java:27)\n\tat books.liao.servlet.InsertAdminServlet.doPost(InsertAdminServlet.java:36)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:661)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:742)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)\n\tat org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)\n\tat org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)\n\tat org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)\n\tat org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)\n\tat org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)\n\tat org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)\n\tat org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)\n\tat org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)\n\tat org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)\n\tat org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)\n\tat org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)\n\tat org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)\n\tat org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)\n\tat org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)\n\tat org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n\tat org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)\n\tat java.lang.Thread.run(Unknown Source)\n七月 24, 2023 10:00:40 下午 org.apache.catalina.core.StandardContext reload\n信息: Reloading Context with name [/Books] has started\n七月 24, 2023 10:00:40 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc\n警告: The web application [Books] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.\n七月 24, 2023 10:00:40 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads\n警告: The web application [Books] 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:\n java.lang.Object.wait(Native Method)\n java.lang.ref.ReferenceQueue.remove(Unknown Source)\n com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:64)\n java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n java.lang.Thread.run(Unknown Source)\n七月 24, 2023 10:00:44 下午 org.apache.jasper.servlet.TldScanner scanJars\n信息: 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.\n七月 24, 2023 10:00:44 下午 org.apache.catalina.core.StandardContext reload\n信息: Reloading Context with name [/Books] is completed\n七月 24, 2023 10:00:44 下午 org.apache.catalina.loader.WebappClassLoaderBase checkStateForResourceLoading\n信息: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.\njava.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.\n\tat org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1311)\n\tat org.apache.catalina.loader.WebappClassLoaderBase.getResource(WebappClassLoaderBase.java:986)\n\tat com.mysql.jdbc.AbandonedConnectionCleanupThread.checkContextClassLoaders(AbandonedConnectionCleanupThread.java:90)\n\tat com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:63)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)\n\tat java.lang.Thread.run(Unknown Source)
</code></pre>
添加管理员 - 管理员管理系统

原文地址: https://www.cveoy.top/t/topic/p0aD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录