库存物资管理系统
一、背景资料:
1、有一个存放商品的仓库,每天都有商品出库和入库。
2、每种商品都有名称、生产厂家、型号、规格等。
3、出入库时必须填写出入库单据,单据包括商品名称、生产厂家、型号、
规格、数量、日期、时间、入库单位(或出库单位)名称、送货(或提货)人
姓名。
二、系统要求与功能设计
2.1 页面要求
(1)能够在 Tomcat 服务器中正确部署,并通过浏览器查看;(1 分)
(2)网站页面整体风格统一;
2.2 设计要求
1、设计出入库单据的录入。
2、实现按商品名称、出入库日期的查询。
CourseDao.java
对数据库的操作,实现增删改查
package com.hjf.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.hjf.entity.Course; import com.hjf.util.DBUtil; public class CourseDao { public boolean add(Course course) { String sql = "insert into course(name, changjia, xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo)" + " values('" + course.getName() + "','" + course.getChangjia() + "','" + course.getXinghao() + "','" +course.getGuige() +"','" + course.getShuliang()+ "','" +course.getRiqi()+ "','" +course.getShijian()+ "','" +course.getRuku()+ "','" +course.getChuku()+ "','" +course.getSonghuo()+ "','" +course.getTihuo()+"')"; //sql=" insert into course(name,changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo) values ('8','8','8','8','8','8','8','8','8','8','8')"; 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 (int id) { boolean f = false; String sql = "delete from course where id='" + id + "'"; 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(Course course) { String sql = "update course set name='" + course.getName() + "', changjia='" + course.getChangjia() + "', xinghao='" + course.getXinghao()+ "', guige='" + course.getGuige()+ "',shuliang='" + course.getShuliang()+ "', riqi='" + course.getRiqi()+ "',shijian='" + course.getShijian()+ "', ruku='" + course.getRuku()+ "', chuku='" + course.getChuku()+ "',songhuo='" + course.getSonghuo()+ "', tihuo='" + course.getTihuo() + "' where id='" + course.getId() + "'"; 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 course 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 Course getCourseById(int id) { String sql = "select * from course where id ='" + id + "'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; Course course = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); 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 shijian = rs.getString("shijian"); String ruku = rs.getString("ruku"); String chuku = rs.getString("chuku"); String songhuo = rs.getString("songhuo"); String tihuo = rs.getString("tihuo"); course = new Course(id, name, changjia, xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return course; } public Course getCourseByName(String name) { String sql = "select * from course where name ='" + name + "'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; Course course = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { int id = rs.getInt("id"); 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 shijian = rs.getString("shijian"); String ruku = rs.getString("ruku"); String chuku = rs.getString("chuku"); String songhuo = rs.getString("songhuo"); String tihuo = rs.getString("tihuo"); course = new Course(id, name1,changjia, xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return course; } public List<Course> search(String name, String changjia, String xinghao,String guige,String shuliang,String riqi,String shijian,String ruku,String chuku,String songhuo,String tihuo) { String sql = "select * from course where "; if (name != "" &&name != null) { sql += "name like '%" + name + "%'"; } if (changjia != ""&&changjia !=null) { sql += "changjia like '%" + changjia + "%'"; } if (xinghao != ""&&xinghao!=null) { sql += "xinghao like '%" + xinghao + "%'"; } if (guige != ""&&guige!=null) { sql += "guige like '%" + guige + "%'"; } if (shuliang != ""&&shuliang!=null) { sql += "shuliang like '%" + shuliang + "%'"; } if (riqi != ""&&riqi!=null) { sql += "riqi like '%" + riqi + "%'"; } if (shijian != ""&&shijian!=null) { sql += "shijian like '%" + shijian + "%'"; } if (ruku != ""&&ruku!=null) { sql += "ruku like '%" + ruku + "%'"; } if (chuku != ""&&chuku!=null) { sql += "chuku like '%" + chuku + "%'"; } if (songhuo != ""&&songhuo!=null) { sql += "songhuo like '%" + songhuo + "%'"; } if (tihuo!= ""&&tihuo!=null) { sql += "tihuo like '%" + tihuo + "%'"; } List<Course> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Course bean = null; while (rs.next()) { int id = rs.getInt("id"); String name2 = rs.getString("name"); String changjia2 = rs.getString("changjia"); String xinghao2 = rs.getString("xinghao"); String guige2 = rs.getString("guige"); String shuliang2 = rs.getString("shuliang"); String riqi2 = rs.getString("riqi"); String shijian2 = rs.getString("shijian"); String ruku2 = rs.getString("ruku"); String chuku2 = rs.getString("chuku"); String songhuo2 = rs.getString("songhuo"); String tihuo2 = rs.getString("tihuo"); bean = new Course(id, name2, changjia2,xinghao2,guige2,shuliang2,riqi2,shijian2,ruku2,chuku2,songhuo2,tihuo2); System.out.println(bean.getName()); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } public List<Course> list() { String sql = "select * from course"; List<Course> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Course bean = null; while (rs.next()) { int id = rs.getInt("id"); String name2 = rs.getString("name"); String changjia2 = rs.getString("changjia"); String xinghao2 = rs.getString("xinghao"); String guige2 = rs.getString("guige"); String shuliang2 = rs.getString("shuliang"); String riqi2 = rs.getString("riqi"); String shijian2 = rs.getString("shijian"); String ruku2 = rs.getString("ruku"); String chuku2 = rs.getString("chuku"); String songhuo2 = rs.getString("songhuo"); String tihuo2 = rs.getString("tihuo"); bean = new Course(id, name2, changjia2,xinghao2,guige2,shuliang2,riqi2,shijian2,ruku2,chuku2,songhuo2,tihuo2); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } }
对于数据的封装
Course.java
package com.hjf.entity; public class Course { private int id; private String name; private String changjia; private String xinghao; private String guige; private String shuliang; private String riqi; private String shijian; private String ruku; private String chuku; private String songhuo; private String tihuo; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = 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 getShijian() { return shijian; } public void setShijian(String shijian) { this.shijian = shijian; } public String getRuku() { return ruku; } public void setRuku(String ruku) { this.ruku = ruku; } public String getChuku() { return chuku; } public void setChuku(String chuku) { this.chuku = chuku; } public String getSonghuo() { return songhuo; } public void setSonghuo(String songhuo) { this.songhuo = songhuo; } public String getTihuo() { return tihuo; } public void setTihuo(String tihuo) { this.tihuo = tihuo; } public Course() {} public Course(int id, String name, String changjia, String xinghao, String guige, String shuliang, String riqi, String shijian, String ruku, String chuku, String songhuo, String tihuo) { this.id = id; this.name = name; this.changjia = changjia; this.xinghao = xinghao; this.guige = guige; this.shuliang = shuliang; this.riqi = riqi; this.shijian = shijian; this.ruku = ruku; this.chuku = chuku; this.songhuo = songhuo; this.tihuo = tihuo; } public Course(String name, String changjia, String xinghao, String guige, String shuliang, String riqi, String shijian, String ruku, String chuku, String songhuo, String tihuo) { this.name = name; this.changjia = changjia; this.xinghao = xinghao; this.guige = guige; this.shuliang = shuliang; this.riqi = riqi; this.shijian = shijian; this.ruku = ruku; this.chuku = chuku; this.songhuo = songhuo; this.tihuo = tihuo; } }
数据的集合
CourseService.java
package com.hjf.service; import java.util.List; import com.hjf.dao.CourseDao; import com.hjf.entity.Course; /** * CourseService * @author Hu * */ public class CourseService { CourseDao cDao = new CourseDao(); /** * @param course * @return */ public boolean add(Course course) { boolean f = false; if(!cDao.name(course.getName())) { cDao.add(course); f = true; } return f; } /** */ public void del(int id) { cDao.delete(id); } /** * @return */ public void update(Course course) { cDao.update(course); } /** * @return */ public Course getCourseById(int id) { return cDao.getCourseById(id); } /** * @return */ public Course getCourseByName(String name) { return cDao.getCourseByName(name); } /** * @return */ public List<Course> search(String name,String changjia, String xinghao, String guige, String shuliang, String riqi, String shijian, String ruku, String chuku, String songhuo, String tihuo) { return cDao.search(name, changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo); } public List<Course> list() { return cDao.list(); } }
连接数据库,实现增删改查
CourseServlet.java
package com.hjf.servlet; 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.hjf.entity.Course; import com.hjf.service.CourseService; @WebServlet("/CourseServlet") public class CourseServlet extends HttpServlet { private static final long serialVersionUID = 1L; CourseService service = new CourseService(); /** * 鏂规硶閫夋嫨 */ 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 ("getcoursebyid".equals(method)) { getCourseById(req, resp); } else if ("getcoursebyname".equals(method)) { getCourseByName(req, resp); } else if ("list".equals(method)) { list(req, resp); } } /** * @param req * @param resp * @throws IOException * @throws ServletException */ private 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 shijian = req.getParameter("shijian"); String ruku = req.getParameter("ruku"); String chuku = req.getParameter("chuku"); String songhuo = req.getParameter("songhuo"); String tihuo = req.getParameter("tihuo"); Course course = new Course(name,changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo); if(service.add(course)) { 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<Course> courses = service.list(); req.setAttribute("courses", courses); req.getRequestDispatcher("list.jsp").forward(req,resp); } /* * @param req * @param resp * @throws ServletException */ private void getCourseById(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); int id = Integer.parseInt(req.getParameter("id")); Course course = service.getCourseById(id); req.setAttribute("course", course); req.getRequestDispatcher("detail2.jsp").forward(req,resp); } /* * @param req * @param resp * @throws IOException * @throws ServletException */ private void getCourseByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); String name = req.getParameter("name"); Course course = service.getCourseByName(name); if(course == null) { req.setAttribute("message", "无此商品"); req.getRequestDispatcher("del.jsp").forward(req,resp); } else { req.setAttribute("course", course); 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"); int id = Integer.parseInt(req.getParameter("id")); service.del(id); 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"); int id = Integer.parseInt(req.getParameter("id")); 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 shijian = req.getParameter("shijian"); String ruku = req.getParameter("ruku"); String chuku = req.getParameter("chuku"); String songhuo = req.getParameter("songhuo"); String tihuo = req.getParameter("tihuo"); Course course = new Course(id, name,changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo); service.update(course); req.setAttribute("message", "修改成功"); req.getRequestDispatcher("CourseServlet?method=list").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 shijian = req.getParameter("shijian"); String ruku = req.getParameter("ruku"); String chuku = req.getParameter("chuku"); String songhuo = req.getParameter("songhuo"); String tihuo = req.getParameter("tihuo"); List<Course> courses = service.search(name,changjia,xinghao,guige,shuliang,riqi,shijian,ruku,chuku,songhuo,tihuo); req.setAttribute("courses", courses); req.getRequestDispatcher("searchlist.jsp").forward(req,resp); } }
index.jsp
主界面
<%@ 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="CourseServlet?method=list">商品信息修改</a> </div> <div class="a"> <a href="del.jsp">商品出库</a> </div> <div class="a"> <a href="search.jsp">商品信息查询</a> </div> </div> </body> </html>
增
add.jsp
商品入库及入库单据
<%@ 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: pink; background-color: yellow; } </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> <h1 style="color: red;">入库单据</h1> <a href="index.jsp">返回主页</a> <form action="CourseServlet?method=add" method="post" οnsubmit="return check()"> <div class="a"> 商品名称<input type="text" id="name" name="name"/> </div> <div class="a"> 生产厂家<input type="text" id="changjia" name="changjia" /> </div> <div class="a"> 型号<input type="text" id="xinghao" name="xinghao" /> </div> <div class="a"> 规格<input type="text" id="guige" name="guige" /> </div> <div class="a"> 数量<input type="text" id="shuliang" name="shuliang" /> </div> <div class="a"> 日期<input type="text" id="riqi" name="riqi" /> </div> <div class="a"> 时间<input type="text" id="shijian" name="shijian" /> </div> <div class="a"> 入库单位名称<input type="text" id="ruku" name="ruku" /> </div> <div class="a"> 送货人姓名<input type="text" id="songhuo" name="songhuo" /> </div> <div class="a"> <button type="submit" class="b">保 存</button> </div> </form> </div> <script type="text/javascript"> function check() { var name = document.getElementById("name");; var changjia = document.getElementById("changjia"); var xinghao = document.getElementById("xinghao"); var guige = document.getElementById("guige"); var shuliang = document.getElementById("shuliang"); var riqi = document.getElementById("riqi"); var shijian = document.getElementById("shijian"); var ruku = document.getElementById("ruku"); var songhuo = document.getElementById("songhuo"); //非空 if(name.value == '') { alert('商品名称为空'); name.focus(); return false; } if(changjia.value == '') { alert('生产厂家为空'); changjia.focus(); return false; } if(xinghao.value == '') { alert('型号为空'); xinghao.focus(); return false; } if(guige.value == '') { alert('规格为空'); guige.focus(); return false; } if(shuliang.value == '') { alert('数量为空'); shuliang.focus(); return false; } if(riqi.value == '') { alert('日期为空'); riqi.focus(); return false; } if(shijian.value == '') { alert('时间为空'); shijian.focus(); return false; } if(ruku.value == '') { alert('入库单位名称为空'); ruku.focus(); return false; } if(songhuo.value == '') { alert('送货人姓名为空'); songhuo.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: pink; background-color: yellow; } </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="CourseServlet?method=getcoursebyname" method="post" οnsubmit="return check()"> <div class="a"> 商品名称<input type="text" id="name" name="name"/> </div> <div class="a"> <button type="submit" class="b">查 找</button> </div> </form> <script type="text/javascript"> function check() { var name = document.getElementById("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: pink; background-color: yellow; } .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>${course.name}</td> </tr> <tr> <td>生产厂家</td> <td>${course.changjia}</td> </tr> <tr> <td>型号</td> <td>${course.xinghao}</td> </tr> <tr> <td>规格</td> <td>${course.guige}</td> </tr> <div align="center"> <div align="center"> </div> <h1 style="color: red;">出库单据</h1> <form action="CourseServlet?method=add" method="post" οnsubmit="return check()"> <div class="a"> 商品名称<input type="text" id="name" name="name"/> </div> <div class="a"> 生产厂家<input type="text" id="changjia" name="changjia" /> </div> <div class="a"> 型号<input type="text" id="xinghao" name="xinghao" /> </div> <div class="a"> 规格<input type="text" id="guige" name="guige" /> </div> <div class="a"> 数量<input type="text" id="shuliang" name="shuliang" /> </div> <div class="a"> 日期<input type="text" id="riqi" name="riqi" /> </div> <div class="a"> 时间<input type="text" id="shijian" name="shijian" /> </div> <div class="a"> 出库单位名称<input type="text" id="chuku" name="chuku" /> </div> <div class="a"> 提货人姓名<input type="text" id="tihuo" name="tihuo" /> </div> <div class="a"> <button type="submit" class="b">保 存</button> </div> </table> <div class="a"> <a οnclick="return check()" href="CourseServlet?method=del&id=${course.id}">删 除</a> </div> </div> <script type="text/javascript"> function check() { if (confirm("真的要删除吗?")){ return true; }else{ return false; } } </script> </body> </html>
商品出库
输入出单库据及删除商品
如果无此商品
改
商品修改,可以进行单个信息的修改
界面一list.jsp 在界面一可以看到所有信息并进行修改,转到界面二
界面二detail2.jsp在界面二中进行单个信息的修改
<%@ 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: pink; background-color:yellow; } .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> <table class="tb"> <tr> <td>id</td> <td>商品名称</td> <td>生产厂家</td> <td>型号</td> <td>规格</td> <td align="center" colspan="2">操作</td> </tr> <c:forEach items="${courses}" var="item"> <tr> <td>${item.id}</td> <td>${item.name}</td> <td>${item.changjia}</td> <td>${item.xinghao}</td> <td>${item.guige}</td> <td><a href="CourseServlet?method=getcoursebyid&id=${item.id}">修改</a></td> </tr> </c:forEach> </table> </div> </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: pink; background-color: yellow; } </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="CourseServlet?method=update" method="post" οnsubmit="return check()"> <div class="a"> 商品名称<input type="text" id="name" name="name" value="${course.name}"/> </div> <div class="a"> 生产厂家<input type="text" id="changjia" name="changjia" value="${course.changjia}"/> </div> <div class="a"> 型号<input type="text" id="xinghao" name="xinghao" value="${course.xinghao}"/> </div> <div class="a"> 规格<input type="text" id="guige" name="guige" value="${course.guige}"/> </div> <input type="hidden" id="id" name="id" value="${course.id}"/> <div class="a"> <button type="submit" class="b">修 改</button> </div> </form> </div> <script type="text/javascript"> function check() { var name = document.getElementById("name");; var changjia= document.getElementById("changjia"); var xinghao = document.getElementById("xinghao"); var guige = document.getElementById("guige"); //非空 if(name.value == '') { alert('商品名称为空'); name.focus(); return false; } if(changjia.value == '') { alert('生产厂家为空'); changjia.focus(); return false; } if(xinghao.value == '') { alert('规格为空'); xinghao.focus(); return false; } if(guige.value == '') { alert('规格为空'); guige.focus(); return false; } } </script> </body> </html>
查
查询商品信息,可以做到模糊查询
界面一search.jsp进行关键字模糊查询
界面二searchlist.jsp出现香港关键字信息
<%@ 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: pink; background-color: yellow; } </style> </head> <body> <div align="center"> <h1 style="color: red;">商品信息查询</h1> <a href="index.jsp">返回主页</a> <form action="CourseServlet?method=search" method="post" οnsubmit="return check()"> <div class="a"> 商品名称<input type="text" id="name" 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");; var changjia = document.getElementById("changjia"); var xinghao = document.getElementById("xinghao"); var guige = document.getElementById("guige"); var shuliang = document.getElementById("shuliang"); var riqi = document.getElementById("riqi"); var shijian = document.getElementById("shijian"); var ruku = document.getElementById("ruku"); var chuku = document.getElementById("chuku"); var songhuo = document.getElementById("songhuo"); var quhuo = document.getElementById("quhuo"); //非空 if(name.value == '' && changjia.value == '' && xinghao.value == '' && guige.value == ''&& shuliang.value == ''&& riqi.value == ''&& shijian.value == ''&& ruhuo.value == ''&& chuhuo.value == ''&& songhuo.value == ''&& tihuo.value == '') { alert('请填写一个条件'); return false; } } </script> </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: pink; background-color: yellow; } .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>id</td> <td>商品名称</td> <td>生产厂家</td> <td>型号</td> <td>规格</td> <td>数量</td> <td>日期</td> <td>时间</td> <td>入库单位名称</td> <td>出库单位名称</td> <td>送货人</td> <td>提货人</td> </tr> <!-- forEach遍历出adminBeans --> <c:forEach items="${courses}" var="item" varStatus="status"> <tr> <td>${item.id}</td> <td><a>${item.name}</a></td> <td>${item.changjia}</td> <td>${item.xinghao}</td> <td>${item.guige}</td> <td>${item.shuliang}</td> <td>${item.riqi}</td> <td>${item.shijian}</td> <td>${item.ruku}</td> <td>${item.chuku}</td> <td>${item.songhuo}</td> <td>${item.tihuo}</td> </tr> </c:forEach> </table> </div> </body> </html>
ps:所有的返回主页均可直接返回主页面