本项目采用eclipse工具开发,jsp+servlet技术编写,样式采用了layui前段框架,数据库采用的是mysql,navicat开发工具。
系统一共分为3个角色分别是:管理员,仓管员,供应商
1、登录
2、仓管员管理
3、仓库管理
4、供应商管理
5、商品管理
6、出库入库管理
仓管员
1、登录
2、个人信息维护
3、查看商品信息
4、库存预警
5、商品申请
6、商品供应记录
7、商品出库入库
供应商
1、登录注册
2、个人信息维护
3、商品出库入库申请
4、个人申请记录
项目结构
数据库结构
登录
注册
仓管员管理
仓库管理
供应商管理
商品管理
出库入库管理
1、登录
login.jsp中,用户填写用户名和密码,点击登录按钮,提交登录的form表单,请求后台的loginservlet类里面的login方法,验证登录后,跳转指定的页面
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
仓 库 管 理 系 统
private void login(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
removeAll(request,response);
String userName = request.getParameter("userName");
String password = request.getParameter("password");
String type = request.getParameter("type");
if(type.equals("1")){
Admin admin = new Admin();
admin.setUsername(userName);
admin.setPwd(password);
Admin admin1 = service.selectAdmin(admin);
try {
if (admin1 == null){
request.setAttribute("message", "管理员用户不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("admin",admin1);
request.getSession().setAttribute("flag",1);
request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}else if(type.equals("2")){
Keeper keep = new Keeper();
keep.setUsername(userName);
keep.setPwd(password);
Keeper keep1 = service.selectKeeper(keep);
try {
if (keep1 == null){
request.setAttribute("message", "仓管员不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("keeper",keep1);
request.getSession().setAttribute("flag",2);
request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}else if(type.equals("3")){
Supplier supplier = service.selectSupplier(userName,password);
try {
if (supplier == null){
request.setAttribute("message", "供应商不存在或者密码错误");
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}else {
request.getSession().setAttribute("supplier",supplier);
request.getSession().setAttribute("flag",3);
request.getRequestDispatcher("/WEB-INF/views/main.jsp").forward(request, response);
}
} catch (Exception e) {
e.printStackTrace();
}
}else{
request.setAttribute("message", "账号不存在或者密码错误");
try {
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
}
注册代码
用户点击注册按钮,跳转注册页面,填写注册表单,提交代码到SupplierServlet里面addSupplier方法中,后台进行数据库的插入操作,这边注册的是供应商,管理员需要审核通过后,供应商才能登陆
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
private void addSupplier(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String te = request.getParameter("te");
String names = request.getParameter("names");
String username = request.getParameter("username");
String pwd = request.getParameter("pwd");
String sex = request.getParameter("sex");
Supplier ss = service.selectSupplierByUsername(username);
Supplier s1 = new Supplier();
s1.setName(names);
s1.setUsername(username);
s1.setPwd(pwd);
s1.setSex(sex);
s1.setTimes(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
s1.setState("1");
try {
if(te != null && te.equals("1")){
if(ss !=null){
request.setAttribute("message", "登录账号重复!");
request.getRequestDispatcher("/WEB-INF/views/register.jsp").forward(request,response);
}else{
service.addSupplier(s1);
request.getRequestDispatcher("/WEB-INF/views/login.jsp").forward(request, response);
}
}else{
if(ss !=null){
request.setAttribute("message", "登录账号重复!");
request.getRequestDispatcher("/WEB-INF/views/supplier/addSupplier.jsp").forward(request,response);
}else{
service.addSupplier(s1);
response.sendRedirect(request.getContextPath()+"/SupplierServlet?action=supplierList");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
仓管员列表
分页查询仓管员的信息,返回给keepList.jsp,前端页面使用jstl进行遍历显示
private void keeperList(HttpServletRequest request, HttpServletResponse response) {
// TODO Auto-generated method stub
String p=request.getParameter("p");//接收页码
int pageSize=4;//每页显示5条
int pageNum=1; //默认第一页
if(p!=null){
pageNum= Integer.parseInt(p);
}
//调用分页查询
List list=service.geKeeperListPage(pageNum,pageSize);
//携带参数到页面
int nums=service.queryKeeperCount(); //查询总数
//计算总页数
int totalPage=(nums%pageSize==0)? (nums/pageSize):(nums/pageSize+1);
request.setAttribute("cp",pageNum); //当前页
request.setAttribute("tp",totalPage); //总页数
try {
request.removeAttribute("msg");
request.setAttribute("list" ,list);
request.getRequestDispatcher("/WEB-INF/views/keeper/keeperList.jsp").forward(request, response);
} catch (Exception e) {
e.printStackTrace();
}
}
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>