我最近制作了一个HTML页面,用于验证表单提交,以便提交具有名称,电子邮件地址,性别,评论和相同密码的值。现在,我正在尝试实现,因此可以将每个表单的这些值插入到数据库中。以下是代码的片段
HTML部分
<form id="regForm" action="insertInfo.jsp" onsubmit="return validation();" method="post" enctype="text/plain">
<fieldset>
<legend>Registration</legend>
<p>Name: <input type="text" name="name" id="name"/></p>
<p>Email Address: <input type="text" name="emailAddress" id="emailAddress"/></p>
<p>Gender:
<input type="radio" name="gender" id="genderM" value="Male" /> Male
<input type="radio" name="gender" id="genderF" value="Female" /> Female
</p>
<p>Password: <input type="password" name="password_1" id="password_1"/></p>
<p>Confirm Password: <input type="password" name="password_2" id="password_2"/></p>
<p>Comments: <input type="text" name="comments" id="comments"/></p>
<p><input type="submit" name="submit" value="Submit"/></p>
</fieldset>
</form>
JSP代码,名为insertInfo.jsp
<%@ page import="java.sql.*" %>
<%
String connectionURL = "jdbc:mysql://sql.school.edu:3306/user";
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "user", "password");
statement = connection.createStatement();
String name=request.getParameter("name");
String password=request.getParameter("password_1");
String email=request.getParameter("emailAddress");
String gender=request.getParameter("gender");
String comments=request.getParameter("comments");
rs = statement.executeQuery("INSERT INTO Information VALUES ('"+name+"', '"+password+"', '"+email+"', '"+gender="', '"+comments+"')");
%>
当我尝试提交表单时,系统会提示我显示类似于
的页面HTTP状态404 - /~user/insertInfo.jsp
输入状态报告
message /〜user /insertInfo.jsp
description请求的资源(/〜user /insertInfo.jsp)不是 可用。 Apache Tomcat / 5.5.29
我很困惑为什么会这样。此外,HTML和JSP文件位于同一个public_html目录中。