<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="${pageContext.request.contextPath}/stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.css">
<script src="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
<script src="${pageContext.request.contextPath}/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<style>
* {
outline: none !important;
}
html,
body {
height:100vh;
background: linear-gradient(aliceblue,black);
}
form {
width: 300px;
background: #ebeff2;
box-shadow: 0px 0px 50px rgba(0, 0, 0, .5);
border-radius: 5px;
padding: 20px;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
box-shadow: 0 18px 28px 0 #628082;
}
.btn-group {
width: 100%;
}
.btn-group button {
width: 50%;
}
</style>
</head>
<body>
<form action="dologin.jsp" method="post">
<h3 align="center" class="text-center" style="text-shadow: 2px 2px 1px #ed3f3f;">欢迎来到星星旗舰店</h3>
<div class="form-group" align="center">
<input name="account" type="text" class="form-control" placeholder="请输入您的用户名">
</div>
<div class="form-group" align="center">
<input name="pwd" type="password" class="form-control" placeholder="请输入您的密码">
</div>
<div class="btn-group" align="center">
<button type="submit" class="btn btn-primary">登录</button>
<button type="button" class="btn btn-danger">没有账号?</button>
</div>
</form>
</body></html>
<%@page import="com.zking.pojo.user"%>
<%@page import="com.zking.biz.Impl.UserbizImpl"%>
<%@page import="com.zking.biz.IUserbiz"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String account=request.getParameter("account");
String pwd=request.getParameter("pwd");
IUserbiz userbiz=new UserbizImpl();
user user=userbiz.login(new user(1,account,pwd));
if(user==null){
response.sendRedirect("login.jsp");
}else{
session.setAttribute("user", user);//将user放到session储存里去
response.sendRedirect("index.jsp");
}
%>
<%@page import="com.zking.pojo.user"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.css">
<script src="bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
<script src="bootstrap-3.3.7-dist/js/bootstrap.js"></script>
<style>
td:nth-child(3)::before{
content: "$";
}
</style>
</head>
<body>
<%
Object obj=session.getAttribute("user");
if(obj==null){
response.sendRedirect("login.jsp");
return;
}
%>
<div class="jumbotron">
<div class="container">
<h1>欢迎来到星星旗舰店</h1>
<p >尊贵的<%=((user)obj).getUser_account()%></p>
<button>购物车</button>
</div>
</div>
<table class="table">
<tr>
<th>商品序号</th>
<th>商品名称</th>
<th>商品单价</th>
<th>商品描述</th>
<th>商品图片</th>
<th>操作</th>
</tr>
<tr>
<td>1</td>
<td>mp4</td>
<td>199.9</td>
<td>卓越画质</td>
<td><img src="" alt=""></td>
<td>
<div class="btn-group btn-group-xs">
<button class="btn btn-primary"><span class="glyphicon glyphicon-tags"></span></button>
<button class="btn btn-primary">添加购物车</button>
</div>
</td>
</tr>
</table>
</body></html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
Document
欢迎光临胡阿玛购物车
尊贵的xxx
商品序号
商品名称
商品个数
商品总价
操作
1
mp4
199.9
1
mp4
199.9
1
mp4
199.9
1
mp4
199.9
当前购物车总价
110
package com.zking.pojo;
public class user{
private Integer user_id;
private String user_account;
private String user_password;
public Integer getUser_id() {
return user_id;
}
public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
public String getUser_account() {
return user_account;
}
public void setUser_account(String user_account) {
this.user_account = user_account;
}
public String getUser_password() {
return user_password;
}
public void setUser_password(String user_password) {
this.user_password = user_password;
}
public user() {
// TODO Auto-generated constructor stub
}
public user(Integer user_id, String user_account, String user_password) {
super();
this.user_id = user_id;
this.user_account = user_account;
this.user_password = user_password;
}
@Override
public String toString() {
return "user [user_id=" + user_id + ", user_account=" + user_account + ", user_password=" + user_password + "]";
}
}
package com.zking.util;
import oracle.jdbc.driver.OracleDriver;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class DBHelper {
//加载驱动
static{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//定义链接字符串
private static final String URL="jdbc:oracle:thin:@localhost:1521:orcl";
//获得链接
public static Connection getCon() {
try {
return DriverManager.getConnection(URL,"scott","123");
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
//关闭资源
public static void close(Connection con,PreparedStatement ps, ResultSet rs) {
try {
if (con!=null&&!con.isClosed()) {
con.close();
}
if(ps!=null){
ps.close();
}
if(rs!=null){
rs.close();
}
}catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println(DBHelper.getCon());//测试是否连接成功
}
}
package com.test.vo;
import com.test.pojo.Goods;
public class CarItem {
private Integer count;//数量
private Double sum;//总价
private Goods goods;//对应的商品
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public Double getSum() {
return sum;
}
public void setSum(Double sum) {
this.sum = sum;
}
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public CarItem() {
// TODO Auto-generated constructor stub
}
public CarItem(Integer count, Double sum, Goods goods) {
super();
this.count = count;
this.sum = sum;
this.goods = goods;
}
@Override
public String toString() {
return "CarItem [count=" + count + ", sum=" + sum + ", goods=" + goods + "]";
}
}
package com.test.biz;
import com.test.pojo.User;
public interface IUserBiz {
User login(User user);
}
package com.test.biz;
import java.util.List;
import com.test.pojo.Goods;
public interface IGoodsBiz {
//查询所有
List<Goods> getAll();
//查询单个
Goods getOne(Integer goodsId);
}
package com.test.biz.impl;
import com.test.biz.IUserBiz;
import com.test.dao.IUserDao;
import com.test.dao.impl.UserDaoImpl;
import com.test.pojo.User;
public class UserBizImpl implements IUserBiz{
private IUserDao userDao=new UserDaoImpl();
@Override
public User login(User user) {
User use = userDao.login(user);
if(use!=null) {
return use;
}
return null;
}
}
package com.test.biz.impl;
import java.util.List;
import com.test.biz.IGoodsBiz;
import com.test.dao.IGoodsDao;
import com.test.dao.impl.GoodsDaoImpl;
import com.test.pojo.Goods;
public class GoodsBizImpl implements IGoodsBiz{
private IGoodsDao goodsDao=new GoodsDaoImpl();
/**
* 查询所有的实现方法
*/
public List<Goods> getAll() {
return goodsDao.getAll();
}
/**
* 查询单个的实现方法
*/
public Goods getOne(Integer goodsId) {
return goodsDao.getOne(goodsId);
}
}
package com.test.dao;
import com.test.pojo.User;
public interface IUserDao {
User login(User user);
}
package com.test.dao;
import java.util.List;
import com.test.pojo.Goods;
public interface IGoodsDao {
//查询所有
List<Goods> getAll();
//查询单个
Goods getOne(Integer goodsId);
}
package com.test.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.test.dao.IUserDao;
import com.test.pojo.User;
import com.test.util.DBHelper;
public class UserDaoImpl implements IUserDao{
private Connection con;
private PreparedStatement ps;
private ResultSet rs;
/**
* 登录的实现方法
*/
public User login(User user) {
try {
con = DBHelper.getCon();
ps = con.prepareStatement("SELECT * FROM SHOP_USER WHERE USER_ACCOUNT=?");
ps.setString(1, user.getUserAccount());
rs = ps.executeQuery();
if(rs.next()) {
User use=new User();
use.setUserId(user.getUserId());
use.setUserAccount(user.getUserAccount());
use.setUserPwd(user.getUserPwd());
return use;
}
} catch (Exception e) {
e.printStackTrace();
}finally {
DBHelper.close(con, ps, rs);
}
return null;
}
}
package com.test.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import com.test.dao.IGoodsDao;
import com.test.pojo.Goods;
import com.test.util.DBHelper;
public class GoodsDaoImpl implements IGoodsDao{
private Connection con;
private PreparedStatement ps;
private ResultSet rs;
/**
* 查询所有的实现方法
*/
public List<Goods> getAll() {
List<Goods> list = new ArrayList<Goods>();
try {
con = DBHelper.getCon();
ps = con.prepareStatement("SELECT * FROM SHOP_GOODS");
rs = ps.executeQuery();
while(rs.next()) {
Goods goods=new Goods();
goods.setGoodsId(rs.getInt(1));
goods.setGoodsName(rs.getString(2));
goods.setGoodsPrice(rs.getDouble(3));
goods.setGoodsInfo(rs.getString(4));
list.add(goods);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
DBHelper.close(con, ps, rs);
}
return list;
}
/**
* 查询单个的实现方法
*/
public Goods getOne(Integer goodsId) {
try {
con = DBHelper.getCon();
ps = con.prepareStatement("SELECT * FROM SHOP_GOODS WHERE GOODS_ID=?");
ps.setInt(1, goodsId);
rs = ps.executeQuery();
if(rs.next()) {
Goods goods=new Goods();
goods.setGoodsId(rs.getInt(1));
goods.setGoodsName(rs.getString(2));
goods.setGoodsPrice(rs.getDouble(3));
goods.setGoodsInfo(rs.getString(4));
return goods;
}
} catch (Exception e) {
e.printStackTrace();
}finally {
DBHelper.close(con, ps, rs);
}
return null;
}
}
谢谢浏览 点个关注再走吧!!