2024.04.15
今天完成了对web的页面的开发,用redis缓存、css等对页面进行了优化
代码示例:
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%> <%@ page errorPage="error.jsp"%> <html> <head> <title>学生信息管理系统</title> <link rel="stylesheet" type="text/css" href="css/style.css"> </head> <body> <h1 style="width: 100%; font-family: 微软雅黑; color:#fff;">学生信息管理系统</h1> <a href="add.jsp">添加学生信息</a> <br /> <br /> <table style="width: 50%;"> <tr> <th>学号</th> <th>姓名</th> <th>性别</th> <th>生日</th> <th>管理</th> </tr> <% try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8", "root", "123456"); //使用Statement对象 Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from student"); while (rs.next()) { int id = rs.getInt(1); out.println("<tr><td>" + rs.getString(1) +"</td><td>" + rs.getString(2) + "</td><td>" + rs.getString(3) + "</td><td>" + rs.getString(4) + "</td><td>"+ rs.getString(5) +"</td><td><a href='edit.jsp?id=" + id + "'>修改</a> <a href='del.jsp?id=" + id + "'>删除</a></td></tr>"); } rs.close(); stmt.close(); con.close(); } catch (Exception e) { out.println("Exception:" + e.getMessage()); } %> </table> <br /> <hr /> <div style="text-align: center; width: 100%; font-size: 12px; color: #333;"> ©版权所有:石家庄铁道大学信息科学与技术学院 <a href="Lab03.png" target="_blank">网站地图</a> </div> </body> </html>
<%@ page contentType="text/html; charset=utf-8" import="java.sql.*" errorPage="error.jsp"%> <html> <head> <title>添加学生信息</title> <link rel="stylesheet" type="text/css" href="css/style.css"> <script type="text/javascript"> function check() { var id = document.getElementById("id"); var name = document.getElementById("name"); var sex = document.getElementById("sex"); var birthday= document.getElementById("birthday"); //非空 if(id.value == '') { alert('学号为空'); name.focus(); return false; } if(name.value == '') { alert('姓名为空'); teacher.focus(); return false; } if(sex.value == '') { alert('性别为空'); classroom.focus(); return false; } if(birthday.value == '') { alert('生日为空'); classroom.focus(); return false; } } </script type="text/javascript"> </head> <body> <% Object message = request.getAttribute("message"); if(message!=null && !"".equals(message)){ %> <script type="text/javascript"> alert("<%=request.getAttribute("message")%>"); </script> <%} %> <form action="addsave.jsp" method="post" onsubmit="return check()"> <h2>添加学生信息</h2> <table style="width: 50%"> <tr> <th width="30%">学号</th> <td width="70%"><input name="id" type="text"></td> </tr> <tr> <th>姓名</th> <td><input name="name" type="text"></td> </tr> <tr> <th>性别</th> <td><input name="sex" type="text"></td> </tr> <tr> <th>生日</th> <td><input name="birthday" type="text"></td> </tr> <tr> <td colspan="2"><input type="submit" name="submit" value="添加"> <input type="reset" value="重置"></td> </tr> </table> </form> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)