仓库管理msi系统
实验思路:
建表:
代码:
1 package com.hjf.util; 2 3 import java.sql.Connection; 4 import java.sql.DriverManager; 5 import java.sql.ResultSet; 6 import java.sql.SQLException; 7 import java.sql.Statement; 8 9 /** 10 * 鏁版嵁搴撹繛鎺ュ伐鍏� 11 * @author Hu 12 * 13 */ 14 public class DBUtil { 15 16 public static String db_url = "jdbc:mysql://localhost:3306/ware?useSSL=false&useUnicode=true&characterEncoding=UTF-8"; 17 public static String db_user = "root"; 18 public static String db_pass = "15568958907lx"; 19 20 public static Connection getConn () { 21 Connection conn = null; 22 23 try { 24 Class.forName("com.mysql.jdbc.Driver");//鍔犺浇椹卞姩 25 conn = DriverManager.getConnection(db_url, db_user, db_pass); 26 } catch (Exception e) { 27 e.printStackTrace(); 28 } 29 30 return conn; 31 } 32 33 /** 34 * 鍏抽棴杩炴帴 35 * @param state 36 * @param conn 37 */ 38 public static void close (Statement state, Connection conn) { 39 if (state != null) { 40 try { 41 state.close(); 42 } catch (SQLException e) { 43 e.printStackTrace(); 44 } 45 } 46 47 if (conn != null) { 48 try { 49 conn.close(); 50 } catch (SQLException e) { 51 e.printStackTrace(); 52 } 53 } 54 } 55 56 public static void close (ResultSet rs, Statement state, Connection conn) { 57 if (rs != null) { 58 try { 59 rs.close(); 60 } catch (SQLException e) { 61 e.printStackTrace(); 62 } 63 } 64 65 if (state != null) { 66 try { 67 state.close(); 68 } catch (SQLException e) { 69 e.printStackTrace(); 70 } 71 } 72 73 if (conn != null) { 74 try { 75 conn.close(); 76 } catch (SQLException e) { 77 e.printStackTrace(); 78 } 79 } 80 } 81 82 }
1 package com.hjf.servlet; 2 3 import java.io.IOException; 4 import java.util.List; 5 6 import javax.servlet.ServletException; 7 import javax.servlet.annotation.WebServlet; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 import com.hjf.dao.CourseDao; 13 import com.hjf.entity.Course; 14 import com.hjf.service.CourseService; 15 16 @WebServlet("/CourseServlet") 17 public class CourseServlet extends HttpServlet { 18 19 private static final long serialVersionUID = 1L; 20 21 CourseDao dao = new CourseDao(); 22 23 /** 24 * 方法选择 25 */ 26 protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 27 req.setCharacterEncoding("utf-8"); 28 String method = req.getParameter("method"); 29 30 if ("add".equals(method)) { 31 add(req, resp); 32 } else if ("del".equals(method)) { 33 del(req, resp); 34 } else if ("update".equals(method)) { 35 update(req, resp); 36 } else if ("search".equals(method)) { 37 search(req, resp); 38 } else if ("getcoursebyid".equals(method)) { 39 getCourseById(req, resp); 40 } else if ("getcoursebyname".equals(method)) { 41 getCourseByName(req, resp); 42 } else if ("list".equals(method)) { 43 list(req, resp); 44 } 45 } 46 47 /** 48 * 添加 49 * @param req 50 * @param resp 51 * @throws IOException 52 * @throws ServletException 53 */ 54 private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { 55 req.setCharacterEncoding("utf-8"); 56 //获取数据 57 String name = req.getParameter("name"); 58 String factory = req.getParameter("factory"); 59 String model = req.getParameter("model"); 60 String spec = req.getParameter("spec"); 61 Course course = new Course(name, factory, model,spec); 62 63 //添加后消息显示 64 if(dao.add(course)) { 65 req.setAttribute("message", "添加成功"); 66 req.getRequestDispatcher("add.jsp").forward(req,resp); 67 } else { 68 req.setAttribute("message", "名称重复,请重新录入"); 69 req.getRequestDispatcher("add.jsp").forward(req,resp); 70 } 71 } 72 73 /** 74 * 全部 75 * @param req 76 * @param resp 77 * @throws ServletException 78 */ 79 private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ 80 req.setCharacterEncoding("utf-8"); 81 82 List<Course> courses = dao.list(); 83 req.setAttribute("courses", courses); 84 req.getRequestDispatcher("list.jsp").forward(req,resp); 85 } 86 87 /** 88 * 通过ID得到Course 89 * @param req 90 * @param resp 91 * @throws ServletException 92 */ 93 private void getCourseById(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ 94 req.setCharacterEncoding("utf-8"); 95 int id = Integer.parseInt(req.getParameter("id")); 96 Course course = dao.getCourseById(id); 97 req.setAttribute("course", course); 98 req.getRequestDispatcher("detail2.jsp").forward(req,resp); 99 } 100 101 /** 102 * 通过名字查找 103 * 跳转至删除 104 * @param req 105 * @param resp 106 * @throws IOException 107 * @throws ServletException 108 */ 109 private void getCourseByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ 110 req.setCharacterEncoding("utf-8"); 111 String name = req.getParameter("name"); 112 Course course = dao.getCourseByName(name); 113 if(course == null) { 114 req.setAttribute("message", "查无此课程!"); 115 req.getRequestDispatcher("del.jsp").forward(req,resp); 116 } else { 117 req.setAttribute("course", course); 118 req.getRequestDispatcher("detail.jsp").forward(req,resp); 119 } 120 } 121 122 /** 123 * 删除 124 * @param req 125 * @param resp 126 * @throws IOException 127 * @throws ServletException 128 */ 129 private void del(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ 130 req.setCharacterEncoding("utf-8"); 131 int id = Integer.parseInt(req.getParameter("id")); 132 dao.delete(id); 133 req.setAttribute("message", "删除成功!"); 134 req.getRequestDispatcher("del.jsp").forward(req,resp); 135 } 136 137 /** 138 * 修改 139 * @param req 140 * @param resp 141 * @throws IOException 142 * @throws ServletException 143 */ 144 private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ 145 req.setCharacterEncoding("utf-8"); 146 int id = Integer.parseInt(req.getParameter("id")); 147 String name = req.getParameter("name"); 148 String factory = req.getParameter("factory"); 149 String model = req.getParameter("model"); 150 String spec = req.getParameter("spec"); 151 Course course = new Course(id, name, factory, model,spec); 152 153 dao.update(course); 154 req.setAttribute("message", "修改成功"); 155 req.getRequestDispatcher("CourseServlet?method=list").forward(req,resp); 156 } 157 158 /** 159 * 查找 160 * @param req 161 * @param resp 162 * @throws ServletException 163 */ 164 private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ 165 req.setCharacterEncoding("utf-8"); 166 String name = req.getParameter("name"); 167 String factory = req.getParameter("factory"); 168 String model = req.getParameter("model"); 169 String spec = req.getParameter("spec"); 170 List<Course> courses = dao.search(name, factory, model,spec); 171 req.setAttribute("courses", courses); 172 req.getRequestDispatcher("searchlist.jsp").forward(req,resp); 173 } 174 }
1 package com.hjf.entity; 2 3 public class Course { 4 5 private int id; 6 private String name; 7 private String factory; 8 private String model; 9 private String spec; 10 public int getId() { 11 return id; 12 } 13 public void setId(int id) { 14 this.id = id; 15 } 16 public String getName() { 17 return name; 18 } 19 public void setName(String name) { 20 this.name = name; 21 } 22 public String getfactory() { 23 return factory; 24 } 25 public void setTeacher(String factory) { 26 this.factory = factory; 27 } 28 public String getmodel() { 29 return model; 30 } 31 public void setClassroom(String model) { 32 this.model = model; 33 } 34 public void setspec(String spec){ 35 this.spec=spec; 36 } 37 public String getspec(){ 38 return spec; 39 } 40 public Course() {} 41 42 public Course(int id, String name, String teacher, String classroom,String spec) { 43 this.id = id; 44 this.name = name; 45 this.factory = factory; 46 this.model = model; 47 this.spec=spec; 48 } 49 50 public Course(String name, String teacher, String classroom,String spec) { 51 this.name = name; 52 this.factory = factory; 53 this.model = model; 54 this.spec=spec; 55 } 56 }
1 package com.hjf.dao; 2 3 import java.sql.Connection; 4 5 import java.sql.ResultSet; 6 import java.sql.SQLException; 7 import java.sql.Statement; 8 import java.util.ArrayList; 9 import java.util.List; 10 11 import com.hjf.entity.Course; 12 import com.hjf.util.DBUtil; 13 14 /** 15 * 璇剧▼Dao 16 * Dao灞傛搷浣滄暟鎹� 17 * @author Hu 18 * 19 */ 20 public class CourseDao { 21 22 /** 23 * 娣诲姞 24 * @param course 25 * @return 26 */ 27 public boolean add(Course course) { 28 String sql = "insert into ware(name, factory, model ,spec) values('" + course.getName() + "','" + course.getfactory() + "','" + course.getmodel() + "','"+course.getspec() + "')"; 29 Connection conn = DBUtil.getConn(); 30 Statement state = null; 31 boolean f = false; 32 int a = 0; 33 34 try { 35 state = conn.createStatement(); 36 a = state.executeUpdate(sql); 37 } catch (Exception e) { 38 e.printStackTrace(); 39 } finally { 40 DBUtil.close(state, conn); 41 } 42 43 if (a > 0) { 44 f = true; 45 } 46 return f; 47 } 48 49 /** 50 * 鍒犻櫎 51 * 52 * @param id 53 * @return 54 */ 55 public boolean delete (int id) { 56 boolean f = false; 57 String sql = "delete from ware where id='" + id + "'"; 58 Connection conn = DBUtil.getConn(); 59 Statement state = null; 60 int a = 0; 61 62 try { 63 state = conn.createStatement(); 64 a = state.executeUpdate(sql); 65 } catch (SQLException e) { 66 e.printStackTrace(); 67 } finally { 68 DBUtil.close(state, conn); 69 } 70 71 if (a > 0) { 72 f = true; 73 } 74 return f; 75 } 76 77 /** 78 * 淇敼 79 * @param name 80 * @param pass 81 */ 82 public boolean update(Course course) { 83 String sql = "update ware set name='" + course.getName() + "',factory='" + course.getfactory() + "', model='" + course.getmodel() + "', spec='" + course.getspec() 84 + "' where id='" + course.getId() + "'"; 85 Connection conn = DBUtil.getConn(); 86 Statement state = null; 87 boolean f = false; 88 int a = 0; 89 90 try { 91 state = conn.createStatement(); 92 a = state.executeUpdate(sql); 93 } catch (SQLException e) { 94 e.printStackTrace(); 95 } finally { 96 DBUtil.close(state, conn); 97 } 98 99 if (a > 0) { 100 f = true; 101 } 102 return f; 103 } 104 105 /** 106 * 楠岃瘉璇剧▼鍚嶇О鏄惁鍞竴 107 * true --- 涓嶅敮涓� 108 * @param name 109 * @return 110 */ 111 public boolean name(String name) { 112 boolean flag = false; 113 String sql = "select name from ware where name = '" + name + "'"; 114 Connection conn = DBUtil.getConn(); 115 Statement state = null; 116 ResultSet rs = null; 117 118 try { 119 state = conn.createStatement(); 120 rs = state.executeQuery(sql); 121 while (rs.next()) { 122 flag = true; 123 } 124 } catch (SQLException e) { 125 e.printStackTrace(); 126 } finally { 127 DBUtil.close(rs, state, conn); 128 } 129 return flag; 130 } 131 132 /** 133 * 閫氳繃ID寰楀埌绫� 134 * @param id 135 * @return 136 */ 137 public Course getCourseById(int id) { 138 String sql = "select * from ware where id ='" + id + "'"; 139 Connection conn = DBUtil.getConn(); 140 Statement state = null; 141 ResultSet rs = null; 142 Course course = null; 143 144 try { 145 state = conn.createStatement(); 146 rs = state.executeQuery(sql); 147 while (rs.next()) { 148 String name = rs.getString("name"); 149 String factory = rs.getString("factory"); 150 String model = rs.getString("model"); 151 String spec = rs.getString("spec"); 152 course = new Course(id, name, factory, model,spec); 153 } 154 } catch (Exception e) { 155 e.printStackTrace(); 156 } finally { 157 DBUtil.close(rs, state, conn); 158 } 159 160 return course; 161 } 162 163 /** 164 * 閫氳繃name寰楀埌Course 165 * @param name 166 * @return 167 */ 168 public Course getCourseByName(String name) { 169 String sql = "select * from ware where name ='" + name + "'"; 170 Connection conn = DBUtil.getConn(); 171 Statement state = null; 172 ResultSet rs = null; 173 Course course = null; 174 175 try { 176 state = conn.createStatement(); 177 rs = state.executeQuery(sql); 178 while (rs.next()) { 179 int id = rs.getInt("id"); 180 String factory = rs.getString("factory"); 181 String model = rs.getString("model"); 182 String spec = rs.getString("spec"); 183 course = new Course(id, name, factory, model,spec); 184 } 185 } catch (Exception e) { 186 e.printStackTrace(); 187 } finally { 188 DBUtil.close(rs, state, conn); 189 } 190 191 return course; 192 } 193 194 /** 195 * 鏌ユ壘 196 * @param name 197 * @param teacher 198 * @param classroom 199 * @return 200 */ 201 public List<Course> search(String name, String factory, String model,String spec) { 202 String sql = "select * from ware where "; 203 if (name != "") { 204 sql += "name like '%" + name + "%'"; 205 } 206 if (factory != "") { 207 sql += "factory like '%" + factory + "%'"; 208 } 209 if (model != "") { 210 sql += "model like '%" + model + "%'"; 211 } 212 if (spec != "") { 213 sql += "spec like '%" + spec + "%'"; 214 } 215 List<Course> list = new ArrayList<>(); 216 Connection conn = DBUtil.getConn(); 217 Statement state = null; 218 ResultSet rs = null; 219 220 try { 221 state = conn.createStatement(); 222 rs = state.executeQuery(sql); 223 Course bean = null; 224 while (rs.next()) { 225 int id = rs.getInt("id"); 226 String name2 = rs.getString("name"); 227 String factory2 = rs.getString("factory"); 228 String model2 = rs.getString("model"); 229 String spec2 = rs.getString("spec"); 230 bean = new Course(id, name2, factory2, model2,spec2); 231 list.add(bean); 232 } 233 } catch (SQLException e) { 234 e.printStackTrace(); 235 } finally { 236 DBUtil.close(rs, state, conn); 237 } 238 239 return list; 240 } 241 242 /** 243 * 鍏ㄩ儴鏁版嵁 244 * @param name 245 * @param teacher 246 * @param classroom 247 * @return 248 */ 249 public List<Course> list() { 250 String sql = "select * from ware"; 251 List<Course> list = new ArrayList<>(); 252 Connection conn = DBUtil.getConn(); 253 Statement state = null; 254 ResultSet rs = null; 255 256 try { 257 state = conn.createStatement(); 258 rs = state.executeQuery(sql); 259 Course bean = null; 260 while (rs.next()) { 261 int id = rs.getInt("id"); 262 String name2 = rs.getString("name"); 263 String factory2 = rs.getString("factory"); 264 String model2 = rs.getString("model"); 265 String spec2 = rs.getString("spec"); 266 bean = new Course(id, name2, factory2, model2,spec2); 267 list.add(bean); 268 } 269 } catch (SQLException e) { 270 e.printStackTrace(); 271 } finally { 272 DBUtil.close(rs, state, conn); 273 } 274 275 return list; 276 } 277 278 }
<%@ 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="factory" name="factory" /> </div> <div class="a"> 型号<input type="text" id="model" name="model" /> </div> <div class="a"> 规格<input type="text" id="spec" name="spec"/> </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 factory = document.getElementById("factory"); var model = document.getElementById("model"); var spec = document.getElementById("spec"); //非空 if(name.value == '') { alert('名称为空'); name.focus(); return false; } if(factory.value == '') { alert('生产商家为空'); factory.focus(); return false; } if(model.value == '') { alert('型号为空'); model.focus(); return false; } if(spec.value == '') { alert('规格为空'); spec.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=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; } .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>${ware.name}</td> </tr> <tr> <td>生产商家</td> <td>${ware.factory}</td> </tr> <tr> <td>型号</td> <td>${ware.model}</td> </tr> <tr> <td>规格</td> <td>${ware.spec}</td> </tr> </table> <div class="a"> <a onclick="return check()" href="CourseServlet?method=del&id=${ware.id}">删 除</a> </div> </div> <script type="text/javascript"> function check() { if (confirm("真的要删除吗?")){ return true; }else{ return false; } } </script> </body> </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>Insert title here</title> 8 <style> 9 .a{ 10 margin-top: 20px; 11 } 12 .b{ 13 font-size: 20px; 14 width: 160px; 15 color: white; 16 background-color: greenyellow; 17 } 18 </style> 19 </head> 20 <body> 21 <% 22 Object message = request.getAttribute("message"); 23 if(message!=null && !"".equals(message)){ 24 25 %> 26 <script type="text/javascript"> 27 alert("<%=request.getAttribute("message")%>"); 28 </script> 29 <%} %> 30 <div align="center"> 31 <h1 style="color: red;">商品信息修改</h1> 32 <a href="index.jsp">返回主页</a> 33 <form action="CourseServlet?method=update" method="post" onsubmit="return check()"> 34 <div class="a"> 35 名称<input type="text" id="name" name="name" value="${ware.name}"/> 36 </div> 37 <div class="a"> 38 生产商家<input type="text" id="factory" name="factory" value="${ware.factory}"/> 39 </div> 40 <div class="a"> 41 型号<input type="text" id="model" name="model" value="${ware.model}"/> 42 </div> 43 <div class="a"> 44 规格<input type="text" id="spec" name="spec" value="${ware.spec}"/> 45 </div> 46 <input type="hidden" id="id" name="id" value="${ware.id}"/> 47 <div class="a"> 48 <button type="submit" class="b">修 改</button> 49 </div> 50 </form> 51 </div> 52 <script type="text/javascript"> 53 function check() { 54 var name = document.getElementById("name");; 55 var factory = document.getElementById("factory"); 56 var model = document.getElementById("model"); 57 var spec = document.getElementById("spec"); 58 59 //非空 60 if(name.value == '') { 61 alert('名称为空'); 62 name.focus(); 63 return false; 64 } 65 if(factory.value == '') { 66 alert('生产商家为空'); 67 factory.focus(); 68 return false; 69 } 70 if(model.value == '') { 71 alert('型号为空'); 72 model.focus(); 73 return false; 74 } 75 if(spec.value == '') { 76 alert('规格为空'); 77 spec.focus(); 78 return false; 79 } 80 81 82 } 83 </script> 84 </body> 85 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>首页</title> 8 <style> 9 .a{ 10 font-size: 26px; 11 margin-top: 20px; 12 } 13 </style> 14 </head> 15 <body> 16 <div align="center"> 17 <h1 style="color: red;">商品基本信息管理系统</h1> 18 <div class="a"> 19 <a href="add.jsp">商品信息录入</a> 20 </div> 21 <div class="a"> 22 <a href="CourseServlet?method=list">商品信息修改</a> 23 </div> 24 <div class="a"> 25 <a href="del.jsp">商品信息删除</a> 26 </div> 27 <div class="a"> 28 <a href="search.jsp">商品信息查询</a> 29 </div> 30 </div> 31 </body> 32 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="UTF-8"> 8 <title>Insert title here</title> 9 <style> 10 .a{ 11 margin-top: 20px; 12 } 13 .b{ 14 font-size: 20px; 15 width: 160px; 16 color: white; 17 background-color: greenyellow; 18 } 19 .tb, td { 20 border: 1px solid black; 21 font-size: 22px; 22 } 23 </style> 24 </head> 25 <body> 26 <% 27 Object message = request.getAttribute("message"); 28 if(message!=null && !"".equals(message)){ 29 30 %> 31 <script type="text/javascript"> 32 alert("<%=request.getAttribute("message")%>"); 33 </script> 34 <%} %> 35 <div align="center"> 36 <h1 style="color: red;">商品信息列表</h1> 37 <a href="index.jsp">返回主页</a> 38 <table class="tb"> 39 <tr> 40 <td>id</td> 41 <td>名称</td> 42 <td>生产商家</td> 43 <td>型号</td> 44 <td>规格</td> 45 <td align="center" colspan="2">操作</td> 46 </tr> 47 <c:forEach items="${wares}" var="item"> 48 <tr> 49 <td>${item.id}</td> 50 <td>${item.name}</td> 51 <td>${item.factory}</td> 52 <td>${item.model}</td> 53 <td>${item.spec}</td> 54 <td><a href="CourseServlet?method=getcoursebyid&id=${item.id}">修改</a></td> 55 </tr> 56 </c:forEach> 57 </table> 58 </div> 59 </body> 60 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html> 4 <html> 5 <head> 6 <meta charset="UTF-8"> 7 <title>Insert title here</title> 8 <style> 9 .a{ 10 margin-top: 20px; 11 } 12 .b{ 13 font-size: 20px; 14 width: 160px; 15 color: white; 16 background-color: greenyellow; 17 } 18 </style> 19 </head> 20 <body> 21 <div align="center"> 22 <h1 style="color: red;">商品信息查询</h1> 23 <a href="index.jsp">返回主页</a> 24 <form action="CourseServlet?method=search" method="post" onsubmit="return check()"> 25 <div class="a"> 26 名称<input type="text" id="name" name="name"/> 27 </div> 28 <div class="a"> 29 生产商家<input type="text" id="factory" name="factory" /> 30 </div> 31 <div class="a"> 32 型号<input type="text" id="model" name="model" /> 33 </div> 34 <div class="a"> 35 规格<input type="text" id="spec" name="spec" /> 36 </div> 37 <div class="a"> 38 <button type="submit" class="b">查 询</button> 39 </div> 40 </form> 41 </div> 42 <script type="text/javascript"> 43 function check() { 44 var name = document.getElementById("name");; 45 var factory = document.getElementById("factory"); 46 var model = document.getElementById("model"); 47 var spec = document.getElementById("spec"); 48 49 //非空 50 if(name.value == '' && factory.value == '' && model.value == '' && spec.value == '') { 51 alert('请填写一个条件'); 52 return false; 53 } 54 } 55 </script> 56 </body> 57 </html>
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 4 <!DOCTYPE html> 5 <html> 6 <head> 7 <meta charset="UTF-8"> 8 <title>Insert title here</title> 9 <style> 10 .a{ 11 margin-top: 20px; 12 } 13 .b{ 14 font-size: 20px; 15 width: 160px; 16 color: white; 17 background-color: greenyellow; 18 } 19 .tb, td { 20 border: 1px solid black; 21 font-size: 22px; 22 } 23 </style> 24 </head> 25 <body> 26 <div align="center"> 27 <h1 style="color: red;">商品信息列表</h1> 28 <a href="index.jsp">返回主页</a> 29 <table class="tb"> 30 <tr> 31 <td>id</td> 32 <td>名称</td> 33 <td>生产商家</td> 34 <td>型号</td> 35 <td>规格</td> 36 </tr> 37 <!-- forEach遍历出adminBeans --> 38 <c:forEach items="${wares}" var="item" varStatus="status"> 39 <tr> 40 <td>${item.id}</td> 41 <td><a>${item.name}</a></td> 42 <td>${item.factory}</td> 43 <td>${item.model}</td> 44 <td>${item.spec}</td> 45 </tr> 46 </c:forEach> 47 </table> 48 </div> 49 </body> 50 </html>
实验总结:500——servlet错误
404找不到连接途径
我觉得这次试验就是为了解决这两个问题!!!!!!!!!