petupdate.jsp
<%@ page language="java" import="cn.dao.UserBean" pageEncoding="UTF-8" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="<%=basePath%>"> <title>宠物修改</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="css/css.css" rel="stylesheet" type="text/css"> <style type="text/css"> #content { position: relative; top: 3px; width: 80%; height: 380px; margin: auto; overflow: hidden; z-index: 2; } .tab1 { position: relative; top: 60px; font-size: 24px; } #in1, #in2, #in3, #in4 ,#in6{ width: 250px; height: 30px; font-size: 24px; } #in5 { width: 80px; height: 28px; margin-top: 10px; } </style> <script type="text/javascript"> function checkId() { if (document.getElementById("in1").value == "" && document.getElementById("in3").value == "" && document.getElementById("in2").value == "" && document.getElementById("in6").value == "") { alert("请输入宠物名相关信息!"); return false; } else if (document.getElementById("in1").value == "") { alert("请输入宠物名!"); return false; } else if (document.getElementById("in3").value == "") { alert("请输入主人!"); return false; } else if (document.getElementById("in6").value == "") { alert("请输入电话!"); return false; }else { return true; } } </script> </head> <body> <jsp:include page="top.jsp"></jsp:include> <!-- include top --> <% UserBean user = (UserBean) request.getAttribute("user"); %> <center> <div id="content"> <br/> <form action="servlet/petupdate" method="post" onsubmit="return checkId()"> <table border="0" cellpadding="0" cellspacing="2" class="tab1"> <tr align="center"> <td>宠物名 </td> <td><input type="text" name="petname" id="in1" value=<%=user.getPetname()%>>* </td> </tr> <tr align="center"> <td>主人 </td> <td><input type="text" name="petmaster" id="in3" value=<%=user.getPetmaster()%>>* </td> </tr> <tr align="center"> <td>城市 </td> <td><input type="text" name="petcity" id="in2" value=<% if(user.getPetcity()==null){out.print(" ");}else{out.print(user.getPetcity());} %>> </td> </tr> <tr align="center"> <td>地址 </td> <td><input type="text" name="petadress" id="in4" value=<% if(user.getPetadress()==null){out.print(" ");}else{out.print(user.getPetadress());} %>> </td> </tr> <tr align="center"> <td>电话 </td> <td><input type="text" name="petphone" id="in6" value=<% if(user.getPetphone()==null){out.print(" ");}else{out.print(user.getPetphone());} %>>* </td> </tr> <tr align="center"> <td colspan="2"> <input type="hidden" name="id" value=<%=user.getId() %>> <input type="submit" value="提交" id="in5"/> <input type="reset" value="重置" id="in5"/> </td> </tr> </table> </form> </div> </center> <!-- include footer --> <jsp:include page="footer.jsp"></jsp:include> </body> </html>
petsearch.jsp
<%@ page language="java" pageEncoding="UTF-8" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="<%=basePath%>"> <title>宠物查询</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="css/css.css" rel="stylesheet" type="text/css"> <style type="text/css"> #content { position: relative; top: 3px; width: 80%; height: 380px; margin: auto; overflow: hidden; z-index: 2; } .tab1 { position: relative; top: 120px; font-size: 24px; } #in1 { width: 250px; height: 30px; font-size: 24px; } #in3 { width: 250px; height: 30px; font-size: 24px; } #in2 { width: 80px; height: 28px; } </style> <script type="text/javascript"> function checkId() { if (document.getElementById("in1").value == "" && document.getElementById("in3").value == "") { alert("请输入宠物名或所有者名!"); return false; } else if (document.getElementById("in1").value != "" && document.getElementById("in3").value != "") { alert("模糊查询只能输入一个!"); return false; } else { return true; ; } } </script> </head> <body> <jsp:include page="top.jsp"></jsp:include> <!-- include top --> <center> <div id="content"> <form action="servlet/petquery" method="post" onsubmit="return checkId()"> <table border="0" cellpadding="0" cellspacing="2" class="tab1"> <tr align="center"> <td>宠物名:</td> <td><input type="text" name="petname" id="in1"/></td> </tr> <tr align="center"> <td>主 人:</td> <td><input type="text" name="petmaster" id="in3"/></td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" value="查询" id="in2"/> <input type="reset" value="重置" id="in2"/> <a href="petadd.jsp"><i><font color="gray" size="3" id="in2">添加</font></i></a> </td> </tr> </table> </form> </div> </center> <!-- include footer --> <jsp:include page="footer.jsp"></jsp:include> </body> </html>
docadd.jsp
<%@ page language="java" pageEncoding="UTF-8" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="<%=basePath%>"> <title>医生新增</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="css/css.css" rel="stylesheet" type="text/css"> <style type="text/css"> #content { position: relative; top: 3px; width: 80%; height: 380px; margin: auto; overflow: hidden; z-index: 2; } .tab1 { position: relative; top: 60px; font-size: 24px; } #in1, #in2, #in3, #in4 { width: 250px; height: 30px; font-size: 24px; } #in5 { width: 80px; height: 28px; margin-top: 10px; } </style> <script type="text/javascript"> function checkId() { if (document.getElementById("in1").value == "" && document.getElementById("in3").value == "" && document.getElementById("in2").value == "") { alert("请输入兽医姓名和专业!"); return false; } else if (document.getElementById("in1").value == "") { alert("请输入姓名"); return false; } else if (document.getElementById("in3").value == "") { alert("请输入专业!"); return false; } else { return true; } } </script> </head> <body> <jsp:include page="top.jsp"></jsp:include> <!-- include top --> <center> <div id="content"> <br/> <form action="servlet/docadd" method="post" onsubmit="return checkId()"> <table border="0" cellpadding="0" cellspacing="2" class="tab1"> <tr align="center"> <td>姓名 </td> <td><input type="text" name="name" id="in1"/>* </td> </tr> <tr align="center"> <td>专业 </td> <td><input type="text" name="major" id="in3"/>* </td> </tr> <tr align="center"> <td>电话 </td> <td><input type="text" name="phone" id="in2"/> </td> </tr> <tr align="center"> <td>地址 </td> <td><input type="text" name="address" id="in4"/> </td> </tr> <tr align="center"> <td colspan="2"> <input type="submit" value="提交" id="in5"/> <input type="reset" value="重置" id="in5"/> </td> </tr> </table> </form> </div> </center> <!-- include footer --> <jsp:include page="footer.jsp"></jsp:include> </body> </html>
docupdate.jsp
<%@ page language="java" import="cn.dao.UserBean" pageEncoding="UTF-8" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="<%=basePath%>"> <title>医生修改</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="css/css.css" rel="stylesheet" type="text/css"> <style type="text/css"> #content { position: relative; top: 3px; width: 80%; height: 380px; margin: auto; overflow: hidden; z-index: 2; } .tab1 { position: relative; top: 60px; font-size: 24px; } #in1, #in2, #in3, #in4 { width: 250px; height: 30px; font-size: 24px; } #in5 { width: 80px; height: 28px; margin-top: 10px; } </style> <script type="text/javascript"> function checkId() { if (document.getElementById("in1").value == "" && document.getElementById("in3").value == "" && document.getElementById("in2").value == "") { alert("请输入兽医姓名和专业!"); return false; } else if (document.getElementById("in1").value == "") { alert("请输入姓名"); return false; } else if (document.getElementById("in3").value == "") { alert("请输入专业!"); return false; } else { return true; } } </script> </head> <body> <jsp:include page="top.jsp"></jsp:include> <!-- include top --> <% UserBean user = (UserBean) request.getAttribute("user"); %> <center> <div id="content"> <br/> <form action="servlet/docupdate" method="post" onsubmit="return checkId()"> <table border="0" cellpadding="0" cellspacing="2" class="tab1"> <tr align="center"> <td>姓名 </td> <td><input type="text" name="name" id="in1" value=<%=user.getDocname()%>>* </td> </tr> <tr align="center"> <td>专业 </td> <td><input type="text" name="major" id="in3" value=<%=user.getDocmajor()%>>* </td> </tr> <tr align="center"> <td>电话 </td> <td><input type="text" name="phone" id="in2" value=<% if(user.getDocphone()==null){out.print(" ");}else{out.print(user.getDocphone());} %>> </td> </tr> <tr align="center"> <td>地址 </td> <td><input type="text" name="address" id="in4" value=<% if(user.getDocadress()==null){out.print(" ");}else{out.print(user.getDocadress());} %>> </td> </tr> <tr align="center"> <td colspan="2"> <input type="hidden" name="id" value=<%=user.getId() %>> <input type="submit" value="提交" id="in5"/> <input type="reset" value="重置" id="in5"/> </td> </tr> </table> </form> </div> </center> <!-- include footer --> <jsp:include page="footer.jsp"></jsp:include> </body> </html>
docsearch.jsp
<%@ page language="java" pageEncoding="UTF-8" %> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <base href="<%=basePath%>"> <title>医生查询</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="css/css.css" rel="stylesheet" type="text/css"> <style type="text/css"> #content { position: relative; top: 3px; width: 80%; height: 380px; margin: auto; overflow: hidden; z-index: 2; } .tab1 { position: relative; top: 120px; font-size: 24px; } #in1 { width: 250px; height: 30px; font-size: 24px; } #in3 { width: 250px; height: 30px; font-size: 24px; } #in2 { width: 80px; height: 28px; } </style> <script type="text/javascript"> function checkId() { if (document.getElementById("in1").value == "" && document.getElementById("in3").value == "") { alert("请输入兽医名或专业!"); return false; } else if (document.getElementById("in1").value != "" && document.getElementById("in3").value != "") { alert("少年,两个都输了,您这是要闹哪样啊!"); return false; } else { return true; ; } } </script> </head> <body> <script type="text/javascript"> <% if(session.getAttribute("update").equals("del")){ %> alert("删除成功!"); <% }else if(session.getAttribute("update").equals("delno")){ %> alert("删除失败 !"); <% }else if(session.getAttribute("update").equals("suc")){ %> alert("添加成功 !"); <% }else if(session.getAttribute("update").equals("err")){ %> alert("添加失败 !"); <% }else if(session.getAttribute("update").equals("ok")){ %> alert("编辑成功 !"); <% } session.setAttribute("update", "null"); %> <% if(session.getAttribute("error").equals("cuo")){ %> alert("出错了!"); <% } session.setAttribute("error", "test"); %> </script> <jsp:include page="top.jsp"></jsp:include> <!-- include top --> <center> <div id="content"> <form action="servlet/docquery" method="post" onsubmit="return checkId()"> <table border="0" cellpadding="0" cellspacing="2" class="tab1"> <tr align="center"> <td>兽医姓名:</td> <td><input type="text" name="docname" id="in1"/></td> </tr> <tr align="center"> <td>专 业:</td> <td><input type="text" name="docmajor" id="in3"/></td> </tr> <tr> <td align="center" colspan="2"> <input type="submit" value="查询" id="in2"/> <input type="reset" value="重置" id="in2"/> <a href="docadd.jsp"><i><font color="gray" size="3" id="in2">添加</font></i></a> </td> </tr> </table> </form> </div> </center> <!-- include footer --> <jsp:include page="footer.jsp"></jsp:include> </body> </html>
2.后端
DBConn
package cn.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class DocManage { // 空构造方法 public DocManage() { } // 添加兽医 public int addPetdoc(UserBean user) { String sql = "INSERT INTO petdoctor(docname,docmajor,docphone,docadress) VALUES (?,?,?,?)"; int i = 0; try { DBConn.prepareConnection(); DBConn.con.setAutoCommit(false); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setString(1, user.getDocname()); DBConn.ps.setString(2, user.getDocmajor()); DBConn.ps.setString(3, user.getDocphone()); DBConn.ps.setString(4, user.getDocadress()); i = DBConn.ps.executeUpdate(); DBConn.con.commit(); } catch (SQLException e) { DBConn.rollback(); e.printStackTrace(); } finally { DBConn.close(); } return i; } // 删除兽医 public int delPetdocForId(UserBean user) { String sql = "DELETE FROM petdoctor WHERE id=?"; int i = 0; try { DBConn.prepareConnection(); DBConn.con.setAutoCommit(false); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setInt(1, user.getId()); i = DBConn.ps.executeUpdate(); DBConn.con.commit(); } catch (SQLException e) { DBConn.rollback(); e.printStackTrace(); } finally { DBConn.close(); } return i; } // 通过id删除兽医 public int delPetdocForId(int id) { String sql = "DELETE FROM petdoctor WHERE id=?"; int i = 0; try { DBConn.prepareConnection(); DBConn.con.setAutoCommit(false); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setInt(1, id); i = DBConn.ps.executeUpdate(); DBConn.con.commit(); } catch (SQLException e) { DBConn.rollback(); e.printStackTrace(); } finally { DBConn.close(); } return i; } // 更新兽医 public int updatePetdocForId(UserBean user) { String sql = "UPDATE petdoctor SET docname=?, docmajor=?,docphone=?,docadress=? WHERE id=?"; int i = 0; try { DBConn.prepareConnection(); DBConn.con.setAutoCommit(false); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setString(1, user.getDocname()); DBConn.ps.setString(2, user.getDocmajor()); DBConn.ps.setString(3, user.getDocphone()); DBConn.ps.setString(4, user.getDocadress()); DBConn.ps.setInt(5, user.getId()); i = DBConn.ps.executeUpdate(); DBConn.con.commit(); } catch (SQLException e) { DBConn.rollback(); e.printStackTrace(); } finally { DBConn.close(); } return i; } // 获取所有兽医 public List<UserBean> getAllPetdoc() { String sql = "SELECT * FROM petdoctor"; List<UserBean> users = new ArrayList<UserBean>(); try { DBConn.prepareConnection(); DBConn.ps = DBConn.con.prepareStatement(sql); ResultSet rs = DBConn.ps.executeQuery(); while (rs.next()) { UserBean user = new UserBean(); user.setId(rs.getInt("id")); user.setDocname(rs.getString("docname")); user.setDocmajor(rs.getString("docmajor")); user.setDocphone(rs.getString("docphone")); user.setDocadress(rs.getString("docadress")); users.add(user); } } catch (SQLException e) { e.printStackTrace(); } finally { DBConn.close(); } return users; } // 通过兽医名获取兽医 public List<UserBean> getPetdocForName(UserBean use) { String sql = "SELECT * FROM petdoctor WHERE docname=?"; List<UserBean> users = new ArrayList<UserBean>(); try { DBConn.prepareConnection(); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setString(1, use.getDocname()); ResultSet rs = DBConn.ps.executeQuery(); while (rs.next()) { UserBean user = new UserBean(); user.setId(rs.getInt("id")); user.setDocname(rs.getString("docname")); user.setDocmajor(rs.getString("docmajor")); user.setDocphone(rs.getString("docphone")); user.setDocadress(rs.getString("docadress")); users.add(user); } } catch (SQLException e) { e.printStackTrace(); } finally { DBConn.close(); } return users; } // 通过兽医专业获取兽医 public List<UserBean> getPetdocForMajor(UserBean use) { String sql = "SELECT * FROM petdoctor WHERE docmajor=?"; List<UserBean> users = new ArrayList<UserBean>(); try { DBConn.prepareConnection(); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setString(1, use.getDocmajor()); ResultSet rs = DBConn.ps.executeQuery(); while (rs.next()) { UserBean user = new UserBean(); user.setId(rs.getInt("id")); user.setDocname(rs.getString("docname")); user.setDocmajor(rs.getString("docmajor")); user.setDocphone(rs.getString("docphone")); user.setDocadress(rs.getString("docadress")); users.add(user); } } catch (SQLException e) { e.printStackTrace(); } finally { DBConn.close(); } return users; } // 通过兽医id获取兽医 public UserBean getPetdocForId(int id) { String sql = "SELECT * FROM petdoctor WHERE id=?"; UserBean user = new UserBean(); try { DBConn.prepareConnection(); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setInt(1, id); ResultSet rs = DBConn.ps.executeQuery(); while (rs.next()) { user.setId(rs.getInt("id")); user.setDocname(rs.getString("docname")); user.setDocmajor(rs.getString("docmajor")); user.setDocphone(rs.getString("docphone")); user.setDocadress(rs.getString("docadress")); } } catch (SQLException e) { e.printStackTrace(); } finally { DBConn.close(); } return user; } // 通过兽医名获取兽医 public Integer getIdForName(UserBean user) { String sql = "SELECT * FROM petdoctor WHERE docname=?"; Integer i = 0; try { DBConn.prepareConnection(); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setString(1, user.getLoginname()); ResultSet rs = DBConn.ps.executeQuery(); while (rs.next()) { i = rs.getInt("id"); } } catch (SQLException e) { e.printStackTrace(); } finally { DBConn.close(); } return i; } }
UserManage
package cn.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class UserManage { // 空构造方法 public UserManage() { } // 添加用户 public int addUser(UserBean user) { String sql = "INSERT INTO userinfo(username,password,userphone) VALUES (?,?,?)"; int i = 0; try { DBConn.prepareConnection(); DBConn.con.setAutoCommit(false); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setString(1, user.getLoginname()); DBConn.ps.setString(2, user.getLoginpassword()); DBConn.ps.setString(3, user.getLoginphone()); i = DBConn.ps.executeUpdate(); DBConn.con.commit(); } catch (SQLException e) { DBConn.rollback(); System.out.println("插入数据失败!"); i = 2; } finally { DBConn.close(); } return i; } // 删除用户 public int delUserForId(UserBean user) { String sql = "DELETE FROM userinfo WHERE id=?"; int i = 0; try { DBConn.prepareConnection(); DBConn.con.setAutoCommit(false); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setInt(1, user.getId()); i = DBConn.ps.executeUpdate(); DBConn.con.commit(); } catch (SQLException e) { DBConn.rollback(); e.printStackTrace(); } finally { DBConn.close(); } return i; } // 更新用户 public int updateUseForId(UserBean user) { String sql = "UPDATE userinfo SET username=?, password=?,userphone=? WHERE id=?"; int i = 0; try { DBConn.prepareConnection(); DBConn.con.setAutoCommit(false); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setString(1, user.getLoginname()); DBConn.ps.setString(2, user.getLoginpassword()); DBConn.ps.setString(3, user.getLoginphone()); i = DBConn.ps.executeUpdate(); DBConn.con.commit(); } catch (SQLException e) { DBConn.rollback(); e.printStackTrace(); } finally { DBConn.close(); } return i; } // 获取所有用户 public List<UserBean> getAllUsers() { String sql = "SELECT * FROM userinfo"; List<UserBean> users = new ArrayList<UserBean>(); try { DBConn.prepareConnection(); DBConn.ps = DBConn.con.prepareStatement(sql); ResultSet rs = DBConn.ps.executeQuery(); while (rs.next()) { UserBean user = new UserBean(); user.setId(rs.getInt("id")); user.setLoginname(rs.getString("username")); user.setLoginpassword(rs.getString("password")); user.setLoginphone(rs.getString("userphone")); users.add(user); } } catch (SQLException e) { e.printStackTrace(); } finally { DBConn.close(); } return users; } // 通过登录名获取id public Integer getIdForName(UserBean user) { String sql = "SELECT * FROM userinfo WHERE username=?"; Integer i = 0; try { DBConn.prepareConnection(); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setString(1, user.getLoginname()); ResultSet rs = DBConn.ps.executeQuery(); while (rs.next()) { i = rs.getInt("id"); } } catch (SQLException e) { e.printStackTrace(); } finally { DBConn.close(); } return i; } // 检查用户登录 public boolean userLogin(UserBean user) { String sql = "SELECT * FROM userinfo WHERE username=?"; boolean flag = false; try { DBConn.prepareConnection(); DBConn.ps = DBConn.con.prepareStatement(sql); DBConn.ps.setString(1, user.getLoginname()); ResultSet rs = DBConn.ps.executeQuery(); while (rs.next()) { if (rs.getString("password").equals(user.getLoginpassword())) flag = true; } } catch (SQLException e) { e.printStackTrace(); } finally { DBConn.close(); } return flag; } }
petAdd
package petservlets; import cn.dao.DocManage; import cn.dao.PetManage; import cn.dao.UserBean; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; import java.io.PrintWriter; /** * @author shuijianshiqing * @date 2021/1/24 11:16 */ public class petAdd extends HttpServlet { public petAdd() { super(); } public void destroy() { super.destroy(); } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); request.setCharacterEncoding("utf-8"); UserBean user = new UserBean(); user.setPetname(request.getParameter("petname")); user.setPetmaster(request.getParameter("petmaster")); user.setPetcity(request.getParameter("petcity")); user.setPetadress(request.getParameter("petadress")); user.setPetphone(request.getParameter("petphone")); PetManage manage = new PetManage(); HttpSession session = request.getSession(); if (manage.addPet(user) == 1) { session.setAttribute("update", "suc"); request.getRequestDispatcher("../petsearch.jsp").forward(request, response); } else { session.setAttribute("update", "err"); request.getRequestDispatcher("../petsearch.jsp").forward(request, response); } out.flush(); out.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } public void init() throws ServletException { // Put your code here } }
petDel
package petservlets; import cn.dao.PetManage; import cn.dao.UserBean; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; import java.io.PrintWriter; /** * @author shuijianshiqing * @date 2021/1/24 11:31 */ public class petDel extends HttpServlet { public petDel() { super(); } public void destroy() { super.destroy(); // Put your code here } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); request.setCharacterEncoding("utf-8"); String mode = request.getParameter("m"); Integer id = Integer.parseInt(request.getParameter("id")); HttpSession session = request.getSession(); PetManage manage = new PetManage(); if (mode.equals("del")) { if (manage.delPetById(id) == 1) { session.setAttribute("update", "del"); } else { session.setAttribute("update", "delno"); } request.getRequestDispatcher("../petsearch.jsp").forward(request, response); } else if (mode.equals("update")) { UserBean user = new UserBean(); user = manage.getPetForId(id); if (!user.getPetname().equals("")) { request.setAttribute("user", user); request.getRequestDispatcher("../petupdate.jsp").forward(request, response); } else { session.setAttribute("error", "cuo"); request.getRequestDispatcher("../petsearch.jsp").forward(request, response); } } out.flush(); out.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.flush(); out.close(); } public void init() throws ServletException { // Put your code here } }
petQuery
package petservlets; import cn.dao.PetManage; import cn.dao.UserBean; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; /** * @author shuijianshiqing * @date 2021/1/24 11:31 */ public class petQuery extends HttpServlet { public petQuery() { super(); } public void destroy() { super.destroy(); // Put your code here } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); request.setCharacterEncoding("utf-8"); String name = request.getParameter("petname"); String master = request.getParameter("petmaster"); UserBean user = new UserBean(); PetManage manage = new PetManage(); List<UserBean> list = new ArrayList<UserBean>(); request.setAttribute("nopet", "flase"); if (master.equals("")) { list = manage.getPetdocForName(name); request.setAttribute("list", list); // 无数据时返回提示 if (list.size() == 0) { request.setAttribute("nopet", "nopet"); } request.getRequestDispatcher("../petresult.jsp").forward(request, response); } else { user.setPetmaster(master); list = manage.getPetByMaster(user); request.setAttribute("list", list); if (list.size() == 0) { request.setAttribute("nopet", "nopet"); } request.getRequestDispatcher("../petresult.jsp").forward(request, response); } out.flush(); out.close(); } public void init() throws ServletException { // Put your code here } }
petUpdate
package petservlets; import cn.dao.PetManage; import cn.dao.UserBean; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; import java.io.PrintWriter; /** * @author shuijianshiqing * @date 2021/1/24 11:31 */ public class petUpdate extends HttpServlet { public petUpdate() { super(); } public void destroy() { super.destroy(); // Put your code here } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.flush(); out.close(); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); request.setCharacterEncoding("utf-8"); Integer id = Integer.parseInt(request.getParameter("id")); String petname = request.getParameter("petname"); String petmaster = request.getParameter("petmaster"); String petcity = request.getParameter("petcity"); String petadress = request.getParameter("petadress"); String petphone = request.getParameter("petphone"); UserBean user = new UserBean(); PetManage manage = new PetManage(); HttpSession session = request.getSession(); user.setId(id); user.setPetname(petname); user.setPetmaster(petmaster); user.setPetcity(petcity); user.setPetadress(petadress); user.setPetphone(petphone); if (manage.updatePetForId(user) == 1) { session.setAttribute("update", "ok"); } else { session.setAttribute("error", "ng"); } request.getRequestDispatcher("../petsearch.jsp").forward(request, response); out.flush(); out.close(); } public void init() throws ServletException { // Put your code here } }
四、其他
1.其他系统实现
Java+JSP实现学生图书管理系统
Java+JSP实现学生信息管理系统
Java+JSP实现用户信息管理系统
Java+Servlet+JSP实现航空订票系统
Java+Servlet+JSP实现房屋租赁管理系统
Java+Servlet+JSP实现学生选课管理系统
Java+Servlet+JSP实现学生成绩管理系统
Java+Servlet+JSP实现宠物诊所管理系统
Java+SSM+Easyui实现网上考试系统
Java+SSM+Bootstrap实现Web学生信息管理系统
Java+Springboot+H-ui实现营销管理系统
Java+Springboot+Mybatis+Bootstrap实现网上商城系统
Java+Springboot+Mybatis+Bootstrap实现景区旅游管理系统