1.设置数据库SMS
(1)设置shopkeeper(店主)表
(2)设置goods_purchase表(商品进货表)
2.部分项目界面总览(目前)
3.jsp页面
(1)登入界面login.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
<base href="<%=basepath %>"/>
<meta charset="UTF-8">
<title>登入界面</title>
<style>
/*全局样式*/
*{margin:0;padding:0;}
body{text-align: center;}
</style>
</head>
<body>
<div>
<h1>超市登入界面</h1>
<div style="padding-top:30px;">
账号:<input type="text" id="id">
<b> <span id="span1" style="color: crimson">${error}</span></b>
</div>
<div style="padding-top:30px;">
密码:<input type="password" id="pwd">
<b> <span id="span2" style="color: crimson"></span></b>
</div>
<button id="btn1" style="margin-top:30px;">登录</button>
<button id="btn2" style="margin-left:20px;margin-top:30px;">重置</button>
<script>
window.onload=function() {
document.getElementById("btn1").onclick = function () {
let id = document.getElementById("id").value;
if (id == null || id == "") {
document.getElementById("span1").innerHTML = "用户名不能为空"
return;
}
let pwd = document.getElementById("pwd").value;
if (pwd == null || pwd == "") {
document.getElementById("span2").innerHTML = "密码不能为空"
return;
}
//跳转到servlet
window.location.href = "DianZhu?id=" + id + "&pwd=" + pwd;
}
//在次点击清空错误信息
document.getElementById("id").onfocus = function () {
document.getElementById("span1").innerText = ""
}
document.getElementById("pwd").onfocus = function () {
document.getElementById("span2").innerText = ""
}
//清空内容
document.getElementById("btn2").onclick=function () {
document.getElementById("id").value="";
document.getElementById("pwd").value="";
}
}
</script>
</div>
</body>
</html>
(2)登入之后的店主操作页面 DianZhu.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
<title>店主主功能界面</title>
<style>
/*全局样式*/
*{margin:0;padding:0;}
body{text-align: center;}
</style>
</head>
<body>
<div>
<h2>欢迎店主${user.getName()}使用</h2>
<button id="btn3" style="margin-top:20px;">商店进货管理功能</button><br>
<button id="btn4" style="margin-top:20px;">商品销售管理功能</button><br>
<button id="btn5" style="margin-top:20px;">商品库存管理功能</button><br>
<button id="btn6" style="margin-top:20px;">损坏商品管理功能</button><br>
<button id="btn7" style="margin-top:20px;">会员顾客管理功能</button><br>
<button id="btn8" style="margin-top:20px;">员工管理功能</button><br>
<script>
window.onload=function() {
document.getElementById("btn3").onclick = function (){
window.location.href = "JinHuo.jsp";
}
document.getElementById("btn4").onclick = function (){
//window.location.href = "XiaoShou";
}
document.getElementById("btn5").onclick = function (){
//window.location.href = "KuCun";
}
document.getElementById("btn6").onclick = function (){
//window.location.href = "SunHuai";
}
}
</script>
</div>
</body>
</html>
(3)设置店主的商品进货管理功能 JinHuo.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<%--JSTL语法,可以使用user.getName()方法--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta charset="UTF-8">
<title>商品进货管理</title>
<style>
/*全局样式*/
*{margin:0;padding:0;}
body{text-align: center;}
#search{
height: 70px;
width: 100%;
background-color: aqua;
}
#inner_s{
width: 30%;
padding-top:25px;
padding-left: 45%;
}
#table{
margin-left: 30%;
margin-top: 30px;
}
td{
text-align: center;
height: 20px;
width: 150px;
border: darkcyan 2px solid;
padding:6px;
}
</style>
</head>
<body>
<div>
<div id="search">
<div id="inner_s">
<input type="text" style="font-size: 20px; height: 26px;width: 190px " id="fileId" placeholder="请输入你要操作的进货编号">
<button style="font-size: 18px; height: 28px;" id="cx"margin-left: 30px>查询</button>
<button style="font-size: 18px; height: 28px;" id="add" margin-left: 100px>添加</button>
<button style="font-size: 18px; height: 28px;" id="delete">删除</button>
<button style="font-size: 18px; height: 28px;" id="change">修改</button>
<b> <span style="color: crimson">${tip}</span></b>
</div>
</div>
<script>
document.getElementById("cx").onclick=function(){
let v = document.getElementById('fileId').value;
//访问服务器searchServlet
window.location.href = "searchServlet?v=" + v;
}
//删除
document.getElementById("delete").onclick=function () {
let v =document.getElementById('fileId').value;
window.location.href = "deleteServlet?v="+v;
}
document.getElementById("add").onclick=function () {
window.location = "addJinHuo.jsp";
}
//修改,跳转到change.jsp
document.getElementById("changeUser").onclick=function () {
let v =document.getElementById('fileId').value;
window.location.href = "upJinHuo.jsp";
}
</script>
<div>
<table id="table" style="height: 30px;width: 700px;border: black 1px solid;border-collapse:collapse;">
<tr style="font-weight: bold" >
<td>进货编号</td>
<td>进货商品编号</td>
<td>进货商品名称</td>
<td>进货量</td>
<td>进货商品进价</td>
</tr>
<%--jstl语法遍历,var是一个指指针--%>
<c:forEach items="${arr}" var="item">
<tr>
<td>${item.getGoodsid()}</td>
<td>${item.getGoods_id()}</td>
<td>${item.getGoods_name()}</td>
<td>${item.getGoods_purchase()}</td>
<td>${item.getGoods_price()}</td>
</td>
</tr>
</c:forEach>
</table>
</div>
</div>
</body>
</html>
(4)商品进货管理功能中的添加进货信息的页面 addJinHuo.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String path = request.getContextPath();
String basepath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
<base href="<%=basepath %>"/>
<meta charset="UTF-8">
<title>添加进货信息</title>
</head>
<body>
<div>
<h2>添加进货信息</h2>
进货编号:<input type="text" style="margin-top:20px;" id="a"><br>
进货商品编号:<input type="text" style="margin-top:20px;" id="b"><br>
进货商品名称:<input type="text" style="margin-top:20px;" id="c"><br>
进货量:<input type="text" style="margin-top:20px" id="d"><br>
进货商品进价:<input type="text" style="margin-top:20px;" id="e"><br>
<b><span id="span3" style="color:crimson"></span></b>
<button id="btn9" style="margin-top:20px;">提交</button>
<script>
document.getElementById("btn9").onclick = function () {
let a = document.getElementById("a").value;
let b = document.getElementById("b").value;
let c = document.getElementById("c").value;
let d = document.getElementById("d").value;
let e = document.getElementById("e").value;
if (a == null || a == "" ||b == null || b == "" ||c == null || c == "" ||
d == null || d == "" ||e == null || e == "") {
document.getElementById("span3").innerHTML = "每项都不能为空"
return;
}
window.location.href = "addJinHuo?a"+a+"&b"+b+"&c"+c+"&d"+d+"&e"+e;
}
</script>
</div>
</body>
</html>
Servlet下
1.loginServlet
package com.xxx.servlet;
import com.xxx.pojo.User;
import com.xxx.service.FileService;
import com.xxx.service.FileServiceImpl;
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("/DianZhu")
public class loginServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String u_id = null, u_pwd = null;
User u = new User();
try {//非数字异常判断
u_id = req.getParameter("id");
u_pwd = req.getParameter("pwd");
u.setId(Integer.valueOf(u_id));
u.setPwd(u_pwd);
} catch (Exception e) {
req.setAttribute("error", "你输入的不是数字");
//错误就回到主界面
req.getRequestDispatcher("login.jsp").forward(req, resp);
}
User user=new User();
FileService fs=new FileServiceImpl();
user= fs.loginService(u);
if(user!=null){
req.setAttribute("user", user);
//跳转到主界面
req.getRequestDispatcher("DianZhu.jsp").forward(req, resp);
}else{
req.setAttribute("error", "密码不匹配");
req.getRequestDispatcher("login.jsp").forward(req, resp);
}
}
}
2.addJinHuoServlet
package com.xxx.servlet;
import com.xxx.pojo.goods_purchase;
import com.xxx.service.FileService;
import com.xxx.service.FileServiceImpl;
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;
import java.util.ArrayList;
@WebServlet("/addJinHuo")
public class addJinHuo extends HttpServlet{
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
req.setCharacterEncoding("UTF-8");
String goodsid=req.getParameter("a");
String goods_id=req.getParameter("b");
String name=req.getParameter("c");
String purchase=req.getParameter("d");
String price=req.getParameter("e");
FileService fs=new FileServiceImpl();
goods_purchase g=new goods_purchase(Integer.valueOf(goodsid),Integer.valueOf(goods_id),name,Integer.valueOf(purchase),
Integer.valueOf(price));
boolean flag=fs.addgoods(g );
ArrayList<goods_purchase> list=fs.getAll();
String tip="";
if (flag){
tip="添加成功";
}else{
tip="添加失败";
}
//发送到前端
req.setAttribute("tip",tip);
req.setAttribute("arr", list);
req.getRequestDispatcher("JinHuo.jsp").forward(req, resp);
}
}