今日学习进度:
第一天 | 第二天 | 第三天 | 第四天 | 第五天 | |
所花时间(小时) | 5 | 6 | |||
代码量(行) | 500 | 600 | |||
博客量(篇) | 1 | 1 | |||
了解到的知识点 | web系统 |
web界面 |
学生管理系统的web界面设计:
index.jsp
<%@page import="entity.Student"%> <%@page import="java.util.List"%> <%@page import="dao.Dao"%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>学生管理系统</title> <style type="text/css"> .bg { background-image:url(images/bg_2.jpg); background-size:cover; } *{font-style: "微软雅黑"} #table{ border-collapse: collapse; margin: auto;text-align: center;} #table th{background-color: #fff7d5;border: 1px solid black;} #table td{background-color:#cffcd5;border: 1px solid black;padding: 15px;color: #000;} #table a{text-decoration: none;font-weight: bold;} #table a:hover {text-decoration: underline;} </style> </head> <body class="bg"> <h2 style="text-align: center;">学生管理系统</h2> <br> <div style="text-align: center;"> <a href="add.jsp" target="_self">添加学生</a> </div> <br> <% request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); List<Student> list=Dao.getAllStudents(); %> <%if(list.isEmpty()) {%> <br> <br> <br> <p style="text-align: center;font-size: xx-large;font-weight: 500;">当前数据库无相关信息</p> <%}else {%> <table id="table"> <tr> <th>姓名</th> <th>性别</th> <th>生日</th> <th>住址</th> <th>操作</th> </tr> <%for(Student str:list){ %> <tr> <td><%=str.getName() %></td> <td><%=str.getSex() %></td> <td><%=str.getBirthday() %></td> <td><%=str.getAddress() %></td> <td><a href="update.jsp?id=<%=str.getId() %>">修改</a> <a href="deletestudent.jsp?id=<%=str.getId() %>" onclick="return confirm('确认删除吗?')">删除</a></td> </tr> <%}} %> </table> </body> </html>
add.jsp
<%@ 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 type="text/css"> .bg { background-image:url(images/bg_1.jpg); background-size:cover; } </style> </head> <body class="bg"> <div> <form action="addstudent.jsp" method="post" id="form" onsubmit="return check()" > <table> <tr> <td>姓名</td> <td><input type="text" name="name" ></td> </tr> <tr> <td>性别</td> <td><input type="radio" name="sex" value="男">男 <input type="radio" name="sex" value="女">女</td> </tr> <tr> <td>生日</td> <td><input type="text" name="birthday" ></td> </tr> <tr> <td>住址</td> <td><input type="text" name="address" ></td> </tr> <tr> <td></td> <td><input type="submit" value="确认" ></td> </tr> </table> </form> </div> </body> <script type="text/javascript"> function check(){ obj=document.getElementById('form'); if(obj.name.value===""||obj.sex.value===""||obj.birthday.value===""||obj.address.value===""){ alert("请将信息填写完整"); return false; } } </script> </html>
addstudent.jsp
<%@page import="dao.Dao"%> <%@page import="entity.Student"%> <%@ 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> </head> <body> <% request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); Student student=new Student(); student.setAddress(request.getParameter("address")); student.setBirthday(request.getParameter("birthday")); student.setName(request.getParameter("name")); student.setSex(request.getParameter("sex")); Dao.addStudent(student); response.sendRedirect("index.jsp"); %> </body> </html>
deletestudent.jsp
<%@page import="dao.Dao"%> <%@ 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> </head> <body> <% request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); int id=Integer.parseInt(request.getParameter("id")); Dao.deleteStudent(id); response.sendRedirect("index.jsp"); %> </body> </html>
update.jsp
<%@page import="dao.Dao"%> <%@page import="entity.Student"%> <%@ 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 type="text/css"> .bg { background-image:url(images/bg_1.jpg); background-size:cover; } </style> </head> <body class="bg"> <% request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); int id=Integer.parseInt(request.getParameter("id")); Student student=Dao.getStudent(id); %> <form action="updatestudent.jsp" method="post" id="form" onsubmit="return check()" > <input type="hidden" name="id" value="<%=id%>"> <table> <tr> <td>姓名</td> <td><input type="text" name="name" ></td> </tr> <tr> <td>性别</td> <td><input type="radio" name="sex" value="男">男 <input type="radio" name="sex" value="女">女</td> </tr> <tr> <td>生日</td> <td><input type="text" name="birthday" ></td> </tr> <tr> <td>住址</td> <td><input type="text" name="address" ></td> </tr> <tr> <td></td> <td><input type="submit" value="确认" ></td> </tr> </table> </form> <script type="text/javascript"> window.onload=function(){ var obj=document.getElementById("form"); obj.name.value="<%=student.getName()%>"; obj.sex.value="<%=student.getSex()%>"; obj.birthday.value="<%=student.getBirthday()%>"; obj.address.value="<%=student.getAddress()%>"; } </script> <script type="text/javascript"> function check(){ obj=document.getElementById('form'); if(obj.name.value===""||obj.sex.value===""||obj.birthday.value===""||obj.address.value===""){ alert("请将信息填写完整"); return false; } } </script> </body> </html>
updatestudent.jsp
<%@page import="dao.Dao"%> <%@page import="entity.Student"%> <%@ 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> </head> <body> <% request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); Student student=new Student(); student.setAddress(request.getParameter("address")); student.setBirthday(request.getParameter("birthday")); student.setId(Integer.parseInt(request.getParameter("id"))); student.setName(request.getParameter("name")); student.setSex(request.getParameter("sex")); Dao.updateStudent(student); response.sendRedirect("index.jsp"); %> </body> </html>