reg.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.main {
background-color: yellow;
height: 300px;
width: 500px;
}
</style>
</head>
<center>
<body>
<div class="main">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">请填写以下信息:</td>
</tr>
<tr>
<td width="24%"><div align="right">姓名:</div></td>
<td width="76%"><form id="form1" name="form1" method="post" action="">
<label for="name"></label>
<input type="text" name="name" id="name" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right">学号:</div></td>
<td><form id="form2" name="form2" method="post" action="">
<label for="id"></label>
<input type="text" name="id" id="id" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right">性别:</div></td>
<td><form id="form4" name="form4" method="post" action="">
<label for="class"></label>
<input type="text" name="sex" id="sex" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right">学院:</div></td>
<td><form id="form5" name="form5" method="post" action="">
<label for="college"></label>
<input type="text" name="college" id="college" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right">密码:</div></td>
<td><form id="form3" name="form3" method="post" action="">
<label for="password"></label>
<input type="text" name="password" id="password" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><form id="form7" name="form7" method="post" action="">
<label for="password"></label>
<input type="submit" name="sumbit" id="sumbit" value="提交" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
</table>
</div>
</body>
</center>
</html>
reg_action.jsp
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="ISO-8859-1"%>
<%
request.setCharacterEncoding("utf-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'reg_action.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String username=request.getParameter("username");
String id=request.getParameter("id");
String sex=request.getParameter("sex");
String college=request.getParameter("college");
String passwd=request.getParameter("password");
String url="jdbc:mysql://localhost:3306/OCSS_reg";
String name="root";
String password="123456";
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url,name,password);
String sql="INSERT INTO reg_table(username,id,sex,college,password) VALUES ('"+username+"','"+id+"','"+sex+"','"+college+"','"+passwd+"')";
Statement stmt=conn.createStatement();
//stmt.executeUpdate("insert into reg_table values(zhangsan,001,nan,jsj,123)");
//stmt.executeUpdate("insert into myreg values(7, '66')");
stmt.executeUpdate(sql);
System.out.print(sql);
//if(i>0){
//out.print(i);
//}
//else{
//out.print("插入失败");
// }
%>
</body>
</html>
为什么在页面上输入数据,在数据库中显示数据都是空?
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
.main {
background-color: yellow;
height: 300px;
width: 500px;
}
</style>
</head>
<center>
<body>
<div class="main">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">请填写以下信息:</td>
</tr>
<tr>
<td width="24%"><div align="right">姓名:</div></td>
<td width="76%"><form id="form1" name="form1" method="post" action="">
<label for="name"></label>
<input type="text" name="name" id="name" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right">学号:</div></td>
<td><form id="form2" name="form2" method="post" action="">
<label for="id"></label>
<input type="text" name="id" id="id" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right">性别:</div></td>
<td><form id="form4" name="form4" method="post" action="">
<label for="class"></label>
<input type="text" name="sex" id="sex" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right">学院:</div></td>
<td><form id="form5" name="form5" method="post" action="">
<label for="college"></label>
<input type="text" name="college" id="college" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right">密码:</div></td>
<td><form id="form3" name="form3" method="post" action="">
<label for="password"></label>
<input type="text" name="password" id="password" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><div align="right"></div></td>
<td><form id="form7" name="form7" method="post" action="">
<label for="password"></label>
<input type="submit" name="sumbit" id="sumbit" value="提交" />
<form action="reg_action.jsp" method="post" ></form>
</form></td>
</tr>
</table>
</div>
</body>
</center>
</html>
reg_action.jsp
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="ISO-8859-1"%>
<%
request.setCharacterEncoding("utf-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'reg_action.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
String username=request.getParameter("username");
String id=request.getParameter("id");
String sex=request.getParameter("sex");
String college=request.getParameter("college");
String passwd=request.getParameter("password");
String url="jdbc:mysql://localhost:3306/OCSS_reg";
String name="root";
String password="123456";
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(url,name,password);
String sql="INSERT INTO reg_table(username,id,sex,college,password) VALUES ('"+username+"','"+id+"','"+sex+"','"+college+"','"+passwd+"')";
Statement stmt=conn.createStatement();
//stmt.executeUpdate("insert into reg_table values(zhangsan,001,nan,jsj,123)");
//stmt.executeUpdate("insert into myreg values(7, '66')");
stmt.executeUpdate(sql);
System.out.print(sql);
//if(i>0){
//out.print(i);
//}
//else{
//out.print("插入失败");
// }
%>
</body>
</html>
为什么在页面上输入数据,在数据库中显示数据都是空?