나는 등록 페이지를 디자인하기 위해 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);
}
%>
이 도와주세요. 다음