标签:
注册页面register.jsp
代码
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<!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>用户注册</title>
<style type="text/css">
#apDiv1 {position:absolute;width:500px;height:115px;z-index:1;eft: 250px;top: 100px;}
</style>
</head>
<body>
<body background=D:\eclipseworkplace\image\2.jpg>
<div id="apDiv1">
<form action="WR.jsp" method="post" name="f1" >
用户名: <input type="text" name="t1" > <br>
<br>
密 码: <input type="password" name="p1"> <br>
<br>
手机号: <input type="text" name="t2"> <br>
<br>
级 别: <input type="text" name="t3"> (u代表用户,a代表书店管理员)
<br>
<br>
<input type="submit" name="s1" value="注册">
<input type="reset" name="t" value="重置">
</form>
</div>
</body>
</html>
将注册信息写入数据库WR.jsp
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@page import="java.sql.*,java.io.*,java.lang.*"%>
<!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>写入注册信息</title>
</head>
<body>
<% String t1=request.getParameter("t1");
String p1=request.getParameter("p1");
String t2=request.getParameter("t2");
String t3=request.getParameter("t3");
if(t1!=null&&p1!=null&&t2!=null)
{
String DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String USER = "sa";
String PASSWORD = "123456";
String URL = "jdbc:sqlserver://localhost:1433;databaseName=book";
Class.forName(DRIVER);
Connection conn=DriverManager.getConnection(URL, USER, PASSWORD);
Statement stmt=conn.createStatement();
String sql="INSERT INTO member values(‘017‘,‘"+t1+"‘,‘"+p1+"‘,‘"+t2+"‘,‘"+t3+"‘)";
stmt.executeUpdate(sql);
stmt.close();
conn.close();
%>
<jsp:forward page="login.jsp"/>
<% } else { %>
<jsp:forward page="register.jsp"/>
<% }%>
</body>
</html>
标签:
原文地址:http://www.cnblogs.com/gjzf/p/5601760.html