登録ページをデザインするためにHTMLファイルを作成しました。 Submitボタンをクリックすると、フォーム値がJSPページに送信されます。しかし、私はこのプロジェクトを実行すると、フォームを記入した後、空のJSPページが表示され、 "データの入力に失敗しました"というメッセージも表示されません。値はデータベースに入力されません。私はNetbeans IDEを使用しています。 ここに両方のファイルのコードがあります。JSPフォームのデータがmysqlデータベースに入力されていません
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);
}
%>
助けてください。事前に感謝:)