我正在尝试将数据从我的注册页面保存到我的数据库,但是它的工作原理并没有。有没有人建议我如何解决它?
这是我的jsp页面表单。 我正在使用嵌入式德比数据库。 任何建议将不胜感激。
<form class="form-signin" method="POST" action="newuserservlet">
<input type="text" class="input-block-level" name="firstName" placeholder="First Name">
<input type="text" class="input-block-level" name="lastName" placeholder="Last Name">
<button class="btn btn-large btn-primary" >Sign up</button>
这是我的servlet:
public class newuserservlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String firstname = request.getParameter("firstName");
String lastname = request.getParameter("lastName");
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Connection dbConnection = null;
String strUrl = "jdbc:derby:billsdb;create=true";
dbConnection = DriverManager.getConnection(strUrl);
PreparedStatement stmt = dbConnection.prepareStatement("insert into USERDATA values(?,?)");
stmt.setString(1, firstname);
stmt.setString(2, lastname);
int i = stmt.executeUpdate();
if (i > 0) {
out.println("You are successfully registered.....");
}
} catch (Exception ey) {
System.out.println(ey);
}
out.close();
}