库存物资管理系统
话不多说,上代码
GoodBean.java
package bean; public class GoodBean { private String name; private String manufacturer; private String type; private String spec; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getManufacturer() { return manufacturer; } public void setManufacturer(String manufacturer) { this.manufacturer = manufacturer; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getSpec() { return spec; } public void setSpec(String spec) { this.spec = spec; } }
FormBean.java:
package bean; public class FormBean extends GoodBean{ private int number; private String date; private String time; private String name1; private String name2; private String formType; public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } public String getName1() { return name1; } public void setName1(String name1) { this.name1 = name1; } public String getName2() { return name2; } public void setName2(String name2) { this.name2 = name2; } public String getFormType() { return formType; } public void setFormType(String formType) { this.formType = formType; } }
GoodDao.java:
package dao; import java.io.IOException; import java.io.UnsupportedEncodingException; 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 javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import bean.FormBean; import bean.GoodBean; import util.DBUtil; public class GoodDao extends HttpServlet { private static final long serialVersionUID = 1L; protected void service(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException{ request.setCharacterEncoding("UTF-8"); String method = request.getParameter("method"); if("insert".equals(method)) insert(request, response); else if("delete".equals(method)) delete(request, response);else if("query".equals(method)) query(request, response); } private void insert(HttpServletRequest request, HttpServletResponse response) { try { request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); String manufacturer = request.getParameter("manufacturer"); String type = request.getParameter("type"); String spec = request.getParameter("spec"); if(name==""||manufacturer==""||type==""||spec=="") response.sendRedirect(request.getContextPath() + "/admin/Insert2.jsp?status=0"); //0代表某些信息为空 else { Connection conn = DBUtil.getConn(); Statement st = conn.createStatement(); String sql = "select * from good where name='"+ name + "'and manufacturer='" + manufacturer + "'and type='" + type + "'and spec='" + spec + "'"; ResultSet i = st.executeQuery(sql); if(!i.next()) { sql = "insert into good values('"+ name + "','" + manufacturer + "','" + type + "','" + spec + "')"; st.executeUpdate(sql); response.sendRedirect(request.getContextPath() + "/admin/Insert2.jsp?status=1"); //1代表录入成功 } else response.sendRedirect(request.getContextPath() + "/admin/Insert2.jsp?status=2"); //2代表该信息已存在 DBUtil.close(st, conn); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } private void delete(HttpServletRequest request, HttpServletResponse response) { String i = request.getParameter("i"); List<GoodBean> list = (List<GoodBean>) request.getSession().getAttribute("l"); String sql = "delete from good where "; sql += "name='" + list.get(Integer.parseInt(i)).getName() + "' and "; sql += "manufacturer='" + list.get(Integer.parseInt(i)).getManufacturer() + "' and "; sql += "type='" + list.get(Integer.parseInt(i)).getType() + "' and "; sql += "spec='" + list.get(Integer.parseInt(i)).getSpec() + "'"; System.out.println(i); System.out.println(sql); Connection conn = DBUtil.getConn(); try { Statement st = conn.createStatement(); st.executeUpdate(sql); response.sendRedirect(request.getContextPath() + "/admin/Query2.jsp?status=3"); //3代表删除成功 } catch (SQLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private void modify(HttpServletRequest request, HttpServletResponse response) { } private void query(HttpServletRequest request, HttpServletResponse response) { try { request.setCharacterEncoding("UTF-8"); Connection conn = DBUtil.getConn(); Statement st = conn.createStatement(); HttpSession session = request.getSession(); List<GoodBean> list = new ArrayList<>(); ResultSet rs = null; GoodBean gb = null; String name = request.getParameter("name"); String manufacturer = request.getParameter("manufacturer"); String type = request.getParameter("type"); String spec = request.getParameter("spec"); String sql = "select * from good where "; if(name!="") sql += "name='" + name + "'"; if(manufacturer!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "manufacturer='" + manufacturer + "'"; } if(type!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "type='" + type + "'"; } if(spec!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "spec='" + spec + "'"; } System.out.println(sql); if(sql.indexOf("=")==-1) response.sendRedirect(request.getContextPath() + "/admin/Query2.jsp?status=0"); //0代表所有项均为空 rs = st.executeQuery(sql); while(rs.next()) { gb = new GoodBean(); gb.setName(rs.getString("name")); gb.setManufacturer(rs.getString("manufacturer")); gb.setType(rs.getString("type")); gb.setSpec(rs.getString("spec")); list.add(gb); } DBUtil.close(st, conn); session.setAttribute("list",list); if(list.size()==0) response.sendRedirect(request.getContextPath() + "/admin/Query2.jsp?status=1"); //1代表不存在该信息 else response.sendRedirect(request.getContextPath() + "/admin/Query2.jsp?status=2"); //2代表查询到信息 } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
FormDao.java:
package dao; import java.io.IOException; import java.io.UnsupportedEncodingException; 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 javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import bean.FormBean; import util.DBUtil; public class FormDao extends HttpServlet { private static final long serialVersionUID = 1L; protected void service(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException{ request.setCharacterEncoding("UTF-8"); String method = request.getParameter("method"); if("insert".equals(method)) insert(request, response); else if("delete".equals(method)) delete(request, response); else if("query".equals(method)) query(request, response); } private void insert(HttpServletRequest request, HttpServletResponse response) { try { request.setCharacterEncoding("UTF-8"); String name = request.getParameter("name"); String manufacturer = request.getParameter("manufacturer"); String type = request.getParameter("type"); String spec = request.getParameter("spec"); String number = request.getParameter("number"); String date = request.getParameter("date"); String time = request.getParameter("time"); String name1 = request.getParameter("name1"); String name2 = request.getParameter("name2"); String formType = request.getParameter("formType"); if(name==""||manufacturer==""||type==""||spec==""||number==""||date==""||time==""||name1==""||name2==""||formType=="") response.sendRedirect(request.getContextPath() + "/admin/Insert.jsp?status=0"); //0代表某些信息为空 else if(number.matches("[^0-9]+")) response.sendRedirect(request.getContextPath() + "/admin/Insert.jsp?status=1"); //1代表数量不对 else { Connection conn = DBUtil.getConn(); Statement st = conn.createStatement(); String sql = "select * from good where name='"+ name + "'and manufacturer='" + manufacturer + "'and type='" + type + "'and spec='" + spec + "'"; ResultSet i = st.executeQuery(sql); if(!i.next()) { sql = "insert into good values('"+ name + "','" + manufacturer + "','" + type + "','" + spec + "')"; st.executeUpdate(sql); } sql = "insert into form values('"+ name + "','" + manufacturer + "','" + type + "','" + spec + "','" + number + "','" + date + "','" + time + "','" + name1 + "','" + name2 + "','" + formType + "')"; st.executeUpdate(sql); DBUtil.close(st, conn); response.sendRedirect(request.getContextPath() + "/admin/Insert.jsp?status=2"); //2代表录入成功 } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } private void delete(HttpServletRequest request, HttpServletResponse response) { String i = request.getParameter("i"); List<FormBean> list = (List<FormBean>) request.getSession().getAttribute("l"); String sql = "delete from form where "; sql += "name='" + list.get(Integer.parseInt(i)).getName() + "' and "; sql += "manufacturer='" + list.get(Integer.parseInt(i)).getManufacturer() + "' and "; sql += "type='" + list.get(Integer.parseInt(i)).getType() + "' and "; sql += "spec='" + list.get(Integer.parseInt(i)).getSpec() + "' and "; sql += "number=" + list.get(Integer.parseInt(i)).getNumber() + " and "; sql += "date='" + list.get(Integer.parseInt(i)).getDate() + "' and "; sql += "time='" + list.get(Integer.parseInt(i)).getTime() + "' and "; sql += "name1='" + list.get(Integer.parseInt(i)).getName1() + "' and "; sql += "name2='" + list.get(Integer.parseInt(i)).getName2() + "' and "; sql += "formType='" + list.get(Integer.parseInt(i)).getFormType() + "'"; Connection conn = DBUtil.getConn(); try { Statement st = conn.createStatement(); st.executeUpdate(sql); response.sendRedirect(request.getContextPath() + "/admin/Query.jsp?status=4"); //4代表删除成功 } catch (SQLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private void query(HttpServletRequest request, HttpServletResponse response) { try { request.setCharacterEncoding("UTF-8"); Connection conn = DBUtil.getConn(); Statement st = conn.createStatement(); HttpSession session = request.getSession(); List<FormBean> list = new ArrayList<>(); ResultSet rs = null; FormBean fb = null; String name = request.getParameter("name"); String manufacturer = request.getParameter("manufacturer"); String type = request.getParameter("type"); String spec = request.getParameter("spec"); String number = request.getParameter("number"); String date = request.getParameter("date"); String time = request.getParameter("time"); String name1 = request.getParameter("name1"); String name2 = request.getParameter("name2"); String formType = request.getParameter("formType"); String sql = "select * from form where "; if(number!="" && number.matches("[^0-9]+")) response.sendRedirect(request.getContextPath() + "/admin/Query.jsp?status=0"); //0代表数量不对 if(name!="") sql += "name='" + name + "'"; if(manufacturer!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "manufacturer='" + manufacturer + "'"; } if(type!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "type='" + type + "'"; } if(spec!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "spec='" + spec + "'"; } if(number!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "number=" + number; } if(date!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "date='" + date + "'"; } if(time!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "time='" + time + "'"; } if(name1!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "name1='" + name1 + "'"; } if(name2!="") { if(sql.indexOf("=")!=-1) sql += " and "; sql += "name2='" + name2 + "'"; } if(formType!=null) { if(sql.indexOf("=")!=-1) sql += " and "; sql += "formType='" + formType + "'"; } if(sql.indexOf("=")==-1) response.sendRedirect(request.getContextPath() + "/admin/Query.jsp?status=1"); //1代表所有项均为空 rs = st.executeQuery(sql); while(rs.next()) { fb = new FormBean(); fb.setName(rs.getString("name")); fb.setManufacturer(rs.getString("manufacturer")); fb.setType(rs.getString("type")); fb.setSpec(rs.getString("spec")); fb.setNumber(rs.getInt("number")); fb.setDate(rs.getString("date")); fb.setTime(rs.getString("time")); fb.setName1(rs.getString("name1")); fb.setName2(rs.getString("name2")); fb.setFormType(rs.getString("formType")); list.add(fb); } DBUtil.close(st, conn); session.setAttribute("list",list); if(list.size()==0) response.sendRedirect(request.getContextPath() + "/admin/Query.jsp?status=2"); //2代表不存在该信息 else response.sendRedirect(request.getContextPath() + "/admin/Query.jsp?status=3"); //3代表查询到信息 } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
DBUtil.java:
package util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class DBUtil { public static String DBDRIVER = "com.mysql.cj.jdbc.Driver"; public static String DBURL = "jdbc:mysql://localhost/test" + "?serverTimezone=GMT%2B8"; public static String DBUSER = "root"; public static String DBPASSWORD = "WJL.991018"; public static Connection getConn() { Connection conn = null; try { Class.forName(DBDRIVER); conn = DriverManager.getConnection(DBURL, DBUSER, DBPASSWORD); } catch (Exception e) { e.printStackTrace(); } return conn; } public static void close(Statement state, Connection conn) { try { if(state!=null) state.close(); if(conn!=null) conn.close(); } catch (SQLException e) { e.printStackTrace(); } } public static void close(ResultSet rs, Statement state, Connection conn) { try { if(rs!=null) rs.close(); if(state!=null) state.close(); if(conn!=null) conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }
HomePage.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>主页面</title> </head> <body> <ul class="topmenu"> <li><a href="Insert.jsp" target="iframe_a">商品出(入)库登记</a></li> <li><a href="Query.jsp" target="iframe_a">删除/修改/查询出(入)库单据</a></li> <li><a href="Insert2.jsp" target="iframe_a">增加商品</a></li> <li><a href="Query2.jsp" target="iframe_a">删除/修改/查询商品信息</a></li> <li><a href="ShowAll.jsp" target="iframe_a">显示全部信息</a></li> </ul> <iframe src="" width="1800" height="1000" name="iframe_a" frameborder="0" id="iframe_a"> <p>该浏览器不支持iframe标签,请更换浏览器。</p> </iframe> </body> <style type="text/css"> html { font-size:large; font-weight:600; width:1000px; overflow-x:auto; } body { margin:0; background-color: #C6E2FE; } .topmenu { list-style-type: none; height:40px; width:100%; margin: 0; padding: 0; background-color: #777; position: absolute; top:0px; } .topmenu li { float: left; } .topmenu li a { border-color:#777; color: white; padding: 8px; text-align: center; text-decoration: none; display: inline-block; } .topmenu li a:hover { background-color: #222; } .topmenu li a:active { color: white; background-color: #4CAF50; } #iframe_a{ position: absolute; top:50px; } #iframe_b{ position: absolute; left:1100px; top:50px; } </style> </html>
Insert.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>商品出(入)库登记</title> </head> <body> <form action="${pageContext.request.contextPath}/servlet/FormDao?method=insert" method="post" id="insert"> <table border='1'> <tr align='center'> <td colspan='2'><h2>商品出(入)库登记</h2></td> </tr> <tr align='center'> <td>商品名称</td> <td><input name="name" type="text" placeholder="商品名称"/></td> </tr> <tr align='center'> <td>生产厂家</td> <td><input name="manufacturer" type="text" placeholder="生产厂家"/></td> </tr> <tr align='center'> <td>型号</td> <td><input name="type" type="text" placeholder="型号"/></td> </tr> <tr align='center'> <td>规格</td> <td><input name="spec" type="text" placeholder="规格"/></td> </tr> <tr align='center'> <td>数量</td> <td><input name="number" type="text" placeholder="数量,必须为整数!"/></td> </tr> <tr align='center'> <td>日期</td> <td><input name="date" type="text" placeholder="日期,格式:1970/01/01"/></td> </tr> <tr align='center'> <td>时间</td> <td><input name="time" type="text" placeholder="时间,格式:12:00"/></td> </tr> <tr align='center'> <td>出(入)库单位名称</td> <td><input name="name1" type="text" placeholder="出(入)库单位名称"/></td> </tr> <tr align='center'> <td>取(送)货人姓名</td> <td><input name="name2" type="text" placeholder="取(送)货人姓名"/></td> </tr> <tr align='center'> <td>表单类型</td> <td><input type="radio" name="formType" value="入库"/>入库<br/> <input type="radio" name="formType" value="出库"/>出库</td> </tr> <tr align='center'> <td colspan='2'><input type="submit" value="保存" /></td> </tr> </table> <c:if test="${param.status.equals('0')}"> <br/><br/><br/> <div>所有项信息均不能为空,请重新填写!</div> </c:if> <c:if test="${param.status.equals('1')}"> <br/><br/><br/> <div>数量非整数,请重新填写!</div> </c:if> <c:if test="${param.status.equals('2')}"> <br/><br/><br/> <div>商品出(入)库表单录入成功!</div> </c:if> </form> </body> </html>
Insert2.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>增加商品</title> </head> <body> <form action="${pageContext.request.contextPath}/servlet/GoodDao?method=insert" method="post" id="insert"> <table border='1'> <tr align='center'> <td colspan='2'><h2>增加商品</h2></td> </tr> <tr align='center'> <td>商品名称</td> <td><input name="name" type="text" placeholder="商品名称"/></td> </tr> <tr align='center'> <td>生产厂家</td> <td><input name="manufacturer" type="text" placeholder="生产厂家"/></td> </tr> <tr align='center'> <td>型号</td> <td><input name="type" type="text" placeholder="型号"/></td> </tr> <tr align='center'> <td>规格</td> <td><input name="spec" type="text" placeholder="规格"/></td> </tr> <tr align='center'> <td colspan='2'><input type="submit" value="保存" /></td> </tr> </table> <c:if test="${param.status.equals('0')}"> <br/><br/><br/> <div>所有项信息均不能为空,请重新填写!</div> </c:if> <c:if test="${param.status.equals('1')}"> <br/><br/><br/> <div>商品增加成功!</div> </c:if> <c:if test="${param.status.equals('2')}"> <br/><br/><br/> <div>该商品信息已存在,无需添加!</div> </c:if> </form> </body> </html>
Query.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page import="util.*,java.sql.*,java.util.*,bean.FormBean" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>查询/删除出(入)库单据</title> </head> <body> <form action="${pageContext.request.contextPath}/servlet/FormDao?method=query" method="post" id="query"> <table border='1'> <tr align='center'> <td colspan='2'><h2>查询/删除出(入)库单据</h2></td> </tr> <tr align='center'> <td>商品名称</td> <td><input name="name" type="text" placeholder="商品名称"/></td> </tr> <tr align='center'> <td>生产厂家</td> <td><input name="manufacturer" type="text" placeholder="生产厂家"/></td> </tr> <tr align='center'> <td>型号</td> <td><input name="type" type="text" placeholder="型号"/></td> </tr> <tr align='center'> <td>规格</td> <td><input name="spec" type="text" placeholder="规格"/></td> </tr> <tr align='center'> <td>数量</td> <td><input name="number" type="text" placeholder="数量,必须为整数!"/></td> </tr> <tr align='center'> <td>日期</td> <td><input name="date" type="text" placeholder="日期,格式:1970/01/01"/></td> </tr> <tr align='center'> <td>时间</td> <td><input name="time" type="text" placeholder="时间,格式:12:00"/></td> </tr> <tr align='center'> <td>出(入)库单位名称</td> <td><input name="name1" type="text" placeholder="出(入)库单位名称"/></td> </tr> <tr align='center'> <td>取(送)货人姓名</td> <td><input name="name2" type="text" placeholder="取(送)货人姓名"/></td> </tr> <tr align='center'> <td>表单类型</td> <td><input type="radio" name="formType" value="入库"/>入库<br/> <input type="radio" name="formType" value="出库"/>出库</td> </tr> <tr align='center'> <td colspan='2'><input type="submit" value="查询" /></td> </tr> </table> <c:if test="${param.status.equals('0')}"> <br/><br/><br/> <div>数量非整数,请重新填写!</div> </c:if> <c:if test="${param.status.equals('1')}"> <br/><br/><br/> <div>请填写信息!</div> </c:if> <c:if test="${param.status.equals('2')}"> <br/><br/><br/> <div>未找到出入库单据信息!</div> </c:if> <c:if test="${param.status.equals('3')}"> <br/><br/><br/> <table border='1'> <tr> <td>商品名称</td> <td>生产厂家</td> <td>型号</td> <td>规格</td> <td>数量</td> <td>日期</td> <td>时间</td> <td>入(出)库单位名称</td> <td>送(取)货人姓名</td> <td>表单类型</td> <td>操作</td> </tr> <%List<FormBean> l = (List<FormBean>)session.getAttribute("list"); session.setAttribute("l",l); for(int i=0;i<l.size();i++){%> <tr> <td><%=l.get(i).getName()%></td> <td><%=l.get(i).getManufacturer()%></td> <td><%=l.get(i).getType()%></td> <td><%=l.get(i).getSpec()%></td> <td><%=l.get(i).getNumber()%></td> <td><%=l.get(i).getDate()%></td> <td><%=l.get(i).getTime()%></td> <td><%=l.get(i).getName1()%></td> <td><%=l.get(i).getName2()%></td> <td><%=l.get(i).getFormType()%></td> <td><a href="${pageContext.request.contextPath}/servlet/FormDao?method=delete&i=<%=i%>">删除</a></td> <%}%> </tr> </table> </c:if> <c:if test="${param.status.equals('4')}"> <br/><br/><br/> <div>删除成功!</div> </c:if> </form> </body> </html>
Query2.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ page import="util.*,java.sql.*,java.util.*,bean.GoodBean" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>查询/删除商品信息</title> </head> <body> <form action="${pageContext.request.contextPath}/servlet/GoodDao?method=query" method="post" id="query"> <table border='1'> <tr align='center'> <td colspan='2'><h2>查询/删除商品信息</h2></td> </tr> <tr align='center'> <td>商品名称</td> <td><input name="name" type="text" placeholder="商品名称"/></td> </tr> <tr align='center'> <td>生产厂家</td> <td><input name="manufacturer" type="text" placeholder="生产厂家"/></td> </tr> <tr align='center'> <td>型号</td> <td><input name="type" type="text" placeholder="型号"/></td> </tr> <tr align='center'> <td>规格</td> <td><input name="spec" type="text" placeholder="规格"/></td> </tr> <tr align='center'> <td colspan='2'><input type="submit" value="查询" /></td> </tr> </table> <c:if test="${param.status.equals('0')}"> <br/><br/><br/> <div>请填写信息!</div> </c:if> <c:if test="${param.status.equals('1')}"> <br/><br/><br/> <div>未找到商品信息!</div> </c:if> <c:if test="${param.status.equals('2')}"> <br/><br/><br/> <table border='1'> <tr> <td>商品名称</td> <td>生产厂家</td> <td>型号</td> <td>规格</td> <td>操作</td> </tr> <%List<GoodBean> l = (List<GoodBean>)session.getAttribute("list"); session.setAttribute("l",l); for(int i=0;i<l.size();i++){%> <tr> <td><%=l.get(i).getName()%></td> <td><%=l.get(i).getManufacturer()%></td> <td><%=l.get(i).getType()%></td> <td><%=l.get(i).getSpec()%></td> <td><a href="${pageContext.request.contextPath}/servlet/GoodDao?method=delete&i=<%=i%>">删除</a></td> <%}%> </tr> </table> </c:if> <c:if test="${param.status.equals('3')}"> <br/><br/><br/> <div>删除成功!</div> </c:if> </form> </body> </html>
ShowAll.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="util.*,java.sql.*" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>显示全部课程</title> </head> <body> <% Connection conn = DBUtil.getConn(); Statement st = conn.createStatement(); ResultSet rs = st.executeQuery("select * from good"); %> <table border=1> <tr> <td>商品名称</td> <td>生产厂家</td> <td>型号</td> <td>规格</td> </tr> <%while(rs.next()) {%> <tr> <td><%=rs.getString("name")%></td> <td><%=rs.getString("manufacturer")%></td> <td><%=rs.getString("type")%></td> <td><%=rs.getString("spec")%></td> </tr> <%}%> </table> <br><br> <% rs = st.executeQuery("select * from form"); %> <table border=1> <tr> <td>商品名称</td> <td>生产厂家</td> <td>型号</td> <td>规格</td> <td>数量</td> <td>日期</td> <td>时间</td> <td>入(出)库单位名称</td> <td>送(取)货人姓名</td> <td>表单类型</td> </tr> <%while(rs.next()) {%> <tr> <td><%=rs.getString("name")%></td> <td><%=rs.getString("manufacturer")%></td> <td><%=rs.getString("type")%></td> <td><%=rs.getString("spec")%></td> <td><%=rs.getInt("number")%></td> <td><%=rs.getString("date")%></td> <td><%=rs.getString("time")%></td> <td><%=rs.getString("name1")%></td> <td><%=rs.getString("name2")%></td> <td><%=rs.getString("formType")%></td> </tr> <%}%> </table> <% DBUtil.close(rs, st, conn); %> </body> </html>
web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <display-name>InventoryManage</display-name> <servlet> <servlet-name>FormDao</servlet-name> <servlet-class>dao.FormDao</servlet-class> </servlet> <servlet-mapping> <servlet-name>FormDao</servlet-name> <url-pattern>/servlet/FormDao</url-pattern> </servlet-mapping> <servlet> <servlet-name>GoodDao</servlet-name> <servlet-class>dao.GoodDao</servlet-class> </servlet> <servlet-mapping> <servlet-name>GoodDao</servlet-name> <url-pattern>/servlet/GoodDao</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>