代码展示
Dao层实现
UserDaoImpl
package org.lyl.taobao.dao.impl;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.dao.IUserDao;
import java.sql.*;
public class UserDaoImpl implements IUserDao {
@Override
public boolean insertUser(User user) throws SQLException {
boolean x = true;
Connection conn = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
String sql = "insert into user values(null,?,?,?)";
String sql1 = "select * from user";
java.sql.Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql1);
while (rs.next()) {
String name = rs.getString("uername");
if (name.equals(user.getUserName())) {
x = false;
}
}
if (x==true) {
PreparedStatement pst = null;
pst = conn.prepareStatement(sql);
pst.setString(1, user.getUserName());
pst.setString(2, user.getUserPassword());
pst.setString(3, user.getPhone());
int len = pst.executeUpdate();
if (len>0){
return true;
}
}
return false;
}
@Override
public boolean change(User user) throws ClassNotFoundException {
Class.forName("com.mysql.cj.jdbc.Driver");
try {
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob", "root", "asd.123");
String sql = "select * from user";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()){
String name = rs.getString("uername");
String phone = rs.getString("phone");
if (name.equals(user.getUserName())&&phone.equals(user.getPhone())){
String sql1 = "UPDATE user SET PASSWORD=? WHERE uername=?";
PreparedStatement ps = conn.prepareStatement(sql1);
ps.setString(1,user.getUserPassword());
ps.setString(2,user.getUserName());
ps.execute();
return true;
}
}
} catch (Exception e ) {
e.printStackTrace();
return false;
}
return false;
}
public static int uid;
@Override
public boolean register(User user) {
try {
Shoping shoping = new Shoping();
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
String sql = "select * from user";
java.sql.Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()){
String paw = rs.getString("password");
String name = rs.getString("uername");
int id = rs.getInt("id");
if (paw.equals(user.getUserPassword())&&name.equals(user.getUserName())){
uid = id;
return true;
}
}
rs.close();
st.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean delete(User user) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
String sql = "delete from user where uername=?";
String sql1 = "select * from user";
String sql2 = "delete from shopping where uid=?";
java.sql.Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql1);
PreparedStatement pr = conn.prepareStatement(sql);
PreparedStatement pr1 = conn.prepareStatement(sql2);
while (rs.next()){
String name = rs.getString("uername");
String password = rs.getString("password");
if (name.equals(user.getUserName())&&password.equals(user.getUserPassword())) {
pr.setString(1,name);
pr1.setInt(1,uid);
pr.execute();
pr1.execute();
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return false;
}
}
IUserDao
package org.lyl.taobao.dao;
import org.lyl.taobao.api.entity.User;
import java.sql.SQLException;
public interface IUserDao {
boolean insertUser(User user) throws SQLException;
boolean change(User user) throws ClassNotFoundException;
boolean register(User user);
boolean delete(User user);
}
ShoppingDaoImpl
package org.lyl.taobao.dao.impl;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.dao.IShoppingDao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class ShoppingDaoImpl implements IShoppingDao {
@Override
public boolean commodity(Shoping shoping) {
boolean z = false;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
String sql = "insert into shopping values(null,?,?,?,?,?)";
String sql1 = "select * from shopping";
String sql2 = "update shopping set num = ? where name = ?";
PreparedStatement pst = conn.prepareStatement(sql);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql1);
while (rs.next()) {
String name = rs.getString("name");
int uid = rs.getInt("uid");
int num = rs.getInt("num");
if (name.equals(shoping.getName())&&uid==UserDaoImpl.uid){
num ++;
PreparedStatement ps = conn.prepareStatement(sql2);
ps.setInt(1,num);
ps.setString(2,shoping.getName());
ps.execute();
z = true;
return true;
}
}
if (z!=true){
pst.setString(1,shoping.getName());
pst.setString(2,shoping.getInformation());
pst.setInt(3,shoping.getPrice());
pst.setInt(4,shoping.getNum());
pst.setInt(5,UserDaoImpl.uid);
}
int len = pst.executeUpdate();
if (len>0){
return true;
}
pst.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return false;
}
public static int x = 0;
@Override
public List<Shoping> query() {
List<Shoping> list = new ArrayList<>();
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
String sql = "select * from shopping";
java.sql.Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql);
while (rs.next()){
int uid = rs.getInt("uid");
if (uid==UserDaoImpl.uid){
int id = rs.getInt("id");
String name = rs.getString("name");
String information = rs.getString("information");
int price = rs.getInt("price");
int num = rs.getInt("num");
Shoping shoping = new Shoping(id,name,information,price,num);
list.add(shoping);
x += price*num;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
@Override
public boolean delet(Shoping shoping) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
String sql = "delete from shopping where id=?";
String sql1 = "select * from shopping";
java.sql.Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql1);
PreparedStatement pr = conn.prepareStatement(sql);
while (rs.next()){
int id = rs.getInt("id");
int uid = rs.getInt("uid");
if (shoping.getId()==id&&uid==UserDaoImpl.uid) {
pr.setInt(1,id);
pr.execute();
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
return false;
}
return false;
}
@Override
public boolean clear(Shoping shoping) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
String sql = "delete from shopping where uid =?";
String sql1 = "select * from shopping";
PreparedStatement pr = conn.prepareStatement(sql);
java.sql.Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql1);
while (rs.next()){
int uid = rs.getInt("uid");
if (UserDaoImpl.uid==uid) {
pr.setInt(1,uid);
pr.execute();
return true;
}
}
pr.execute();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
@Override
public boolean update(Shoping shoping) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/runoob","root","asd.123");
String sql1 = "select * from shopping";
String sql2 = "update shopping set num = ? where id = ?";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(sql1);
while (rs.next()){
int id = rs.getInt("id");
int uid = rs.getInt("uid");
int num = rs.getInt("num");
if (id==shoping.getId()&&uid==UserDaoImpl.uid){
num--;
if (num==0){
return false;
}else {
PreparedStatement ps = conn.prepareStatement(sql2);
ps.setInt(1, num);
ps.setInt(2, id);
ps.execute();
}
}
}
rs.close();
st.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
Dao层接口
package org.lyl.taobao.dao;
import org.lyl.taobao.api.entity.Shoping;
import java.util.List;
public interface IShoppingDao {
boolean commodity(Shoping shoping);
List<Shoping> query();
boolean delet(Shoping shoping);
boolean clear(Shoping shoping);
boolean update(Shoping shoping);
}
Service层接口
package org.lyl.taobao.api;
import org.lyl.taobao.api.entity.User;
import java.sql.SQLException;
public interface IUserService {
boolean insertUser(User user) throws SQLException;
boolean change(User user) throws ClassNotFoundException;
boolean register(User user);
boolean delete (User user);
}
IShoppingService
package org.lyl.taobao.api;
import org.lyl.taobao.api.entity.Shoping;
import java.util.List;
public interface IShoppingService {
boolean commodity(Shoping shoping);
List<Shoping> query();
boolean delet(Shoping shoping);
boolean clear(Shoping shoping);
boolean update(Shoping shoping);
}
Service层实现
UserServiceImpl
package org.lyl.taobao.service;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.dao.IUserDao;
import org.lyl.taobao.dao.impl.UserDaoImpl;
import java.sql.SQLException;
public class UserServiceImpl implements IUserService {
@Override
public boolean insertUser(User user) throws SQLException {
IUserDao iUserDao = new UserDaoImpl();
return iUserDao.insertUser(user);
}
@Override
public boolean change(User user) throws ClassNotFoundException {
IUserDao iUserDao = new UserDaoImpl();
return iUserDao.change(user);
}
@Override
public boolean register(User user) {
IUserDao iUserDao = new UserDaoImpl();
return iUserDao.register(user);
}
@Override
public boolean delete(User user) {
IUserDao iUserDao = new UserDaoImpl();
return iUserDao.delete(user);
}
}
ShoppingServiceImpl
package org.lyl.taobao.service;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.dao.IShoppingDao;
import org.lyl.taobao.dao.impl.ShoppingDaoImpl;
import java.util.List;
public class ShoppingServiceImpl implements IShoppingService {
@Override
public boolean commodity(Shoping shoping) {
IShoppingDao iShoppingDao = new ShoppingDaoImpl();
return iShoppingDao.commodity(shoping);
}
@Override
public List<Shoping> query() {
IShoppingDao iShoppingDao = new ShoppingDaoImpl();
return iShoppingDao.query();
}
@Override
public boolean delet(Shoping shoping) {
IShoppingDao iShoppingDao = new ShoppingDaoImpl();
return iShoppingDao.delet(shoping);
}
@Override
public boolean clear(Shoping shoping) {
IShoppingDao iShoppingDao = new ShoppingDaoImpl();
return iShoppingDao.clear(shoping);
}
@Override
public boolean update(Shoping shoping) {
IShoppingDao iShoppingDao = new ShoppingDaoImpl();
return iShoppingDao.update(shoping);
}
}
实体层
User
package org.lyl.taobao.api.entity;
public class User {
private String userName;
private String userPassword;
private String phone;
public User(String userName, String userPassword, String phone) {
this.userName = userName;
this.userPassword = userPassword;
this.phone = phone;
}
public User(String userName, String userPassword) {
this.userName = userName;
this.userPassword = userPassword;
}
public String getUserName() {
return userName;
}
public String getPhone() {
return phone;
}
public String getUserPassword() {
return userPassword;
}
@Override
public String toString() {
return "User{" +
"userName='" + userName + '\'' +
", userPassword='" + userPassword + '\'' +
", phone=" + phone +
'}';
}
}
Shoping
package org.lyl.taobao.api.entity;
public class Shoping {
private int id;
private String name;
private String information;
private int price;
private int num;
private int uid;
public Shoping() {
}
public Shoping(String name, String information, int price, int num) {
this.name = name;
this.information = information;
this.price = price;
this.num = num;
}
public Shoping(String name, String information, int price) {
this.name = name;
this.information = information;
this.price = price;
}
public Shoping(int id) {
this.id = id;
}
public Shoping(int id, String name, String information, int price, int num) {
this.id = id;
this.name = name;
this.information = information;
this.price = price;
this.num = num;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getInformation() {
return information;
}
public int getPrice() {
return price;
}
public int getNum() {
return num;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
@Override
public String toString() {
return "Shooping{" +
"name='" + name + '\'' +
", information='" + information + '\'' +
", price=" + price +
", num=" + num +
'}';
}
}
Controller层
ChangeServlet
package org.lyl.taobao.controller;
import lombok.SneakyThrows;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/change")
public class ChangeServlet extends HttpServlet {
static boolean x ;
@SneakyThrows
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;utf-8");
String name = req.getParameter("uname");
String paw = req.getParameter("upaw");
String num = req.getParameter("phone");
if (name==""||paw==""||num==""){
req.setAttribute("msg","输入的值不能为空!!!");
req.getRequestDispatcher("change.jsp").forward(req,resp);
}else {
User user1 = new User(name,paw,num);
IUserService iUserService = new UserServiceImpl();
x = iUserService.change(user1);
resp.sendRedirect("panduan1.jsp");
}
}
public static boolean x() {
return x;
}
}
ClearServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.service.ShoppingServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/clear")
public class ClearServlet extends HttpServlet {
public static boolean x;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;utf-8");
Shoping shoping = new Shoping();
IShoppingService iShoppingService = new ShoppingServiceImpl();
x = iShoppingService.clear(shoping);
if (x){
resp.sendRedirect("shopping.jsp");
}
}
}
CommodityServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.service.ShoppingServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/com")
public class CommodityServlet extends HttpServlet {
static boolean x;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;utf-8");
String name = req.getParameter("names");
String information = req.getParameter("informations");
int price = Integer.parseInt(req.getParameter("prices"));
int num = Integer.parseInt(req.getParameter("num"));
Shoping shoping1 = new Shoping(name,information,price,num);
IShoppingService iShoppingService = new ShoppingServiceImpl();
x = iShoppingService.commodity(shoping1);
resp.sendRedirect("panduan3.jsp");
}
public static boolean x(){
return x;
}
}
DeletServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.service.ShoppingServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/del")
public class DeletServlet extends HttpServlet {
static boolean x;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;utf-8");
int id = Integer.parseInt(req.getParameter("id"));
Shoping shoping = new Shoping(id);
IShoppingService iShoppingService = new ShoppingServiceImpl();
x =iShoppingService.delet(shoping);
resp.sendRedirect("panduan2.jsp");
}
public static boolean x(){
return x;
}
}
InsertUserServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/insertUser")
public class InsertUserServlet extends HttpServlet {
static boolean x;
@lombok.SneakyThrows
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;utf-8");
String name = req.getParameter("names");
String paw = req.getParameter("paw");
String num = req.getParameter("num");
if (name==""||paw==""||num==""){
req.setAttribute("msg","输入的值不能为空!!!");
req.getRequestDispatcher("login.jsp").forward(req,resp);
}else {
User user = new User(name,paw,num);
IUserService iUserService = new UserServiceImpl();
x = iUserService.insertUser(user);
resp.sendRedirect("panduan4.jsp");
}
}
public static boolean x() {
return x;
}
}
LogoutServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/lout")
public class LogoutServlet extends HttpServlet {
public static boolean x;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;utf-8");
String password = req.getParameter("password");
User user = new User(RegisterServlet.name1,password);
IUserService iUserService = new UserServiceImpl();
x = iUserService.delete(user);
if (x){
resp.sendRedirect("index.jsp");
}else {
req.setAttribute("msg","密码错误,注销失败!!!");
req.getRequestDispatcher("logout.jsp").forward(req,resp);
}
}
}
QueryServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.service.ShoppingServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@WebServlet("/que")
public class QueryServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;utf-8");
HttpSession session = req.getSession();
IShoppingService iShoppingService = new ShoppingServiceImpl();
List<Shoping> shopings = iShoppingService.query();
session.setAttribute("shop",shopings);
resp.sendRedirect("shopping.jsp");
}
}
RegisterServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IUserService;
import org.lyl.taobao.api.entity.User;
import org.lyl.taobao.service.UserServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/enter")
public class RegisterServlet extends HttpServlet {
static boolean x;
public static String name1;
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;utf-8");
HttpSession session = req.getSession();
String name = req.getParameter("uname");
String paw = req.getParameter("upaw");
if (name==""||paw==""){
req.setAttribute("msg","输入的值不能为空!!!");
req.getRequestDispatcher("enter.jsp").forward(req,resp);
}else {
session.setAttribute("uname",name);
name1 = name;
User user2 = new User(name,paw);
IUserService iUserService = new UserServiceImpl();
x = iUserService.register(user2);
resp.sendRedirect("panduan.jsp");
}
}
public static boolean rgs(){
return x;
}
}
UpdatenumServlet
package org.lyl.taobao.controller;
import org.lyl.taobao.api.IShoppingService;
import org.lyl.taobao.api.entity.Shoping;
import org.lyl.taobao.service.ShoppingServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@WebServlet("/update")
public class UpdatenumServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
resp.setContentType("text/html;utf-8");
IShoppingService iShoppingService = new ShoppingServiceImpl();
int id = Integer.parseInt(req.getParameter("id"));
Shoping shoping = new Shoping(id);
boolean x= iShoppingService.update(shoping);
if (x){
HttpSession session = req.getSession();
List<Shoping> shopings = iShoppingService.query();
session.setAttribute("shop",shopings);
resp.sendRedirect("shopping.jsp");
}else {
iShoppingService.delet(shoping);
HttpSession session = req.getSession();
List<Shoping> shopings = iShoppingService.query();
session.setAttribute("shop",shopings);
resp.sendRedirect("shopping.jsp");
}
}
}
前端html
change.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>更改信息</title>
</head>
<body>
<h2>欢迎来到更改用户密码页面</h2>
<form action="/change" method="post">
请输入用户名:<input type="text" name="uname"><br>
请输入注册手机号:<input type="text" name="phone"><br>
请输入新密码:<input type="password" name="upaw"><br>
<button>确定修改</button>
</form>
<form action="enter.jsp" method="post">
<button>取消修改</button>
</form>
${msg}
</body>
</html>
commod.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
<link rel="stylesheet" href="commodity.css">
</head>
<body>
<h2>欢迎来到购物页面</h2>
<div class="bax w" id="5">
<div class="gowu1">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/bao/upload/O1CN010yGEVn1vtqXpTwABQ_!!6000000006231-2-yinhe.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">三只松鼠手撕面包1kg整箱网红零食礼包早餐休闲食品蛋糕点心吐司</div>
<div class="floor-price">¥29</div>
<form class="zong" action="com" method="post">
<input type="hidden" value="三只松鼠手撕面包" name="names">
<input type="hidden" value="1kg整箱网红零食礼包早餐休闲食品蛋糕点心吐司" name="informations">
<input type="hidden" value="29" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
<div class="gowu1">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/bao/upload/O1CN01slUasP1gTzxMU8bId_!!6000000004144-2-yinhe.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">可优比儿童滑板车1-3-6岁宝宝踏板12岁小孩单脚滑滑车2宽轮溜溜车</div>
<div class="floor-price">¥238.0</div>
<form class="zong" action="com" method="post">
<input type="hidden" value="可优比儿童滑板车" name="names">
<input type="hidden" value="1-3-6岁宝宝踏板12岁小孩单脚滑滑车2宽轮溜溜车" name="informations">
<input type="hidden" value="238" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
<div class="gowu1">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/i1/725677994/O1CN01WMINGM28vImwvic51_!!2-item_pic.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">威露士除菌内衣洗衣液300g专业洗内裤除螨抑菌 去血渍去异味亮白</div>
<div class="floor-price">¥37</div>
<form class="zong" action="com" method="post">
<input type="hidden" value="威露士除菌内衣洗衣液" name="names">
<input type="hidden" value="300g专业洗内裤除螨抑菌 去血渍去异味亮白" name="informations">
<input type="hidden" value="37" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
<div class="gowu1">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/i4/392147177/O1CN015TRyuD22t7E49AkSs_!!2-item_pic.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">预售【周黑鸭_锁鲜】盒装卤鸭脖鸭锁骨鸭翅鸭掌素食 多口味任选装</div>
<div class="floor-price">¥34</div>
<form class="zong" action="com" method="post">
<input type="hidden" value="鸭脖鸭锁骨鸭翅鸭掌" name="names">
<input type="hidden" value="盒装卤鸭脖鸭锁骨鸭翅鸭掌素食 多口味任选装" name="informations">
<input type="hidden" value="34" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
<div class="gowu1">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/bao/upload/TB18OBMjIKfxu4jSZPfXXb3dXXa.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">维达手帕纸超韧4层8张18包卫生纸巾 自然无香面巾纸 新旧交替发货</div>
<div class="floor-price">¥11</div>
<form class="zong" action="com" method="post">
<input type="hidden" value=">维达手帕纸" name="names">
<input type="hidden" value="超韧4层8张18包卫生纸巾 自然无香面巾纸 新旧交替发货" name="informations">
<input type="hidden" value="11" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
<div class="gowu2">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/bao/upload/O1CN01uCASei1EomgiiUqJB_!!6000000000399-2-yinhe.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">良品铺子坚果零食大礼包送礼混合坚果小包装干果食品坚果礼盒整箱</div>
<div class="floor-price">¥108.0</div>
<form class="zong" action="com" method="post">
<input type="hidden" value="良品铺子坚果零食大礼包" name="names">
<input type="hidden" value="送礼混合坚果小包装干果食品坚果礼盒整箱" name="informations">
<input type="hidden" value="108" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
<div class="gowu1">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/bao/upload/O1CN01mVxyRv1KShHqCAbfp_!!6000000001163-2-yinhe.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">百草味-零食大礼包 网红爆款休闲充饥夜宵小吃饼干组合一整箱送礼</div>
<div class="floor-price">¥49</div>
<form class="zong" action="com" method="post">
<input type="hidden" value="百草味-零食大礼包" name="names">
<input type="hidden" value="网红爆款休闲充饥夜宵小吃饼干组合一整箱送礼" name="informations">
<input type="hidden" value="49" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
<div class="gowu1">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/bao/upload/TB1YmPsH1L2gK0jSZPhXXahvXXa.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">维达无芯卷纸超韧4层78克10卷(中棒)卫生纸巾 厕纸手纸家用实惠装</div>
<div class="floor-price">¥39</div>
<form class="zong" action="com" method="post">
<input type="hidden" value="维达无芯卷纸" name="names">
<input type="hidden" value="4层78克10卷(中棒)卫生纸巾 厕纸手纸家用实惠装" name="informations">
<input type="hidden" value="39" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
<div class="gowu1">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/bao/upload/TB1_gzhHYr1gK0jSZR0XXbP8XXa.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">Walch/威露士倍护滋润抑菌洗手液525ml抵御干燥 怡人清香清香型</div>
<div class="floor-price">¥20.0</div>
<form class="zong" action="com" method="post">
<input type="hidden" value="威露士倍护滋润抑菌洗手液" name="names">
<input type="hidden" value="525ml抵御干燥 怡人清香清香型" name="informations">
<input type="hidden" value="20" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
<div class="gowu2">
<div class="wupin">
<img src="//img.alicdn.com/bao/uploaded/bao/upload/O1CN01qwpuRZ1msAYGtSH9P_!!6000000005009-2-yinhe.png_400x400q60.jpg" alt="">
</div>
<div class="floor-item-title">三只松鼠芒果干88g零食蜜饯果脯果干网红休闲办公室零食小吃特产</div>
<div class="floor-price">¥20.0</div>
<form class="zong" action="com" method="post">
<input type="hidden" value="三只松鼠芒果干" name="names">
<input type="hidden" value="88g零食蜜饯果脯果干网红休闲办公室零食小吃特产" name="informations">
<input type="hidden" value="20" name="prices">
<input type="hidden" value="1" name="num">
<button>确定购买</button>
</form>
</div>
</div>
<form action="/que" method="post">
<button>查看购物车</button>
</form>
<form action="enter.jsp" method="post">
<button>切换登录</button>
</form>
<form action="logout.jsp" method="post">
<button>注销账户</button>
</form>
</body>
</html>
delete.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>删除订单</title>
</head>
<body>
<form action="del" method="post">
请输入要删除订单id:<input type="text" name="id">
<button>确定删除</button>
</form>
<form action="enter.jsp" method="post">
<button>切换登录</button>
</form>
</body>
</html>
enter.jsp
<%@ page import="org.lyl.taobao.controller.RegisterServlet" %><%--
Created by IntelliJ IDEA.
User: jijunxiang
Date: 2021/4/14
Time: 9:05
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>登录页面</title>
</head>
<body>
<h2>欢迎来到登录页面!!!</h2>
<form action="enter" method="post">
请输入用户名:<input type="text" name="uname"> <br>
请输入密码:<input type="password" name="upaw">
<button>登录</button>
</form>
<form action="change.jsp" method="post">
<button>修改密码</button>
</form>
<form action="login.jsp" method="post">
<button>注册账号</button>
</form>
${msg}
</body>
</html>
index.jsp
<%@ page import="org.lyl.taobao.controller.LogoutServlet" %><%--
Created by IntelliJ IDEA.
User: jijunxiang
Date: 2021/4/10
Time: 15:23
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>主页面</title>
</head>
<body>
<%
if (LogoutServlet.x == false){
}else {
out.print("<script>alert(\"注销成功,请重新登录\")</script>");
}
%>
<h2>欢迎来到主页!!!</h2>
<h4>请选择服务!!!</h4>
<form action="login.jsp" method="post">
<button>注册</button>
</form>
<form action="enter.jsp" method="post">
<button>登录</button>
</form>
</body>
</html>
login.jsp
<html>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<body>
<header>
</header>
<h2>欢迎来到注册页面!!!</h2>
<form action="/insertUser" method="post">
用户名:<input type="text" name="names">
密码:<input type="password" name="paw">
手机号:<input type="text" name="num">
<button>注册</button>
</form>
${msg}
</body>
</html>
logout.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>Title</title>
</head>
<body>
<form action="/lout" method="post">
请输入密码:<input type="password" name="password">
<button>确定注销</button>
</form>
${msg}
</body>
</html>
panduan.jsp
<%@ page import="org.lyl.taobao.controller.RegisterServlet" %><%--
Created by IntelliJ IDEA.
User: jijunxiang
Date: 2021/4/14
Time: 16:33
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
if (RegisterServlet.rgs() ==true){
response.sendRedirect("commodity.jsp");
}else {
out.print("<script>alert(\"您输入的用户名或密码有误请重新输入!!!\")</script>");
}
%>
<form action="enter.jsp" method="post">
<button>重新登录</button>
</form>
</body>
</html>
panduan1.jsp
<%@ page import="org.lyl.taobao.controller.ChangeServlet" %><%--
Created by IntelliJ IDEA.
User: jijunxiang
Date: 2021/4/14
Time: 18:46
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
if (ChangeServlet.x() ==true){
out.print("<script>alert(\"修改成功!!!\")</script>");
}else {
out.print("<script>alert(\"您输入的用户名或手机号有误请重新输入!!!\")</script>");
}
%>
<form action="enter.jsp" method="post">
<button>登录</button>
</form>
<form action="change.jsp" method="post">
<button>继续修改</button>
</form>
<form action="login.jsp" method="post">
<button>重新注册</button>
</form>
</body>
</html>
panduan2.jsp
<%@ page import="org.lyl.taobao.controller.DeletServlet" %><%--
Created by IntelliJ IDEA.
User: jijunxiang
Date: 2021/4/14
Time: 18:53
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>判断</title>
</head>
<body>
<%
if (DeletServlet.x() ==true){
out.print("<script>alert(\"删除成功\")</script>");
}else {
out.print("<script>alert(\"删除失败\")</script>");
}
%>
<form action="/que" method="post">
<button>查看购物车</button>
</form>
<form action="commodity.jsp" method="post">
<button>继续购物</button>
</form>
<form action="enter.jsp" method="post">
<button>切换登录</button>
</form>
</body>
</html>
panduan3.jsp
<%@ page import="org.lyl.taobao.controller.CommodityServlet" %><%--
Created by IntelliJ IDEA.
User: jijunxiang
Date: 2021/4/14
Time: 18:56
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
if (CommodityServlet.x() ==true){
out.print("<script>alert(\"购买成功\")</script>");
}else {
out.print("<script>alert(\"因部分原因购买失败\")</script>");
}
%>
<form action="commodity.jsp" method="post">
<button>继续购物</button>
</form>
<form action="/que" method="post">
<button>查看购物车</button>
</form>
<form action="enter.jsp" method="post">
<button>切换登录</button>
</form>
</body>
</html>
panduan4.jsp
<%@ page import="org.lyl.taobao.controller.InsertUserServlet" %><%--
Created by IntelliJ IDEA.
User: jijunxiang
Date: 2021/4/14
Time: 19:30
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<%
if (InsertUserServlet.x() ==true){
out.print("<script>alert(\"注册成功!!!\")</script>");
}else {
out.print("<script>alert(\"注册账号已存在!!!\")</script>");
}
%>
<form action="login.jsp" method="post">
<button>重新注册</button>
</form>
<form action="enter.jsp" method="post">
<button>登录</button>
</form>
<form action="change.jsp" method="post">
<button>修改密码</button>
</form>
</body>
</html>
shopping.jsp
<%@ page import="org.lyl.taobao.dao.impl.ShoppingDaoImpl" %>
<%@ page import="org.lyl.taobao.controller.ClearServlet" %>
<%@ page import="org.lyl.taobao.api.entity.Shoping" %>
<%@ page import="java.util.List" %><%--
Created by IntelliJ IDEA.
User: jijunxiang
Date: 2021/4/14
Time: 16:25
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<title>购物车</title>
</head>
<body>
<%--<%--%>
<%-- IShoppingDao iShoppingDao = new ShoppingDaoImpl();--%>
<%-- List list1 = iShoppingDao.queryid();--%>
<%-- int i = 0;--%>
<%-- for (Object list : QueryServlet.list()){--%>
<%-- out.print(list);--%>
<%-- request.setAttribute("list",list1.get(i));--%>
<%-- i++;--%>
<%--%>--%>
<%--<form action="del" method="post">--%>
<%-- <input type="hidden" value="${list}" name="id">--%>
<%-- <button>删除订单</button>--%>
<%--</form>--%>
<%--<form action="/update" method="post">--%>
<%-- <input type="hidden" value="${list}" name="id">--%>
<%-- <button>-</button>--%>
<%--</form>--%>
<%--<br>--%>
<%--<%--%>
<%-- }--%>
<%-- i = 0;--%>
<%--%>--%>
<%
List<Shoping> list = (List<Shoping>) session.getAttribute("shop");
request.setAttribute("shopList",list);
%>
<c:if test="${!empty shopList}">
<table align="center" width="800" border="1" style="border-collapse: collapse">
<tr>
<th>商品名称</th>
<th>商品信息</th>
<th>商品价格</th>
<th>商品数量</th>
<th>选择服务</th>
</tr>
<c:forEach items="${shopList}" var="shop1">
<tr>
<td>${shop1.name}</td>
<td>${shop1.information}</td>
<td>${shop1.price}</td>
<td>${shop1.num}</td>
<td><form action="del" method="post">
<input type="hidden" value="${shop1.id}" name="id">
<button>删除订单</button>
</form>
<form action="/update" method="post">
<input type="hidden" value="${shop1.id}" name="id">
<button>-</button>
</form></td>
</tr>
</c:forEach>
</c:if>
<h1>
总价格为 :<%
out.println(ShoppingDaoImpl.x);
ShoppingDaoImpl.x = 0;
%>
</h1>
<form action="commodity.jsp" method="post">
<button>继续购物</button>
</form>
<form action="/clear" method="post">
<button>清空订单</button>
</form>
<form action="enter.jsp" method="post">
<button>切换登录</button>
</form>
<%
if (ClearServlet.x ==true){
out.print("<script>alert(\"清除成功\")</script>");
ClearServlet.x=false;
}
%>
</body>
</html>
css
.gowu1 {
background-color: #fff;
width: 234px;
height: 300px;
float: left;
margin-right: 14px;
margin-bottom: 14px;
}
.gowu1:hover {
box-shadow: 10px 10px 10px -4px rgba(0,0,0,0.3);
}
.wupin {
margin-top: 12px;
text-align: center;
}
.wupin img {
width: 185px;
height: 185px;
}
.bax {
background-color: #f5f5f5;
margin-top: 50px;
width: 1226px;
height: 615px;
}
.floor-item-title {
width: 135px;
height: 40px;
font-size: 14px;
color: #333;
line-height: 20px;
overflow: hidden;
margin: 8px auto;
}
.floor-price {
font-size: 18px;
color: #FF0036;
line-height: 18px;
text-align: center;
margin-top: 10px;
}
.zong {
text-align: center;
}
.w {
width: 1226px;
margin: 0 auto;
}
.gowu2 {
background-color: #fff;
width: 234px;
height: 300px;
float: left;
margin-bottom: 14px;
}
.gowu2:hover {
box-shadow: 10px 10px 10px -4px rgba(0,0,0,0.3);
}