标签:增删改查 table 方法 管理 post tle drive std object
先实现第一个要求及名称,厂家,型号,规格的增删改查再完成出入库单据的增查。
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 { /** * 添加 * @param course * @return */ public boolean add(Course course) { String sql = "insert into course(name, producer, model,standard,number,date,time,monad,people) values(‘" + course.getName() + "‘,‘" + course.getProducer() + "‘,‘" + course.getModel() + "‘,‘" + course.getStandard() + "‘,‘" + course.getNumber() + "‘,‘" + course.getDate() + "‘,‘" + course.getTime() + "‘,‘" + course.getMonad() + "‘,‘" + course.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) { 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; } /** * 修改 * @param name * @param pass */ public boolean update(Course course) { String sql = "update course set name=‘" + course.getName() + "‘, producer=‘" + course.getProducer() + "‘, model=‘" + course.getModel()+ "‘, standard=‘" + course.getStandard()+ "‘ 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; } /** * 验证课程名称是否唯一 * true --- 不唯一 * @param name * @return */ 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; } /** * 通过ID得到类 * @param id * @return */ 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 producer = rs.getString("producer"); String model = rs.getString("model"); String standard = rs.getString("standard"); String number = rs.getString("number"); String date = rs.getString("date"); String time = rs.getString("time"); String monad = rs.getString("monad"); String people = rs.getString("people"); course = new Course(name, producer, model,standard,number,date,time,monad,people); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return course; } /** * 通过name得到Course * @param name * @return */ 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 producer = rs.getString("producer"); String model = rs.getString("model"); String standard = rs.getString("standard"); String number = rs.getString("number"); String date = rs.getString("date"); String time = rs.getString("time"); String monad = rs.getString("monad"); String people = rs.getString("people"); course = new Course(name, producer, model,standard,number,date,time,monad,people); } } catch (Exception e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return course; } /** * 查找 * @param name * @param producer * @param model * @return */ public List<Course> search(String name, String producer, String model,String standard,String number,String date,String time,String monad,String people) { String sql = "select * from course where "; if (name != "") { sql += "name like ‘%" + name + "%‘"; } if (producer != "") { sql += "producer like ‘%" + producer + "%‘"; } if (model != "") { sql += "model like ‘%" + model + "%‘"; } if (standard != "") { sql += "standard like ‘%" + standard + "%‘"; } if (number != "") { sql += "standard like ‘%" + number + "%‘"; } if (date != "") { sql += "standard like ‘%" + date + "%‘"; } if (time != "") { sql += "standard like ‘%" + time + "%‘"; } if (monad != "") { sql += "standard like ‘%" + monad + "%‘"; } if (people != "") { sql += "standard like ‘%" + people + "%‘"; } 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 producer2 = rs.getString("producer"); String model2 = rs.getString("model"); String standard2 = rs.getString("standard"); String number2 = rs.getString("number"); String date2 = rs.getString("date"); String time2 = rs.getString("time"); String monad2 = rs.getString("monad"); String people2 = rs.getString("people"); bean = new Course(id, name2, producer2, model2,standard2,number2,date2,time2,monad2,people2); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } /** * 全部数据 * @param name * @param producer * @param model * @return */ 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 producer2 = rs.getString("producer"); String model2 = rs.getString("model"); String standard2 = rs.getString("standard"); String number2 = rs.getString("number"); String date2 = rs.getString("date"); String time2 = rs.getString("time"); String monad2 = rs.getString("monad"); String people2 = rs.getString("people"); bean = new Course(id, name2, producer2, model2,standard2,number2,date2,time2,monad2,people2); list.add(bean); } } catch (SQLException e) { e.printStackTrace(); } finally { DBUtil.close(rs, state, conn); } return list; } }
package com.hjf.entity; public class Course { private int id; private String name; private String producer; private String model; private String standard; private String number; private String date; private String time; private String monad; private String people; 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 getProducer() { return producer; } public void setProducer(String producer) { this.producer = producer; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public String getStandard() { return standard; } public void setStandard(String standard) { this.standard = standard; } public void setNumber(String number) { this.number = number; } public String getNumber() { return number; } public void setDate(String date) { this.date = date; } public String getDate() { return date; } public void setTime(String time) { this.time = time; } public String getTime() { return time; } public void setMonad(String monad) { this.monad = monad; } public String getMonad() { return monad; } public void setPeople(String people) { this.people = people; } public String getPeople() { return people; } public Course() {} public Course(int id, String name, String producer, String model,String standard,String number,String date,String time,String monad,String people) { this.id = id; this.name = name; this.producer = producer; this.model = model; this.standard = standard; this.number = number; this.date = date; this.time = time; this.monad = monad; this.people = people; } public Course(String name, String producer, String model,String standard,String number,String date,String time,String monad,String people) { this.name = name; this.producer = producer; this.model = model; this.standard = standard; this.number = number; this.date = date; this.time = time; this.monad = monad; this.people = people; } }
package com.hjf.service; import java.util.List; import com.hjf.dao.CourseDao; import com.hjf.entity.Course; /** * CourseService * 服务层 * */ 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); } /** * 通过ID得到一个Course * @return */ public Course getCourseById(int id) { return cDao.getCourseById(id); } /** * 通过Name得到一个Course * @return */ public Course getCourseByName(String name) { return cDao.getCourseByName(name); } /** * 查找 * @return */ public List<Course> search(String name, String producer, String model,String standard,String number,String date,String time,String monad,String people) { return cDao.search(name, producer, model,standard,number,date,time,monad,people); } /** * 全部数据 * @return */ public List<Course> list() { return cDao.list(); } public boolean add1(Course course) { // TODO Auto-generated method stub boolean f = false; if(!cDao.name(course.getName())) { cDao.add(course); f = true; } return f; } }
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 producer = req.getParameter("producer"); String model = req.getParameter("model"); String standard = req.getParameter("standard"); String number = req.getParameter("number"); String date = req.getParameter("date"); String time = req.getParameter("time"); String monad = req.getParameter("monad"); String people = req.getParameter("people"); Course course = new Course(name, producer, model,standard,number,date,time,monad,people); //添加后消息显示 if(service.add(course)) { 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); } /** * 通过ID得到Course * @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 producer = req.getParameter("producer"); String model = req.getParameter("model"); String standard = req.getParameter("standard"); String number = req.getParameter("number"); String date = req.getParameter("date"); String time = req.getParameter("time"); String monad = req.getParameter("monad"); String people = req.getParameter("people"); Course course = new Course(id,name, producer, model,standard,number,date,time,monad,people); 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 producer = req.getParameter("producer"); String model = req.getParameter("model"); String standard = req.getParameter("standard"); String number = req.getParameter("number"); String date = req.getParameter("date"); String time = req.getParameter("time"); String monad = req.getParameter("monad"); String people = req.getParameter("people"); List<Course> courses = service.search(name, producer,model,standard,number,date,time,monad,people); req.setAttribute("courses", courses); req.getRequestDispatcher("searchlist.jsp").forward(req,resp); } }
package com.hjf.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 db_url = "jdbc:mysql://localhost:3306/mysql?useSSL=false"; public static String db_user = "root"; public static String db_pass = "123456"; 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>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>id</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.producer}</td> <td>${item.model}</td> <td>${item.standard}</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="CourseServlet?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="producer" name="producer" /> </div> <div class="a"> 型号 <input type="text" id="model" name="model" /> </div> <div class="a"> 规格 <input type="text" id="standard" name="standard" /> </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 producer = document.getElementById("producer"); var model = document.getElementById("model"); var standard = document.getElementById("standard"); //非空 if(name.value == ‘‘ && producer.value == ‘‘ && model.value == ‘‘) { alert(‘请填写一个条件‘); 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> <% 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.producer}</td> <td>${item.model}</td> <td>${item.standard}</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> <% 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" onsubmit="return check()"> <div class="a"> 商品名称<input type="text" id="name" name="name" value="${control.name}"/> </div> <div class="a"> 生产厂家<input type="text" id="producer" name="producer" value="${control.producer}"/> </div> <div class="a"> 型号 <input type="text" id="model" name="model" value="${control.model}"/> </div> <div class="a"> 型号 <input type="text" id="standard" name="standard" value="${control.standard}"/> </div> <input type="hidden" id="id" name="id" value="${control.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 producer = document.getElementById("producer"); var model = document.getElementById("model"); var standard = document.getElementById("standard"); //非空 if(name.value == ‘‘) { alert(‘商品名称为空‘); name.focus(); return false; } if(producer.value == ‘‘) { alert(‘生产厂家为空‘); producer.focus(); return false; } if(model.value == ‘‘) { alert(‘型号为空‘); model.focus(); return false; } if(standard.value == ‘‘) { alert(‘规格为空‘); model.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>${control.name}</td> </tr> <tr> <td>生产厂家</td> <td>${control.producer}</td> </tr> <tr> <td> 型号 </td> <td>${control.model}</td> </tr> <tr> <td> 规格 </td> <td>${control.standard}</td> </tr> </table> <div class="a"> <a onclick="return check()" href="CourseServlet?method=del&id=${control.id}">删 除</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>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="CourseServlet?method=getcoursebyname" 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>
<%@ 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="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="producer" name="producer" /> </div> <div class="a"> 型号<input type="text" id="model" name="model" /> </div> <div class="a"> 规格<input type="text" id="standard" name="standard" /> </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 producer = document.getElementById("producer"); var model = document.getElementById("model"); var standard = document.getElementById("standard"); //非空 if(name.value == ‘‘) { alert(‘商品名称为空‘); name.focus(); return false; } if(producer.value == ‘‘) { alert(‘生产厂家为空‘); producer.focus(); return false; } if(model.value == ‘‘) { alert(‘型号为空‘); model.focus(); return false; } if(standard.value == ‘‘) { alert(‘规格为空‘); model.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; } </style> </head> <body> <div align="center"> <h1 style="color: red;">出入库信息信息查询</h1> <a href="index.jsp">返回主页</a> <form action="CourseServlet?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="producer" name="producer" /> </div> <div class="a"> 型号 <input type="text" id="model" name="model" /> </div> <div class="a"> 规格 <input type="text" id="standard" name="standard" /> </div> <div class="a"> 数量<input type="text" id="number" name="number" /> </div> <div class="a"> 日期<input type="text" id="date" name="date" /> </div> <div class="a"> 时间<input type="text" id="time" name="time" /> </div> <div class="a"> 出库/入库单位<input type="text" id="monad" name="monad" /> </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 producer = document.getElementById("producer"); var model = document.getElementById("model"); var standard = document.getElementById("standard"); //非空 if(name.value == ‘‘ && producer.value == ‘‘ && model.value == ‘‘) { alert(‘请填写一个条件‘); 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; } </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="producer" name="producer" /> </div> <div class="a"> 型号<input type="text" id="model" name="model" /> </div> <div class="a"> 规格<input type="text" id="standard" name="standard" /> </div> <div class="a"> 数量<input type="text" id="number" name="number" /> </div> <div class="a"> 日期<input type="text" id="date" name="date" /> </div> <div class="a"> 时间<input type="text" id="time" name="time" /> </div> <div class="a"> 出库/入库单位<input type="text" id="monad" name="monad" /> </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 producer = document.getElementById("producer"); var model = document.getElementById("model"); var standard = document.getElementById("standard"); var standard = document.getElementById("number"); var standard = document.getElementById("date"); var standard = document.getElementById("time"); var standard = document.getElementById("monad"); var standard = document.getElementById("people"); //非空 if(name.value == ‘‘) { alert(‘商品名称为空‘); name.focus(); return false; } if(producer.value == ‘‘) { alert(‘生产厂家为空‘); producer.focus(); return false; } if(model.value == ‘‘) { alert(‘型号为空‘); model.focus(); return false; } if(standard.value == ‘‘) { alert(‘规格为空‘); model.focus(); return false; } if(number.value == ‘‘) { alert(‘数量为空‘); model.focus(); return false; } if(date.value == ‘‘) { alert(‘日期为空‘); model.focus(); return false; } if(time.value == ‘‘) { alert(‘时间为空‘); model.focus(); return false; } if(monad.value == ‘‘) { alert(‘入库或出库单位为空‘); model.focus(); return false; } if(people.value == ‘‘) { alert(‘送货或提货人姓名为空‘); model.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="CourseServlet?method=list">商品信息修改</a> </div> <div class="a"> <a href="del.jsp">商品信息删除</a> </div> <div class="a"> <a href="search.jsp">商品信息查询</a> </div> <div class="a"> <a href="add1.jsp">商品出入库录入</a> </div> <div class="a"> <a href="search1.jsp">商品出入库查询</a> </div> </div> </body> </html>
标签:增删改查 table 方法 管理 post tle drive std object
原文地址:https://www.cnblogs.com/gkl20173667/p/10116514.html