fix<页面调整>

master
liyansheng 2024-12-21 18:06:18 +08:00
parent 3d64451e43
commit 78f1155583
13 changed files with 110 additions and 83 deletions

View File

@ -1,6 +1,6 @@
# jsp+servlet # jsp+servlet
## 全局过滤器的应用 ## 全局过滤器的应用(鉴权,异常统一处理)

View File

@ -12,8 +12,8 @@ public class UserDao {
private final QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource()); private final QueryRunner queryRunner = new QueryRunner(DBUtils.getDataSource());
public int addUser(String username, String phone,String password) throws Exception { public int addUser(String username, String phone,String password) throws Exception {
String sql = "INSERT INTO user (username,phone, password,admin) VALUES (?, ?,?,?)"; String sql = "INSERT INTO user (username,phone, password,role) VALUES (?, ?,?,?)";
return queryRunner.update(sql, username, phone,password,0); return queryRunner.update(sql, username, phone,password,"user");
} }
public User getUserById(int id) throws Exception { public User getUserById(int id) throws Exception {

View File

@ -6,17 +6,17 @@ public class User {
private int id; private int id;
private String username; private String username;
private String password; private String password;
private Boolean admin; private String role;
private String phone; private String phone;
public User() { public User() {
} }
public User(int id, String username, String password, Boolean admin, String phone) { public User(int id, String username, String password, String role, String phone) {
this.id = id; this.id = id;
this.username = username; this.username = username;
this.password = password; this.password = password;
this.admin = admin; this.role=role;
this.phone = phone; this.phone = phone;
} }
@ -44,12 +44,12 @@ public class User {
this.password = password; this.password = password;
} }
public Boolean getAdmin() { public String getRole() {
return admin; return role;
} }
public void setAdmin(Boolean admin) { public void setRole(String role) {
this.admin = admin; this.role = role;
} }
public String getPhone() { public String getPhone() {

View File

@ -2,22 +2,23 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Computer</title> <title>电脑产品发布</title>
</head> </head>
<body> <body>
<h1>Add New Computer</h1> <h1>电脑产品发布</h1>
<form action="/addComputer" method="post"> <form action="/addComputer" method="post">
<label for="name">Name: </label><br> <label for="name">名称: </label><br>
<input type="text" id="name" name="name"><br><br> <input type="text" id="name" name="name"><br><br>
<label for="price">Price: </label><br> <label for="price">价格: </label><br>
<input type="text" id="price" name="price"><br><br> <input type="text" id="price" name="price"><br><br>
<label for="stock">Stock: </label><br> <label for="stock">库存: </label><br>
<input type="text" id="stock" name="stock"><br><br> <input type="text" id="stock" name="stock"><br><br>
<input type="submit" value="Add Computer"> <input type="submit" value="确定">
</form> </form>
<br> <br>
<a href="/computerList">Back to List</a> <a href="/computerList">返回电脑列表</a>
</body> </body>
</html> </html>

View File

@ -3,6 +3,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>购物车</title> <title>购物车</title>

View File

@ -3,6 +3,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>订单确认</title> <title>订单确认</title>

View File

@ -2,21 +2,24 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Computer List</title> <title>电脑产品列表</title>
</head> </head>
<body> <body>
<h1>Computer List</h1> <h1>电脑产品列表</h1>
<table border="1"> <table border="1">
<thead> <thead>
<tr> <tr>
<th>ID</th> <th>ID</th>
<th>Name</th> <th>名称</th>
<th>Price</th> <th>价格</th>
<th>Stock</th> <th>库存</th>
<th>Actions</th> <th>操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -27,9 +30,15 @@
<td>${computer.price}</td> <td>${computer.price}</td>
<td>${computer.stock}</td> <td>${computer.stock}</td>
<td> <td>
<a href="/editComputer?id=${computer.id}">Edit</a> | <c:if test="${sessionScope.user.role == 'admin'}">
<a href="/deleteComputer?id=${computer.id}">Delete</a> | <a href="/editComputer?id=${computer.id}">编辑</a> |
<a href="/deleteComputer?id=${computer.id}">删除</a>
</c:if>
<c:if test="${sessionScope.user.role == 'user'}">
<a href="/cart?action=add&id=${computer.id}">加购</a> <a href="/cart?action=add&id=${computer.id}">加购</a>
</c:if>
</td> </td>
</tr> </tr>
</c:forEach> </c:forEach>
@ -37,10 +46,16 @@
</table> </table>
<hr> <hr>
<p style="color: red;">${requestScope.msg}</p> <p style="color: red;">${requestScope.msg}</p>
<a href="/cart?action=list">我的购物车</a>
<br /> <br />
<a href="/addComputer">Add New Computer</a> <c:if test="${sessionScope.user.role == 'user'}">
<a href="/cart?action=list">我的购物车</a>
</c:if>
<c:if test="${sessionScope.user.role == 'admin'}">
<a href="/addComputer">发布电脑产品</a>
</c:if>
<br> <br>
<a href="/">主页</a> <a href="/">主页</a>
</body> </body>
</html> </html>

View File

@ -3,23 +3,24 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Update Computer</title> <title>更新电脑信息</title>
</head> </head>
<body> <body>
<h1>Update Computer</h1> <h1>更新电脑信息</h1>
<form action="/editComputer" method="post"> <form action="/editComputer" method="post">
<input type="hidden" name="id" value="${computer.id}"> <input type="hidden" name="id" value="${computer.id}">
<label for="name">Name: </label><br> <label for="name">名称: </label><br>
<input type="text" id="name" name="name" value="${computer.name}"><br><br> <input type="text" id="name" name="name" value="${computer.name}"><br><br>
<label for="price">Price: </label><br> <label for="price">价格: </label><br>
<input type="text" id="price" name="price" value="${computer.price}"><br><br> <input type="text" id="price" name="price" value="${computer.price}"><br><br>
<label for="stock">Stock: </label><br> <label for="stock">库存: </label><br>
<input type="text" id="stock" name="stock" value="${computer.stock}"><br><br> <input type="text" id="stock" name="stock" value="${computer.stock}"><br><br>
<input type="submit" value="Update Computer"> <input type="submit" value="提交修改">
</form> </form>
<br> <br>
<a href="/computerList">Back to List</a> <a href="/computerList">返回电脑列表</a>
</body> </body>
</html> </html>

View File

@ -4,19 +4,28 @@
<body> <body>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script> <script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<h2>电脑商城-首页</h2> <h2>电脑商城-首页</h2>
<p>你好!${sessionScope.user.username}</p>
<c:if test="${sessionScope.user!= null}"> <c:if test="${sessionScope.user!= null}">
<a href="/computerList">电脑列表</a> <a href="/computerList">电脑选购</a>
<a href="/user?action=list">用户列表</a> <c:if test="${sessionScope.user.role == 'user'}">
<a href="/cart?action=list">我的购物车</a> <a href="/cart?action=list">我的购物车</a>
<a href="/orders?action=all">所有订单</a>
<a href="/logout">注销登录</a>
<a href="/orders?action=my">我的订单</a> <a href="/orders?action=my">我的订单</a>
</c:if> </c:if>
<c:if test="${sessionScope.user.role == 'admin'}">
<a href="/user?action=list">用户列表</a>
<a href="/orders?action=all">所有订单</a>
</c:if>
<a href="/logout">注销登录</a>
</c:if>
<c:if test="${sessionScope.user == null}"> <c:if test="${sessionScope.user == null}">
<p>请登录后查看更多内容~</p> <p>请登录后查看更多内容~</p>
<br> <br>
<a href="/register">注册</a> <a href="/register">注册</a>
<a href="/login">登录</a> <a href="/login">登录</a>
</c:if> </c:if>
</body> </body>
</html> </html>

View File

@ -3,6 +3,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>我的订单</title> <title>我的订单</title>
@ -22,7 +23,6 @@
<th>总金额</th> <th>总金额</th>
<th>地址</th> <th>地址</th>
<th>商品信息</th> <th>商品信息</th>
<th>操作</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -34,9 +34,6 @@
<td>${order.totalPrice}</td> <td>${order.totalPrice}</td>
<td>${order.address}</td> <td>${order.address}</td>
<td>${order.remark}</td> <td>${order.remark}</td>
<td>
<a href="/orders?action=delete&id=${order.id}">删除</a>
</td>
</tr> </tr>
</c:forEach> </c:forEach>
</tbody> </tbody>

View File

@ -3,6 +3,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>订单列表</title> <title>订单列表</title>

View File

@ -3,6 +3,7 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>操作结果</title> <title>操作结果</title>

View File

@ -3,12 +3,13 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<script src="https://www.liyansheng.top/cdn/watermark.js"></script>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>user List</title> <title>系统用户</title>
</head> </head>
<body> <body>
<h1>user List</h1> <h1>系统用户</h1>
<table border="1"> <table border="1">
<thead> <thead>
<tr> <tr>
@ -25,10 +26,9 @@
<td>${user.id}</td> <td>${user.id}</td>
<td>${user.username}</td> <td>${user.username}</td>
<td>${user.phone}</td> <td>${user.phone}</td>
<td>${user.admin}</td> <td>${user.role}</td>
<td> <td>
<a href="/edituser?id=${user.id}">Edit</a> | <a href="javascript:void(0)" >Delete</a>
<a href="/deleteuser?id=${user.id}">Delete</a>
</td> </td>
</tr> </tr>
</c:forEach> </c:forEach>