20170622的代码

来源:互联网 发布:脑卒中危险因素知多少 编辑:程序博客网 时间:2024/06/03 23:43

-----------------------------------------------------show.jsp-----------------------------------------------------


<%@page import="java.util.ArrayList"%>
<%@page import="com.ntqn.stduent.Student"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://www.ntqingniao.com/core/c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<style>
    #t1{
        border: 1px black solid;
        border-collapse:collapse;
    }
    #t1 tr{
        border: 1px black solid;
        border-collapse:collapse;
    }
    #t1 tr:NTH-CHILD(even){
        background-color: rgba(122,122,122,0.2);
    }
    #t1 tr:NTH-CHILD(odd){
        background-color: rgba(200,23,23,0.2);
    }
    #t1 tr>td{
        height:30px;
        border: 1px black solid;
        border-collapse:collapse;
        line-height: 30px;
        font-size: 18px;
        text-align: center;
    }
</style>
</head>
<script src="../assent/js/jquery-3.2.1.min.js"></script>
<body>

    <form action="/studentManager/StudentServlet.do" method="get">
        <p><span>请输入学生姓名:</span><input type="text" id="input1" name="name"/>&nbsp;<input type="submit" value="搜索"/></p>
    </form>
    <table id="t1">
        <thead>
            <tr style="background-color: white;">
                <th>姓名</th>
                <th>学号</th>
                <th>性别</th>
                <th>班级</th>
                <th>爱好</th>
                <th>邮箱</th>
                <th>个人介绍</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${stus }" var="student">
                <tr>
                    <td>${student.name }</td>
                    <td>${student.code }</td>
                    <td>${student.sex ==1 ? '男':'女' }</td>
                    <td>${student.clazz }</td>
                    <td>${student.habit }</td>
                    <td>${student.email }</td>
                    <td>${student.introduce }</td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
   
</body>

</html>

-----------------------------------------------------stduentService.java---------------------------------------

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        List<Student> stus = new ArrayList<Student>();
        String name = (String)request.getParameter("name");
        
        try {
            stus = new StudentImplement().findByName(name);
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        request.setAttribute("stus", stus);
        request.getRequestDispatcher("/view/show.jsp").forward(request, response);

    }