Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html JSP表单数据未进入mysql数据库_Html_Mysql_Jsp_Jdbc_Netbeans - Fatal编程技术网

Html JSP表单数据未进入mysql数据库

Html JSP表单数据未进入mysql数据库,html,mysql,jsp,jdbc,netbeans,Html,Mysql,Jsp,Jdbc,Netbeans,我制作了一个HTML文件来设计注册页面。单击Submit按钮,表单值被发送到JSP页面。但是当我运行这个项目时,在填写表单之后,会显示空白的JSP页面,甚至不会显示“输入数据失败”。和值并没有输入到数据库中。我正在使用Netbeans IDE。 这是两个文件的代码 addlibform.html: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text

我制作了一个HTML文件来设计注册页面。单击Submit按钮,表单值被发送到JSP页面。但是当我运行这个项目时,在填写表单之后,会显示空白的JSP页面,甚至不会显示“输入数据失败”。和值并没有输入到数据库中。我正在使用Netbeans IDE。 这是两个文件的代码

addlibform.html:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Add Librarian</title>
    <link rel="stylesheet"      href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="background.css">
    <link rel="stylesheet" type="text/css" href="main.css">
    <style>
        .label{
            font-size: 15px;
            color: black;
            position: absolute;
            margin-left: 500px;
            margin-top: 100px;
        }
        .input{
            position: absolute;
            margin-left: 650px;
            margin-top: 100px;
        }
    </style>
</head>
<body>

    <h1 style="position: absolute; margin-left: 550px;">Add Librarian</h1><br>
    <form method="post" action="addlib.jsp">
        <label for="username" class="label">Username:</label>

        <input type="text" name="userid" id="userid" required class="input"><br><br><br>

    <label for="password" class="label">Password:</label>

    <input type="password" name="password" id="password" class="input"><br><br><br>

        <label for="address" class="label">Address:</label>

        <textarea rows="2" cols="22" name="add" class="input"></textarea><br><br><br>

        <label for="city" class="label">City:</label>

        <input type="text" name="city" class="input"><br><br><br>

        <label for="contact" class="label">Contact No.:</label>

        <input type="text" name="contact" class="input"><br><br><br>

        <input type="submit" class="btn btn-default" value="Add Librarian" style="position: relative; margin-left: 600px; margin-top: 100px;">
        <input class="btn btn-default" value="Back" style="position: relative; margin-left: 600px; margin-top: 20px;">        
    </form>

</body>
</html>

添加图书管理员
.标签{
字体大小:15px;
颜色:黑色;
位置:绝对位置;
左边距:500px;
边缘顶部:100px;
}
.输入{
位置:绝对位置;
左边距:650px;
边缘顶部:100px;
}
添加图书管理员
用户名:


密码:


地址:


城市:


联络电话:


addlib.jsp文件:

<%@ page import ="java.sql.*" %>
<%@ page import ="java.lang.*" %>
<%
String username = request.getParameter("userid");
String pwd = request.getParameter("password");
String add = request.getParameter("address");
String city = request.getParameter("city");
String contact = request.getParameter("contact");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection c= DriverManager.getConnection("jdbc:mysql://localhost:3306/librarymgmt", "root", "root");
Statement st = c.createStatement();

int i=st.executeUpdate("INSERT INTO librarians VALUES('" + username + "','" + pwd + "','" + add + "','" + city + "','" + contact + ")");
if(i > 0)
    System.out.println("Librarian added successfully");
else
    System.out.println("Failed to insert data");
}
catch(Exception e)
{
  System.out.println(e);
}
%>  

0)
System.out.println(“图书管理员添加成功”);
其他的
System.out.println(“插入数据失败”);
}
捕获(例外e)
{
系统输出打印ln(e);
}
%>  
请帮忙。提前感谢:)

以下内容:

"','" + contact + ")");
在关闭括号之前无法关闭单引号

那是你的错误

但这无关紧要。这里的问题不是你所犯的特定错误,而是你在盲中编码,却看不到错误。如果你继续在盲人中编码,将会发生更多的错误,而且你仍然不知道哪里出了问题。我们stackoverflow是来帮忙的,但在某一点之后,它开始变得单调乏味,无论是对你还是对我们

因此,在您的代码中,如果抛出异常(正如我在上面解释的,它抛出的),异常的
toString()
将输出到标准输出。你在控制台里看到了吗?如果您无条件地将“hello”输出到标准输出(比如说,就在
try{,
)之前),您看到了吗?如果没有,那么这就是问题所在:错误被有效地抑制了,因此您无法知道出了什么问题

尝试捕获异常如何,这样服务器将为您捕获异常,并在服务器日志和实际网页中提供有意义的错误消息