web连接数据库完成登录注册
完整文件目录如下:
-
主页面的编写(.jsp文件)
<html>
<head>
<title>淘宝网</title>
</head>
<body>
<h1>欢迎来到主页面!</h1>
<a href="Login.jsp">去登陆</a><br>
<a href="register.jsp">去注册</a>
</body>
</html>
给客户两个选项(登陆/注册)---完成页面如下
1.登陆页面编写
<html>
<head>
<title>登陆页面</title>
</head>
<body>
<h2>欢迎学习WEB!</h2>
<form action="login" method="post">
账号:<input type="text" name="username" value=""> <br>
密码:<input type="password" name="password" value=""> <br>
<input type="submit" value="登录">
</form>
</body>
</html>
1.2注册页面
<html>
<head>
<title>注册页面</title>
</head>
<body>
<h1>注册页面</h1>
<form action="register" method="post">
账号:<input type="text" name="username" value=""> <br>
密码:<input type="password" name="password" value=""> <br>
再次输入密码:<input type="password" name="password" value=""> <br>
手机号:<input type="text" name="phone" value=""> <br>
地址:<input type="text" name="address" value=""> <br>
<input type="submit" value="注册">
<a href="Login.jsp">已有账号?点击登录</a>
</form>
</body>
</html>
1.3项目页面
<html>
<head>
<title>主页</title>
</head>
<body>
<h1>欢迎项目主页</h1>
<h2>主页信息展示</h2>
<table>
<thead>
<tr>
<th>商品编号</th>
<th>商品名称</th>
<th>商品价格</th>
<th>商品介绍</th>
</tr>
</thead>
<tbody id="list">
<%
// 获取session
HttpSession session1 = request.getSession();
// 从session中取出数据
List<Goods> goodsList = (List<Goods>) session1.getAttribute("goodsList");
// 遍历集合中的元素
for (Goods goods : goodsList) {
%>
<!--使用java脚本获取集合中对象的元素,放入html标签中-->
<tr>
<td><%=goods.getGid()%></td>
<td><%=goods.getGname()%></td>
<td><%=goods.getPrice()%></td>
<td><%=goods.getMark()%></td>
</tr>
<%
}
%>
</tbody>
</table>
</body>
</html>
1.4错误页面
<html>
<head>
<title>错误页</title>
</head>
<body>
<h1>密码输入错误!!!</h1>
<a href="index.jsp">回到主页</a> <br>
<a href="Login.jsp">回到登录页</a>
</body>
</html>
2.登陆页面编写
<html>
<head>
<title>登陆页面</title>
</head>
<body>
<h1>登陆页面</h1>
<h2>欢迎学习WEB!</h2>
<form action="login" method="post">
账号:<input type="text" name="username" value=""> <br>
密码:<input type="password" name="password" value=""> <br>
<input type="submit" value="登录">
<a href="register.jsp">没有账号?点击注册</a>
</form>
</body>
</html>
2.1实体类
package com.man.dao;
public class User {
private Integer uid;
private String username;
private String password;
private String phone;
private String address;
public User() {
}
public User(Integer uid, String username, String password, String phone, String address) {
this.uid = uid;
this.username = username;
this.password = password;
this.phone = phone;
this.address = address;
}
public Integer getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public S