• 2020/11/5


    一.在这里写一个遍历数据库数据的过程

    public List<student> bianli () {
    		String sql="select * from text3";
    		Connection conn = DBUtil.getConn();
    		Statement state = null;
    		
    		ResultSet rs = null;
    		List<student> list = new ArrayList<>();
    		try {
    			state = conn.createStatement();
    			rs = state.executeQuery(sql);
    			student bean = null;
    			while (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);
    				list.add(bean);
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		} finally {
    			DBUtil.close(state, conn);
    		}
    		return list;
    	}
    

     这是dao层

      private void login(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
        	req.setCharacterEncoding("utf-8");
        	String sid = req.getParameter("sid");
    		String sname = req.getParameter("sname");
    		HttpSession session = req.getSession();
    		    
    		Dao dao=new Dao();
    
    		List<student> holds = dao.bianli();
    		req.setAttribute("holds", holds);
    
    		if(dao.judge(sid))
    		{
    			req.setAttribute("message", "登录成功!");
    			req.getRequestDispatcher("lookall.jsp").forward(req,resp);	
    		}
    		else {
    			req.setAttribute("message", "没有该学生!");
    			req.getRequestDispatcher("denglu.jsp").forward(req,resp);
    		}
        }
    

     这里是

     利用这个进行遍历,这里是servelt层,

    <%@ 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到这个jsp中就可以遍历出;

    二.jsp是使用的模板,自己对这里面的数据也是不太清楚

    三.点击删除

  • 相关阅读:
    supervisor(一)基础篇
    linux添加开机自启动脚本示例详解
    suse 不能远程登录
    LintCode,hihoCoder,LeetCode有什么区别?
    windows 下安装nodejs 要怎么设置环境变量
    Java 集合:HashSet 与 ArrayList
    Java ArrayList、Vector和LinkedList等的差别与用法(转)
    一行代码实现java list去重
    25 highest paying companies: Which tech co outranks Google, Facebook and Microsoft?
    Chart: Who pays the most in Seattle for software engineers
  • 原文地址:https://www.cnblogs.com/qiangini/p/14159738.html
Copyright © 2020-2023  润新知