库存物资管理系统实验要求如下:
1.背景资料
1、有一个存放商品的仓库,每天都有商品出库和入库。
2、每种商品都有名称、生产厂家、型号、规格等。
3、出入库时必须填写出入库单据,单据包括商品名称、生产厂家、型号、
规格、数量、日期、时间、入库单位(或出库单位)名称、送货(或提货)人
姓名。
2.系统要求与功能设计
2.1页面要求
(1)能够在Tomcat服务器中正确部署,并通过浏览器查看;(1分)
(2)网站页面整体风格统一;
2.2设计要求
1、设计出入库单据的录入。
2、实现按商品名称、出入库日期的查询。
3.评分标准:
1、A类:完全实现上述功能,达到A类标准的同学可以免于参加期末上机考试,
期末上机考试成绩按满分计算。
2、B类:实现出入库单据记录的添加。
3、C类:实现数据库的连接。
4、D类:不满足上述要求的。
详细过程:1.刚拿到题目,觉得貌似比上次的简单,因为看题目要求的篇幅并不多,但看完题后,思考编写的过程发现并不简单,题目能给的关键信息点太少;
2.首先编写必要的jsp界面,自己懒得写,是课前在网上见过的类似界面代码修改而成的,想省下点时间写关键的方法代码;
3.商品信息的录入和查询通过上次实验的学习已经基本掌握了,但是也费了半天时间弄,主要是不太熟悉,有些东西也是修改代码完成的;
4.接下来就是最头疼的那个出库,有点懵,我一开始想是不是还用考虑往外取物资的系统,瞎编了半天没结果,马上就快下机了,然后听说是没那么复杂,就是相当于上次学生管理系统的修改步骤,想着A标已经无妄了,就回宿舍参考了上次的那个系统又改了快一个多小时,终于磕磕巴巴的做出了个粗糙的程序。
总结:上次靠学长的代码完完全全的实现了功能,觉得下一次做系统应该差不多了,没想到只是按照人家的思路可以做下来,自己做一个新的系统,一些类似的死的东西道是没问题,出了个出库就直接懵了,还是缺乏自己的独立思考,不过这次就是同学提醒了一下思路就自己完成了,还算有进步了,时间花费比较多,以后要加快速度。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style> .a{ margin-top: 20px; } .b{ font-size: 20px; width: 160px; color: white; background-color: greenyellow; } </style> </head> <body> <% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <div align="center"> <h1 style="color: red;">商品入库</h1> <a href="index.jsp">返回主页</a> <form action="UserServlet?method=add" method="post" onsubmit="return check()"> <div class="a"> 分类名<input type="text" name="name" /> </div> <div class="a"> 厂家<input type="text" name="changjia" /> </div> <div class="a"> 型号<input type="text" name="xinghao"/> </div> <div class="a"> 规格<input type="text" name="guige"/> </div> <div class="a"> 数量<input type="text" name="shuliang" /> </div> <div class="a"> 日期<input type="text" name="riqi" /> </div> <div class="a"> 单位名称<input type="text" name="danwei" /> </div> <div class="a"> 人名<input type="text" name="xingming"/> </div> <div class="a"> 操作<input type="text" name="caozuo"/> </div> <div class="a"> <input type="submit" value="添加" onClick="delcfm1()" /> </div> </form> </div> <script language="javascript"> function delcfm1() { if (!confirm("确认要添加?")) { window.event.returnValue = false; } } </script> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style> .a{ margin-top: 20px; } .b{ font-size: 20px; width: 160px; color: white; background-color: greenyellow; } </style> </head> <body> <% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <div align="center"> <h1 style="color: red;">删除</h1> <a href="index.jsp">返回主页</a> <form action="UserServlet?method=getuserbyname" method="post" onsubmit="return check()"> <div class="a"> 商品名称<input type="text" name="name" /> </div> <div class="a"> <button type="submit" class="b">查 找</button> </div> </form> </div> <script type="text/javascript"> function check() { var name = document.getElementByName("name");; //非空 if(name.value == ‘‘) { alert(‘商品名称为空‘); name.focus(); return false; } } </script> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style> .a{ margin-top: 20px; } .b{ font-size: 20px; width: 160px; color: white; background-color: greenyellow; } .tb, td { border: 1px solid black; font-size: 22px; } </style> </head> <body> <div align="center"> <h1 style="color: red;"></h1> <a href="index.jsp">返回主页</a> <table class="tb"> <tr> <td>商品名称</td> <td>${user.name}</td> </tr> <tr> <td>商品厂家</td> <td>${user.changjia}</td> </tr> <tr> <td>商品型号</td> <td>${user.xinghao}</td> </tr> <tr> <td>商品规格</td> <td>${user.guige}</td> </tr> <tr> <td>商品数量</td> <td>${user.shuliang}</td> </tr> <tr> <td>日期</td> <td>${user.riqi}</td> </tr> <tr> <td>单位</td> <td>${user.danwei}</td> </tr> <tr> <td>姓名</td> <td>${user.xingming}</td> </tr> <tr> <td>操作</td> <td>${user.caozuo}</td> </tr> </table> <div class="a"> <a onclick="return check()" href="UserServlet?method=del&name=${user.name}">删 除</a> </div> </div> <script type="text/javascript"> function check() { if (confirm("真的要删除吗?")){ return true; }else{ return false; } } </script> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>首页</title> <style> .a{ font-size: 26px; margin-top: 20px; } </style> </head> <body> <div align="center"> <h1 style="color: red;">库存物资管理</h1> <div class="a"> <a href="add.jsp">商品出入库</a> </div> <div class="a"> <a href="del.jsp">商品的删除</a> </div> <div class="a"> <a href="search.jsp">查询</a> </div> </div> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <style> .a{ margin-top: 20px; } .b{ font-size: 20px; width: 160px; color: white; background-color: greenyellow; } .tb, td { border: 1px solid black; font-size: 22px; } </style> </head> <body> <% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <div align="center"> <h1 style="color: red;">商品信息列表</h1> <a href="index.jsp">返回主页</a> <form action="UserServlet?method=getuserbyname" method="post" onsubmit="return check()"> <div class="a"> 商品名称<input type="text" name="name" /> </div> <div class="a"> <button type="submit" class="b">查 找</button> </div> </form> </div> <script type="text/javascript"> function check() { var name = document.getElementById("name");; //非空 if(name.value == ‘‘) { alert(‘商品名称为空‘); name.focus(); return false; } } </script> </body> </html>
package com.jaovo.msg.dao; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import com.jaovo.msg.model.User; import com.jaovo.msg.Util.DBUtil; public class Dao { public boolean add(User user) { String sql = "insert into user( name, changjia,xinghao,guige,shuliang,riqi,danwei,xingming,caozuo) values(‘" + user.getName() + "‘,‘" + user.getChangjia() + "‘,‘" + user.getXinghao() + "‘,‘" + user.getGuige() + "‘,‘" + user.getShuliang() + "‘,‘" + user.getRiqi() +"‘,‘" + user.getDanwei() +"‘,‘" + user.getXingming() +"‘,‘" + user.getCaozuo()+"‘)"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); state.executeUpdate(sql); } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } return f; } public boolean delete (String name) { boolean f = false; String sql = "delete from user where name=‘" + name + "‘"; Connection conn = DBUtil.getConn(); Statement state = null; int a = 0; try { state = conn.createStatement(); a = state.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } return f; } public boolean update(User user) { String sql = "update user set guige=‘"+user.getGuige()+ "‘, changjia=‘" + user.getChangjia() + "‘, xinghao=‘" + user.getXinghao()+ "‘, shuliang=‘" + user.getShuliang() +"‘, riqi=‘" + user.getRiqi() +"‘, danwei=‘" + user.getDanwei()+"‘, xingming=‘" + user.getXingming() +"‘, caozuo=‘" + user.getCaozuo() +"‘where name=‘" + user.getName() + "‘"; Connection conn = DBUtil.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); a = state.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(state, conn); } if (a > 0) { f = true; } return f; } public boolean name(String name) { boolean flag = false; String sql = "select name from user where name = ‘" + name + "‘"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { flag = true; } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return flag; } public User getUserByName(String name) { String sql = "select * from user where name =‘" + name + "‘"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; User user= null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { String name1 = rs.getString("name"); String changjia= rs.getString("changjia"); String xinghao= rs.getString("xinghao"); String guige =rs.getString("guige"); String shuliang=rs.getString("shuliang"); String riqi=rs.getString("riqi"); String danwei=rs.getString("danwei"); String xingming=rs.getString("xingming"); String caozuo=rs.getString("caozuo"); user = new User(name1,changjia,xinghao,guige,shuliang,riqi,danwei,xingming,caozuo); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return user; } public List<User> search(String name,String changjia,String xinghao,String guige,String shuliang,String riqi,String danwei,String xingming ) { String sql = "select * from user where "; if (name != "") { sql += "name like ‘%" + name + "%‘"; } if (changjia!= "") { sql += "changjia like ‘%" + changjia + "%‘"; } if (xinghao != "") { sql += "xinghao like ‘%" + xinghao+ "%‘"; } if (guige != "") { sql += "guige like ‘%" + guige+ "%‘"; } if (shuliang != "") { sql += "shuliang like ‘%" + shuliang + "%‘"; } if (riqi != "") { sql += "riqi like ‘%" + riqi + "%‘"; } if (danwei != "") { sql += "danwei like ‘%" + danwei+ "%‘"; } if (xingming != "") { sql += "xingming like ‘%" + xingming + "%‘"; } List<User> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); User bean = null; while (rs.next()) { String name1 = rs.getString("name"); String changjia1= rs.getString("changjia"); String xinghao1= rs.getString("xinghao"); String guige1 =rs.getString("guige"); String shuliang1=rs.getString("shuliang"); String riqi1=rs.getString("riqi"); String danwei1=rs.getString("danwei"); String xingming1=rs.getString("xingming"); String caozuo=rs.getString("caozuo"); bean = new User(name1,changjia1,xinghao1,guige1,shuliang1,riqi1,danwei1,xingming1,caozuo); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } public List<User> list() { String sql = "select * from user"; List<User> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); User bean = null; while (rs.next()) { String name = rs.getString("name"); String changjia= rs.getString("changjia"); String xinghao= rs.getString("xinghao"); String guige =rs.getString("guige"); String shuliang=rs.getString("shuliang"); String riqi=rs.getString("riqi"); String danwei=rs.getString("danwei"); String xingming=rs.getString("xingming"); String caozuo=rs.getString("caozuo"); bean= new User(name,changjia,xinghao,guige,shuliang,riqi,danwei,xingming,caozuo); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } }
package com.jaovo.msg.model; import java.sql.Connection; public class User { private String name; private String changjia; private String xinghao; private String guige; private String shuliang; private String riqi; private String danwei; private String xingming; private String caozuo; public void setName(String name) { this.name = name; } public String getName() { return name; } public String getChangjia() { return changjia; } public void setChangjia(String changjia) { this.changjia = changjia; } public String getXinghao() { return xinghao; } public void setXinghao(String xinghao) { this.xinghao = xinghao; } public String getGuige() { return guige; } public void setGuige(String guige) { this.guige = guige; } public String getShuliang() { return shuliang; } public void setShuliang(String shuliang) { this.shuliang = shuliang; } public String getRiqi() { return riqi; } public void setRiqi(String riqi) { this.riqi = riqi; } public String getDanwei() { return danwei; } public void setDanwei(String danwei) { this.danwei = danwei; } public String getXingming() { return xingming; } public void setXingming(String xingming) { this.xingming = xingming; } public User(String name,String changjia,String xinghao,String guige,String shuliang,String riqi,String danwei,String xingming ,String caozuo) { this.name = name; this.changjia = changjia; this.xinghao = xinghao; this.guige = guige; this.shuliang = shuliang; this.riqi = riqi; this.danwei = danwei; this.xingming = xingming; this.setCaozuo(caozuo); } public User() { // TODO Auto-generated constructor stub } public String getCaozuo() { return caozuo; } public void setCaozuo(String caozuo) { this.caozuo = caozuo; } }
package com.jaovo.msg.service; import java.util.List; import com.jaovo.msg.dao.Dao; import com.jaovo.msg.model.User; public class UserService { Dao cDao = new Dao(); public boolean add(User user) { boolean f = false; if(!cDao.name(user.getName())) { cDao.add(user); f = true; } return f; } public void del(String name) { cDao.delete(name); } public void update(User user) { cDao.update(user); } public User getUserByName(String name) { return cDao.getUserByName(name); } public List<User> search(String name ) { return (List<User>) cDao.getUserByName(name); } public List<User> list() { return cDao.list(); } }
package com.jaovo.msg.severlet; import java.io.IOException; import java.util.List; 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 com.jaovo.msg.model.User; import com.jaovo.msg.service.UserService; @WebServlet("/UserServlet") public class UserServlet extends HttpServlet { private static final long serialVersionUID = 1L; UserService service = new UserService(); /** * 鏂规硶閫夋嫨 */ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String method = req.getParameter("method"); if ("add".equals(method)) { add(req, resp); } else if ("del".equals(method)) { del(req, resp); } else if ("update".equals(method)) { update(req, resp); } else if ("search".equals(method)) { search(req, resp); } else if ("getuserbyname".equals(method)) { getUserByName(req, resp); } else if ("list".equals(method)) { list(req, resp); } } /** * 娣诲姞 * @param <service> * @param req * @param resp * @throws IOException * @throws ServletException */ private <service> void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { req.setCharacterEncoding("utf-8"); String name = req.getParameter("name"); String changjia= req.getParameter("changjia"); String xinghao=req.getParameter("xinghao"); String guige =req.getParameter("guige"); String shuliang=req.getParameter("shuliang"); String riqi=req.getParameter("riqi"); String danwei=req.getParameter("danwei"); String xingming=req.getParameter("xingming"); String caozuo=req.getParameter("caozuo"); User user = new User(name,changjia,xinghao,guige,shuliang,riqi,danwei,xingming,caozuo); //娣诲姞鍚庢秷鎭樉绀? if(service.add(user)) { req.setAttribute("message", "娣诲姞鎴愬姛"); req.getRequestDispatcher("add.jsp").forward(req,resp); } else { req.setAttribute("message", "鍟嗗搧鍚嶇О閲嶅锛岃閲嶆柊褰曞叆"); req.getRequestDispatcher("add.jsp").forward(req,resp); } } /** * 鍏ㄩ儴 * @param req * @param resp * @throws ServletException */ private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); List<User> users = service.list(); req.setAttribute("users", users); req.getRequestDispatcher("list.jsp").forward(req,resp); } /** * 閫氳繃鍚嶅瓧鏌ユ壘 * 璺宠浆鑷冲垹闄? * @param req * @param resp * @throws IOException * @throws ServletException */ private void getUserByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); String name = req.getParameter("name"); User user = service.getUserByName(name); if(user == null) { req.setAttribute("message", "鏌ユ棤姝ゅ晢鍝侊紒"); req.getRequestDispatcher("del.jsp").forward(req,resp); } else { req.setAttribute("user", user); req.getRequestDispatcher("detail.jsp").forward(req,resp); } } /** * 鍒犻櫎 * @param req * @param resp * @throws IOException * @throws ServletException */ private void del(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); String name = req.getParameter("name"); service.del(name); req.setAttribute("message", "鍒犻櫎鎴愬姛锛?"); req.getRequestDispatcher("del.jsp").forward(req,resp); } /** * 淇敼 * @param req * @param resp * @throws IOException * @throws ServletException */ private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); String name = req.getParameter("name"); String changjia= req.getParameter("changjia"); String xinghao=req.getParameter("xinghao"); String guige =req.getParameter("guige"); String shuliang=req.getParameter("shuliang"); String riqi=req.getParameter("riqi"); String danwei=req.getParameter("danwei"); String xingming=req.getParameter("xingming"); String caozuo=req.getParameter("caozuo"); User user = new User(name,changjia,xinghao,guige,shuliang,riqi,danwei,xingming,caozuo); service.update(user); req.setAttribute("message", "淇敼鎴愬姛"); req.getRequestDispatcher("").forward(req,resp); } /** * 鏌ユ壘 * @param req * @param resp * @throws ServletException */ private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); String name = req.getParameter("name"); String changjia= req.getParameter("changjia"); String xinghao= req.getParameter("xinghao"); String guige =req.getParameter("guige"); String shuliang=req.getParameter("shuliang"); String riqi=req.getParameter("riqi"); String danwei=req.getParameter("danwei"); String xingming=req.getParameter("xingming"); List<User> users = service.search(name); req.setAttribute("users", users); req.getRequestDispatcher("searchlist.jsp").forward(req,resp); } }
package com.jaovo.msg.Util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * 鏁版嵁搴撹繛鎺ュ伐鍏? * @author Hu * */ public class DBUtil { public static String db_url = "jdbc:mysql://localhost:3306/runoob?useUnicode=true&characterEncoding=utf-8"; public static String db_user = "root"; public static String db_pass = "root"; public static Connection getConn () { Connection conn = null; try { Class.forName("com.mysql.cj.jdbc.Driver");//鍔犺浇椹卞姩 conn = DriverManager.getConnection(db_url, db_user, db_pass); } catch (Exception e) { e.printStackTrace(); } return conn; } /** * 鍏抽棴杩炴帴 * @param state * @param conn */ public static void close (Statement state, Connection conn) { if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close (ResultSet rs, Statement state, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } }
原文地址:https://www.cnblogs.com/cuijunfeng/p/10117179.html