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.Product; import com.hjf.util.DBUtil; /** * 课程Dao * Dao层操作数据 * @author Zheng * */ public class ProductDao { /** * 添加 增 * @param course * @return */ public boolean add(Product product) { String sql = "insert into product(name, home, type, guige, num, data, time, people) values('" + product.getName() + "','" + product.getHome() + "','" + product.getType() + "','"+product.getGuige()+"','"+product.getNum()+"','"+product.getData()+"','"+product.getTime()+"','"+product.getPeople()+"')"; 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; } /** * 删除 * *参数 @param id * @return */ public boolean delete (int id) { String sql = "delete from product where id='" + id + "'"; 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; } /** * 修改 * @param name * @param pass */ public boolean update(Product product) { String sql = "update product set name='" + product.getName() + "', home='" + product.getHome() + "', type='" + product.getType() + "',guige='" + product.getGuige() + "',num='" + product.getNum() + "',data='" + product.getData() + "',time='" + product.getTime() + "',people='" + product.getPeople() + "' where id='" + product.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; } /** * 验证商品名称是否唯一 * true --- 不唯一 * @param name * @return */ public boolean name(String name) { boolean flag = false; String sql = "select name from product 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; } /** * 通过ID得到类 * @param id * @return */ public Product getProductById(int id) { String sql = "select * from product where id ='" + id + "'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; Product product = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { String name = rs.getString("name"); String home = rs.getString("home"); String type = rs.getString("type"); String guige=rs.getString("guige"); String num=rs.getString("num"); String data=rs.getString("data"); String time=rs.getString("time"); String people=rs.getString("people"); product = new Product(id, name, home, type, guige, num, data, time, people); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return product; } /** * 通过name得到Product * @param name * @return */ public Product getProductByName(String name) { String sql = "select * from product where name ='" + name + "'"; Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; Product product = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { int id = rs.getInt("id"); String home = rs.getString("home"); String type = rs.getString("type"); String guige = rs.getString("guige"); String num=rs.getString("num"); String data=rs.getString("data"); String time=rs.getString("time"); String people=rs.getString("people"); product = new Product(id, name, home, type, guige, num, data, time, people); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return product; } /** * 查找 * @param name * @param home * @param type * @param guige * @param num * @return */ public List<Product> search(String name, String data) { String sql = "select * from product where "; if (name != "") { sql += "name like '%" + name + "%'"; } if (data != "") { sql += "data like '%" + data + "%'"; } List<Product> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Product bean = null; while (rs.next()) { int id = rs.getInt("id"); String name2 = rs.getString("name"); String home2=rs.getString("home"); String type2=rs.getString("type"); String guige2=rs.getString("guige"); String num2=rs.getString("num"); String data2=rs.getString("data"); String time2=rs.getString("time"); String people2=rs.getString("people"); bean = new Product(id, name2, home2, type2, guige2, num2, data2, time2, people2); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } /** * 全部数据 * @param name * @param home * @param type * @param guige * @param num * @param data * @param time * @param people * @return */ public List<Product> list() { String sql = "select * from product"; List<Product> list = new ArrayList<>(); Connection conn = DBUtil.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); Product bean = null; while (rs.next()) { int id = rs.getInt("id"); String name2 = rs.getString("name"); String home2 = rs.getString("home"); String type2 = rs.getString("type"); String guige2 = rs.getString("guige"); String num2=rs.getString("num"); String data2=rs.getString("data"); String time2=rs.getString("time"); String people2=rs.getString("people"); bean = new Product(id, name2, home2, type2, guige2, num2, data2, time2, people2); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } }
dao层负责对数据库的基本操作,进行增删改查的操作
在数据的写入时一定要注意顺序,否则将带来不可挽回的错误
package com.hjf.entity; public class Product { private int id; private String name; private String home; private String type; private String guige; private String num; private String data; private String time; private String people; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getHome() { return home; } public void setHome(String home) { this.home = home; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getGuige() { return guige; } public void setGuige(String guige) { this.guige = guige; } public String getNum() { return num; } public void setNum(String num) { this.num=num; } public String getData() { return data; } public void setData(String data) { this.data = data; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } public String getPeople() { return people; } public void setPeople(String people) { this.people = people; } public Product() {} //*构造方法 public Product(int id, String name, String home, String type,String guige,String num,String data,String time,String people) { this.id = id; this.home = home; this.type = type; this.guige = guige; this.num=num; this.data=data; this.time=time; this.people=people; this.name=name; } public Product(String name, String home, String type,String guige,String num,String data,String time,String people) { this.home = home; this.type = type; this.guige = guige; this.num=num; this.data=data; this.time=time; this.people=people; this.name=name; } public Product(int id,String data,String name) { this.id = id; this.data=data; this.name=name; } }
实体类Product初始化所需要的变量,并为变量增加get、set方法并设置构造函数
package com.hjf.service; import java.util.List; import com.hjf.dao.ProductDao; import com.hjf.entity.Product; /** * CourseService * 服务层 * @author Zheng * */ public class ProductService { ProductDao pDao = new ProductDao(); /** * 添加 * @param course * @return */ public boolean add(Product product) { boolean f = false; if(!pDao.name(product.getName())) { pDao.add(product); f = true; } return f; } /** * 删除 */ public void del(int id) { pDao.delete(id); } /** * 修改 * @return */ public void update(Product product) { pDao.update(product); } /** * 通过ID得到一个Product * @return */ public Product getProductById(int id) { return pDao.getProductById(id); } /** * 通过Name得到一个Course * @return */ public Product getProductByName(String name) { return pDao.getProductByName(name); } /** * 查找 * @return */ public List<Product> search(String name, String data) { return pDao.search(name, data); } /** * 全部数据 * @return */ public List<Product> list() { return pDao.list(); } }
用于服务
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.Product; import com.hjf.service.ProductService; @WebServlet("/ProductServlet") public class ProductServlet extends HttpServlet { private static final long serialVersionUID = 1L; ProductService service = new ProductService(); /** * 方法选择 */ 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 ("getproductbyid".equals(method)) { getProductById(req, resp); } else if ("getproductbyname".equals(method)) { getProductByName(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 home = req.getParameter("home"); String type = req.getParameter("type"); String guige = req.getParameter("guige"); String num = req.getParameter("num"); String data = req.getParameter("data"); String time = req.getParameter("time"); String people = req.getParameter("people"); Product product = new Product(name, home, type, guige, num, data, time, people); //添加后消息显示 if(service.add(product)) { 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<Product> products = service.list(); req.setAttribute("products", products); for(int i = 0; i < products.size(); i++) { System.out.println(products.get(i).getName()); } req.getRequestDispatcher("list.jsp").forward(req,resp); } /** * 通过ID得到Course * @param req * @param resp * @throws ServletException */ private void getProductById(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); int id = Integer.parseInt(req.getParameter("id")); Product product = service.getProductById(id); req.setAttribute("product", product); req.getRequestDispatcher("detail2.jsp").forward(req,resp); } /** * 通过名字查找 * 跳转至删除 * @param req * @param resp * @throws IOException * @throws ServletException */ private void getProductByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); String name = req.getParameter("name"); Product product = service.getProductByName(name); if(product == null) { req.setAttribute("message", "查无此商品!"); req.getRequestDispatcher("del.jsp").forward(req,resp); } else { req.setAttribute("product", product); 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"); String name = req.getParameter("name"); String home = req.getParameter("home"); String type = req.getParameter("type"); String guige = req.getParameter("guige"); String num = req.getParameter("num"); String data = req.getParameter("data"); String time = req.getParameter("time"); String people = req.getParameter("people"); Product product = new Product(name, home, type, guige, num, data, time, people); service.update(product); req.setAttribute("message", "修改成功"); req.getRequestDispatcher("ProductServlet?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 data = req.getParameter("data"); List<Product> products = service.search(name, data); req.setAttribute("products", products); req.getRequestDispatcher("searchlist.jsp").forward(req,resp); } }
用于对各jsp文件之间进行跳转等操作
package com.hjf.util; //数据库连接 import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * 数据库连接工具 * @author Zheng * */ public class DBUtil { public static String db_url = "jdbc:mysql://localhost:3306/test?useSSL=false"; public static String db_user = "root"; public static String db_pass = "root"; public static Connection getConn () { Connection conn = null; try { Class.forName("com.mysql.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(); } } } }
链接数据库的公式,很实用改个密码、数据库名便可以轻松上手
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>写入</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="CourseServlet?method=add" method="post" onsubmit="return check()"> <div class="a"> 商品名称<input type="text" id="name" name="name"/> </div> <div class="a"> 生产厂家<input type="text" id="home" name="home" /> </div> <div class="a"> 型号<input type="text" id="type" name="type" /> </div> <div class="a"> 规格<input type="text" id="guige" name="guige" /> </div> <div class="a"> 数量<input type="text" id="num" name="num" /> </div> <div class="a"> 日期<input type="text" id="data" name="data" /> </div> <div class="a"> 时间<input type="text" id="time" name="time" /> </div> <div class="a"> 入库单位及姓名<input type="text" id="people" name="people" /> </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 home = document.getElementById("home"); var type = document.getElementById("type"); var guige = document.getElementById("guige"); var num = document.getElementById("num"); var data = document.getElementById("data"); var time = document.getElementById("time"); var people = document.getElementById("people"); //非空 if(name.value == '') { alert('商品名称为空'); name.focus(); return false; } if(home.value == '') { alert('生产厂家为空'); home.focus(); return false; } if(type.value == '') { alert('型号为空'); type.focus(); return false; } if(guige.value == '') { alert('规格为空'); guige.focus(); return false; } if(num.value == '') { alert('数量为空'); num.focus(); return false; } if(data.value == '') { alert('日期为空'); data.focus(); return false; } if(time.value == '') { alert('时间为空'); time.focus(); return false; } if(people.value == '') { alert('入库单位为空'); type.focus(); return false; } } </script> </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: 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="ProductServlet?method=getproductbyname" method="post" onsubmit="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");; //非空 if(name.value == '') { alert('商品名称为空'); name.focus(); return false; } } </script> </body> </html>
用于删除的jsp
del.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{ 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>${product.name}</td> </tr> <tr> <td>生产厂家</td> <td>${product.home}</td> </tr> <tr> <td>型号</td> <td>${product.type}</td> </tr> <tr> <td>规格</td> <td>${product.guige}</td> </tr> <tr> <td>数量</td> <td>${product.num}</td> </tr> <tr> <td>日期</td> <td>${product.data}</td> </tr> <tr> <td>时间</td> <td>${product.time}</td> </tr> <tr> <td>入库单位及姓名</td> <td>${product.people}</td> </tr> </table> <div class="a"> <a onclick="return check()" href="ProductServlet?method=del&id=${product.id}">删 除</a> </div> </div> <script type="text/javascript"> function check() { if (confirm("真的要删除吗?")){ return true; }else{ return false; } } </script> </body> </html>
detail.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{ 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="ProductServlet?method=update" method="post" onsubmit="return check()"> <div class="a"> 商品名称<input type="text" id="name" name="name" value="${product.name}"/> </div> <div class="a"> 生产厂家<input type="text" id="home" name="home" value="${product.home}"/> </div> <div class="a"> 型号<input type="text" id="type" name="type" value="${product.type}"/> </div> <div class="a"> 规格<input type="text" id="guige" name="guige" value="${product.guige}"/> </div> <div class="a"> 数量<input type="text" id="num" name="num" value="${product.num}"/> </div> <div class="a"> 日期<input type="text" id="data" name="data" value="${product.data}"/> </div> <div class="a"> 时间<input type="text" id="time" name="time" value="${product.time}"/> </div> <div class="a"> 入库单位及姓名<input type="text" id="people" name="people" value="${product.people}"/> </div> <input type="hidden" id="id" name="id" value="${product.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 home = document.getElementById("home"); var type = document.getElementById("type"); var guige = document.getElementById("guige"); var num = document.getElementById("num"); var data = document.getElementById("data"); var time = document.getElementById("time"); var people = document.getElementById("people"); //非空 if(name.value == '') { alert('商品名称为空'); name.focus(); return false; } if(home.value == '') { alert('生产厂家为空'); home.focus(); return false; } if(type.value == '') { alert('型号为空'); type.focus(); return false; } if(guige.value == '') { alert('规格为空'); guige.focus(); return false; } if(num.value == '') { alert('数量为空'); num.focus(); return false; } if(data.value == '') { alert('日期为空'); data.focus(); return false; } if(time.value == '') { alert('时间为空'); time.focus(); return false; } if(people.value == '') { alert('入库单位为空'); people.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>首页</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="ProductServlet?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>
<%@ 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> <table class="tb"> <tr> <td>id</td> <td>商品名称</td> <td>生产厂家</td> <td>型号</td> <td>规格</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.type}</td> <td>${item.guige}</td> <td>${item.num}</td> <td>${item.data}</td> <td>${item.time}</td> <td>${item.people}</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: white; background-color: greenyellow; } </style> </head> <body> <div align="center"> <h1 style="color: red;">商品信息查询</h1> <a href="index.jsp">返回主页</a> <form action="ProductServlet?method=search" method="post" onsubmit="return check()"> <div class="a"> 商品名称<input type="text" id="name" name="name"/> </div> <div class="a"> 日期<input type="text" id="data" name="data" /> </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 data = document.getElementById("data"); //非空 if(name.value == '' && data.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>查找信息列表</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>id</td> <td>商品名称</td> <td>生产厂家</td> <td>型号</td> <td>规格</td> <td>数量</td> <td>日期</td> <td>时间</td> <td>入库单位及姓名</td> </tr> <!-- forEach遍历出adminBeans --> <c:forEach items="${products}" var="item" varStatus="status"> <tr> <td>${item.id}</td> <td>${item.name}</td> <td>${item.home}</td> <td>${item.type}</td> <td>${item.guige}</td> <td>${item.num}</td> <td>${item.data}</td> <td>${item.time}</td> <td>${item.people}</td> </tr> </c:forEach> </table> </div> </body> </html>
这样就算只是完成了一半还差出库入库的单子需要打印并输出!