2020年12月12日Java学习日记
主页面:index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>首页</title> <style> .a{ font-size: 26px; margin-top: 20px; } </style> </head> <body> <div align="center"> <h1 style="color: red;">青年志愿者服务网</h1> <div class="a"> <a href="add.jsp">志愿者登记信息</a> </div> <div class="a"> <a href="CourseServlet?method=list">修改志愿者信息</a> </div> <div class="a"> <a href="del.jsp">删除志愿者信息</a> </div> <div class="a"> <a href="search.jsp">查询志愿者信息</a> </div> <div class="a"> <a href="CourseServlet?method=show">志愿者信息浏览</a> </div> </div> </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>菜单</title> </head> <body> <% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <div align="center"> <h1 style="color: red;">志愿者信息登记</h1> <a href="index.jsp">返回主页</a> <form action="CourseServlet?method=add" method="post" onsubmit="return check()"> <div class="a"> 姓名<input type="text" id="name" name="name"/> </div> <div class="a"> <td>性别</td> <td> <label><input type="radio" name="sex" value="男">男</label> <label><input type="radio" name="sex" value="女">女</label> </td> </div> <div class="a"> 民族<input type="text" id="minzu" name="minzu" /> </div> <div class="a"> 注册时间<input type="text" id="time" name="time" /> </div> <div class="a"> 年龄<input type="text" id="age" name="age" /> </div> <div class="a"> <td width="150px">政治面貌</td> <td> <select name="mianmao"> <option value ="政治面貌">政治面貌</option> <option value ="群众">群众</option> <option value="共青团员">共青团员</option> <option value="中共党员">中共党员</option> </select> </td> </div> <div class="a"> <td>服务类别(最多四项):</td> <input type="checkbox" name="fuwu" value="扶危济困"/>扶危济困<input type="checkbox" name="fuwu" value="敬老助残"/>敬老助残<input type="checkbox" name="fuwu" value="社会服务"/>社会服务<input type="checkbox" name="fuwu" value="秩序维护"/>秩序维护<input type="checkbox" name="fuwu" value="文体服务"/>文体服务 <input type="checkbox" name="fuwu" value="环境保护"/>环境保护<input type="checkbox" name="fuwu" value="治安防范"/>治安防范<input type="checkbox" name="fuwu" value="医疗救治"/>医疗救治<input type="checkbox" name="fuwu" value="法律援助"/>法律援助<input type="checkbox" name="fuwu" value="大型活动"/>大型活动 <input type="checkbox" name="fuwu" value="心理疏导"/>心理疏导<input type="checkbox" name="fuwu" value="精神抚慰"/>精神抚慰<input type="checkbox" name="fuwu" value="支教支医"/>支教支医<input type="checkbox" name="fuwu" value="科学普及"/>科学普及<input type="checkbox" name="fuwu" value="应急救援"/>应急救援 <input type="checkbox" name="fuwu" value="便民服务"/>便民服务<input type="checkbox" name="fuwu" value="民事调解"/>民事调解<input type="checkbox" name="fuwu" value="文明引导"/>文明引导<input type="checkbox" name="fuwu" value="安全生产"/>安全生产<input type="checkbox" name="fuwu" value="禁毒宣传"/>禁毒宣传 </div> <div class="a"> <button type="submit" class="b">保 存 </button> <b href="CourseServlet?method=searchlist"> </div> </form> </div> <script type="text/javascript"> function check() { var name = document.getElementById("name"); var sex = document.getElementById("sex"); var minzu = document.getElementById("minzu"); var time = document.getElementById("time"); var age = document.getElementById("age"); var mianmao = document.getElementById("mianmao"); var fuwu = document.getElementById("fuwu"); //非空 if(name.value == '') { alert('志愿者姓名为空'); name.focus(); return false; } if(sex.value == '') { alert('性别为空'); sex.focus(); return false; } if(minzu.value == '') { alert('民族为空'); minzu.focus(); return false; } if(time.value == '') { alert('注册时间为空'); time.focus(); return false; } if(age.value == '') { alert('年龄为空'); age.focus(); return false; } if(mianmao.value == '') { alert('政治面貌为空'); mianmao.focus(); return false; } if(fuwu.value == '') { alert('服务类型为空'); fuwu.focus(); return false; } } </script> </body> </html>
浏览页面:list.jsp
<%@ 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> </head> <body> <% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <div align="center"> <h1 style="color: red;">志愿者信息列表</h1> <a href="index.jsp">返回主页</a> <table class="tb"> <tr> <td>id</td> <td>姓名</td> <td>性别</td> <td>民族</td> <td>注册时间</td> <td>年龄</td> <td>政治面貌</td> <td>服务类型</td> <td align="center" colspan="2">操作</td> </tr> <c:forEach items="${courses}" var="item"> <tr> <td>${item.id}</td> <td>${item.name}</td> <td>${item.sex}</td> <td>${item.minzu}</td> <td>${item.time}</td> <td>${item.age}</td> <td>${item.mianmao}</td> <td>${item.fuwu}</td> <td><a href="CourseServlet?method=getCourseById&id=${item.id}">修改</a></td> </tr> </c:forEach> </table> </div> </body> </html>