一.今天写了个
使用遍历后点击进行的删除的
<%@ 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; 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="denglu.jsp">返回主页面</a> <table class="tb"> <tr> <td>学号</td> <td>姓名</td> <td>性别</td> <td>班级</td> <td>专业</td> </tr> <!-- forEach遍历出adminBeans --> <c:forEach items="${holds}" var="item" varStatus="status"> <tr> <td>${item.sid}</td> <td><a>${item.sname}</a></td> <td>${item.ssex}</td> <td>${item.sclass}</td> <td>${item.szy}</td> <td><a href="Servlet?method=look&sid=${item.sid}">删除</a></td> </tr> </c:forEach> </table> </div> </body> </html>
这个页面删除可点击
之后到servelt中确认删除
private void look(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); String sid = req.getParameter("sid"); Dao dao=new Dao(); System.out.println(sid); List<student> holds2= dao.scha("sid",sid); req.setAttribute("holds2", holds2); req.getRequestDispatcher("deletelook.jsp").forward(req,resp); }
public student searchID(String x){//查询
String sql="select * from text3 where sid='"+x+"'";
Connection conn=DBUtil.getConn();
Statement st=null;
List<student> list=new ArrayList<>();
ResultSet rs=null;
student bean=null;
try {
st=conn.createStatement();
rs=st.executeQuery(sql);
rs.next();
String sid = rs.getString("sid");
String sname = rs.getString("sname");
String ssex = rs.getString("ssex");
String sclass=rs.getString("sclass");
String szy = rs.getString("szy");
bean=new student(sid,sname,ssex,sclass,szy);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
DBUtil.close(rs, st, conn);
}
return bean;
}
这是dao 中的一个查询
<%@ 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; 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="lookall.jsp">返回主页面</a> <table class="tb"> <tr> <td>学号</td> <td>姓名</td> <td>性别</td> <td>班级</td> <td>专业</td> </tr> <!-- forEach遍历出adminBeans --> <c:forEach items="${holds2}" var="item" varStatus="status"> <tr> <td>${item.sid}</td> <td><a>${item.sname}</a></td> <td>${item.ssex}</td> <td>${item.sclass}</td> <td>${item.szy}</td> <td><a href="Servlet?method=delete&sid=${item.sid}">确认删除</a></td> </tr> </c:forEach> </table> </div> </body> </html>
确认删除
进入servelt成功删除
private void delete(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{ req.setCharacterEncoding("utf-8"); String sid = req.getParameter("sid"); Dao dao =new Dao(); boolean f=dao.san(sid); if(f) { req.setAttribute("message", "删除成功!"); req.getRequestDispatcher("denglu.jsp").forward(req,resp); } else { req.setAttribute("message", "添加失败!"); req.getRequestDispatcher("denglu.jsp").forward(req,resp); } }
二.这个流程思路还是挺清楚的
三.总结