这是我的代码。我正在尝试使用JSP和MYSQL向表中添加值。表和数据库的名称是正确的。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Inserting Data from form</title>
</head>
<body>
<h1> Insert a Record</h1>
<form method="post" action="insertrecord.jsp">
<table>
<tr>
<td>
<input type="text" name="uname">
</td>
<td>
<input type="password" name="upass">
</td>
<tr>
<tr>
<td><input type="submit" name="submit" value ="submit"></td>
</tr>
</table>
</form>
<%
String sub = request.getParameter("submit");
if(sub!=null)
{
String uname=request.getParameter("uname");
String password = request.getParameter("upass");
if(uname!=null && password!=null)
{
try
{
Connection con;
Class.forName("com.mysql.jdbc.Driver").newInstance();
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root","");
Statement stmt = con.createStatement();
int i = stmt.executeUpdate("insert into user values ('"+uname+"','"+password+"')");
out.println("Record Inserted Successfully");
stmt.close();
con.close();
}
catch(SQLException e)
{
out.println(e.getMessage());
}
}
}
%>
</body>
</html>
&#13;
当我点击提交时。我收到此错误: HTTP状态404 - 未找到
输入状态报告
消息/something/insertrecord.jsp
描述源服务器没有找到目标资源的当前表示,或者不愿意透露该目标资源是否存在。
Apache Tomcat / 9.0.5