【发布时间】:2016-12-28 07:50:02
【问题描述】:
我制作了一个 HTML 文件来设计一个注册页面。单击提交按钮时,表单值被发送到 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>
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);
}
%>
请帮忙。在此先感谢:)
【问题讨论】:
标签: html mysql jsp jdbc netbeans