Dao层:
package com.yds.dao; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import com.yds.DBUtil.Util; import com.yds.model.User; public class Dao { /** * 注册 * * @param user * @return */ public boolean add(User user) { String sql = "insert into zhuce(username, password) values(‘" + user.getUsername() + "‘,‘" + user.getPassword() + "‘)"; Connection conn = Util.getConn(); Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); a = state.executeUpdate(sql); a++; } catch (Exception e) { e.printStackTrace(); } finally { Util.close(state, conn); } if (a > 0) { f = true; } return f; } /** * 登录,比对密码 * * @param username * @return */ public String search(String username) { String sql = "select * from zhuce where "; if (username != "") { sql += "username like ‘%" + username + "%‘"; } Connection conn = Util.getConn(); Statement state = null; ResultSet rs = null; String password2 = null; try { state = conn.createStatement(); rs = state.executeQuery(sql); while (rs.next()) { password2 = rs.getString("password"); } } catch (SQLException e) { e.printStackTrace(); } finally { Util.close(rs, state, conn); } return password2; } /** * 登录,比对用户名 * * @param username * @return */ public String search1(String username) { String sql = "select * from zhuce where "; if (username != "") { sql += "username like ‘%" + username + "%‘"; } Connection conn = Util.getConn(); Statement state = null; ResultSet rs = null; try { state = conn.createStatement(); rs = state.executeQuery(sql);//executeQuery()返回包含给定查询所生成数据的 ResultSet 对象,如果没有查询到信息,返回一个next()为false的ResultSet 对象 while (rs.next()) { username = rs.getString("username"); } } catch (SQLException e) { e.printStackTrace(); } finally { Util.close(rs, state, conn); } return username; } }
package com.yds.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import com.mysql.jdbc.Statement; import com.yds.DBUtil.Util; import com.yds.model.Tally; /** * 分页查询DAO * @author Lenovo * */ public class PagerDao { public List<Tally> find(int page) { // 创建List List<Tally> list = new ArrayList<Tally>(); Connection conn = Util.getConn(); String sql = "select * from tallybook order by id desc limit ?,?"; try { // 获取PreparedStatement PreparedStatement ps = conn.prepareStatement(sql); // 对SQL语句中的第1个参数赋值 ps.setInt(1, (page - 1) * Tally.PAGE_SIZE); // 对SQL语句中的第2个参数赋值 ps.setInt(2, Tally.PAGE_SIZE); // 执行查询操作 ResultSet rs = ps.executeQuery(); // 光标向后移动,并判断是否有效 while (rs.next()) { // 实例化Tally Tally p = new Tally(); // 对id属性赋值 p.setId(rs.getInt("id")); p.setDate(rs.getString("date")); p.setType(rs.getString("Type")); p.setMoney(rs.getString("money")); p.setStyle(rs.getString("style")); // 将Tally添加到List集合中 list.add(p); } // 关闭ResultSet rs.close(); // 关闭PreparedStatement ps.close(); // 关闭Connection conn.close(); } catch (SQLException e) { e.printStackTrace(); } return list; } /** * * 查询总记录数 * * @return 总记录数 * */ public int findCount() { // 总记录数 int count = 0; // 获取数据库连接 Connection conn = Util.getConn(); // 查询总记录数SQL语句 String sql = "select count(*) from tallybook"; try { // 创建Statement Statement stmt = (Statement) conn.createStatement(); // 查询并获取ResultSet ResultSet rs = stmt.executeQuery(sql); // 光标向后移动,并判断是否有效 if (rs.next()) { // 对总记录数赋值 count = rs.getInt(1); } // 关闭ResultSet rs.close(); // 关闭Connection conn.close(); } catch (SQLException e) { e.printStackTrace(); } // 返回总记录数 return count; } }
package com.yds.dao; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; import com.yds.DBUtil.Util; import com.yds.model.Tally; public class TallyDao { /** * 添加 * * @param course * @return */ public boolean add(Tally course) { String sql = "insert into tallybook(date, Type, money, style) values(‘" + course.getDate() + "‘,‘" + course.getType() + "‘,‘" + course.getMoney() + "‘,‘" + course.getStyle() + "‘ )";// insert // : // 创建一个表 // 表名course // 包含三个条目 // 创建数据库链接 Connection conn = Util.getConn();// Connection对象实例化 java.sql.Statement state = null; boolean f = false; int a = 0; try { state = conn.createStatement(); a = state.executeUpdate(sql);// executeUpdate 增 删 改时使用 } catch (Exception e) { e.printStackTrace(); } finally { // 关闭连接 Util.close(state, conn); } if (a > 0) { f = true; } return f; } /** * 删除 * * @param id * @return */ public boolean delete (int id) { boolean f = false; String sql = "delete from tallybook where id=‘" + id + "‘"; Connection conn = Util.getConn(); Statement state = null; int a = 0; try { state = conn.createStatement(); a = state.executeUpdate(sql); } catch (SQLException e) { e.printStackTrace(); } finally { Util.close(state, conn); } if (a > 0) { f = true; } return f; } }
DButil层:
package com.yds.DBUtil; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import com.mysql.jdbc.PreparedStatement; /** * 数据库连接工具 * * @author * */ public class Util { public static String db_url = "jdbc:mysql://localhost:3306/tallybook"; public static String db_user = "root"; public static String db_pass = "101032"; public static Connection getConn() { Connection conn = null;// 设置为空,准备重新连接数据库 try { Class.forName("com.mysql.jdbc.Driver");// 加载驱动 conn = DriverManager.getConnection(db_url, db_user, db_pass); //System.out.println("111"); } catch (Exception e) { e.printStackTrace(); } return conn; } /** * 关闭连接 * * @param state * @param conn */ public static void close(Statement state, Connection conn) { if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void close(ResultSet rs, Statement state, Connection conn) { if (rs != null) { try { rs.close(); } catch (SQLException e) { e.printStackTrace(); } } if (state != null) { try { state.close(); } catch (SQLException e) { e.printStackTrace(); } } if (conn != null) { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } } public void close(Connection conn, PreparedStatement pstmt, ResultSet result) { if (conn != null) { try { conn.close(); } catch (SQLException e) { } } if (pstmt != null) { try { pstmt.close(); } catch (SQLException e) { e.printStackTrace(); } } if (result != null) { try { result.close(); } catch (SQLException e) { e.printStackTrace(); } } } public static void main(String[] args) { getConn(); } }
Bean:
import java.util.List; public class Page<T> { private Integer pageNow;// 当前页数 // private Integer pageCount;总页数 private Integer rowCount;// 总行数 private Integer pageSize;// 每一页行数 private List<Tally> pageRow;// 当前页表格数据 public Page() { super(); } public Page(Integer pageNow, Integer rowCount, Integer pageSize, List<Tally> pageRow) { super(); this.pageNow = pageNow; this.rowCount = rowCount; this.pageSize = pageSize; this.pageRow = pageRow; } public Integer getPageNow() { return pageNow; } public void setPageNow(Integer pageNow) { this.pageNow = pageNow; } public Integer getPageCount() { Integer pageCount = rowCount % pageSize == 0 ? rowCount / pageSize : (rowCount / pageSize + 1); return pageCount; } /* * public void setPageCount(Integer pageCount) { this.pageCount = pageCount; * } */ public Integer getRowCount() { return rowCount; } public void setRowCount(Integer rowCount) { this.rowCount = rowCount; } public Integer getPageSize() { return pageSize; } public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } public List<Tally> getpageRow() { return pageRow; } public void setpageRow(List<Tally> pageRow) { this.pageRow = pageRow; } }
public class Tally { public static final int PAGE_SIZE = 6; private int id; private String date; private String money; private String Type;// 收入还是支出 private String style;// 收入支出方式 public int getId() { return id; } public void setId(int id) { this.id = id; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getMoney() { return money; } public void setMoney(String money) { this.money = money; } public String getType() { return Type; } public void setType(String type) { Type = type; } public String getStyle() { return style; } public void setStyle(String style) { this.style = style; } public Tally(int id, String date, String Type, String money, String style) { this.id = id; this.date = date; this.Type = Type; this.style = style; } public Tally(String date, String Type, String money, String style) { this.date = date; this.Type = Type; this.style = style; this.money = money; } public Tally(){ } }
public class User { private int id; private String username; private String password; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public User(int id,String username,String password) { this.id = id; this.username = username; this.password = password; } public User(String username,String password) { this.username = username; this.password = password; } }
Servlet:
import java.io.IOException; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.yds.dao.PagerDao; import com.yds.model.Tally; /** * Servlet implementation class PagerServlet */ @WebServlet("/PagerServlet") public class PagerServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * 分页查询Servlet */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 当前页码 int currPage = 1; // 判断传递页码是否有效 if (request.getParameter("page") != null) { // 对当前页码赋值 currPage = Integer.parseInt(request.getParameter("page")); } PagerDao dao = new PagerDao(); // 查询所有信息 List<Tally> list = dao.find(currPage); // 将list放置到request之中 request.setAttribute("list", list); // 总页数 int pages; // 查询总记录数 int count = dao.findCount(); // 计算总页数 if (count % Tally.PAGE_SIZE == 0) { // 对总页数赋值 pages = count / Tally.PAGE_SIZE; } else { // 对总页数赋值 pages = count / Tally.PAGE_SIZE + 1; } // 实例化StringBuffer StringBuffer sb = new StringBuffer(); // 通过循环构建分页条 for (int i = 1; i <= pages; i++) { // 判断是否为当前页 if (i == currPage) { // 构建分页条 sb.append("『" + i + "』"); } else { // 构建分页条 sb.append("<a href=‘PagerServlet?page=" + i + "‘>" + i + "</a>"); } // 构建分页条 sb.append(" "); } // 将分页条的字符串放置到request之中 request.setAttribute("bar", sb.toString()); request.getRequestDispatcher("index.jsp").forward(request, response); } }
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.yds.dao.TallyDao; import com.yds.model.Tally; /** * 具体增删改查Servlet */ @WebServlet("/TallyBookServlet") public class TallyBookServlet extends HttpServlet { private static final long serialVersionUID = 1L; TallyDao dao = new TallyDao(); /** * 方法选择 */ protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String method = req.getParameter("method"); if ("add".equals(method)) { add(req, resp); } // else if ("ids_1".equals(method)) { // del(req, resp); // } else if ("ids_2".equals(method)) { // upd(req, resp); // } } /** * 增加 * * @param req * @param resp * @throws IOException * @throws ServletException */ private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { req.setCharacterEncoding("utf-8"); // 获取数据 String date = req.getParameter("date"); String Type = req.getParameter("Type"); String money = req.getParameter("money"); String style = req.getParameter("style"); Tally course = new Tally(date, Type, money, style); if (dao.add(course)) { req.setAttribute("message", "记录添加成功"); req.getRequestDispatcher("add.jsp").forward(req, resp); } else { req.setAttribute("message", "记录添加失败!请重新添加!"); req.getRequestDispatcher("add.jsp").forward(req, resp); } } // /** // * 删除 // * // * @param req // * @param resp // * @throws IOException // * @throws ServletException // */ // @SuppressWarnings("unused") // private void del(HttpServletRequest req, HttpServletResponse resp) throws // IOException, ServletException { // req.setCharacterEncoding("utf-8"); // int id = Integer.parseInt(req.getParameter("ids")); // dao.delete(id); // req.setAttribute("message", "删除成功!"); // req.getRequestDispatcher("index.jsp").forward(req, resp); // } // // /** // * 修改 // * // * @param req // * @param resp // */ // private void upd(HttpServletRequest req, HttpServletResponse resp) { // // } }
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.yds.dao.Dao; import com.yds.model.User; /** * 用户登录注册Servlet * @author Lenovo * */ @WebServlet("/UserServlet") public class UserServlet extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public UserServlet() { super(); } Dao dao = new Dao(); protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("utf-8"); String method = req.getParameter("method"); if ("add".equals(method)) { add(req, resp); } else if ("search".equals(method)) { search(req, resp); } } private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { req.setCharacterEncoding("utf-8"); String username = req.getParameter("username"); String password = req.getParameter("password"); String rpassword = dao.search(username); String rusername = dao.search1(username); if(password.equals(rpassword)&&username.equals(rusername )) { req.setAttribute("message", "登陆成功!"); req.getRequestDispatcher("userlist.jsp").forward(req,resp); } else { req.setAttribute("message", "用户不存在或密码错误!"); req.getRequestDispatcher("denglu.jsp").forward(req,resp); } } private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { String username = req.getParameter("username"); String password = req.getParameter("password"); User user= new User(username,password); if(dao.add(user)) { req.setAttribute("message", "注册成功!"); req.getRequestDispatcher("denglu.jsp").forward(req, resp); }else { req.setAttribute("message", "注册失败!"); req.getRequestDispatcher("zhuce.jsp").forward(req, resp); } } }
JSP:
登录:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <!-- table表格美化 --> <style type="text/css"> .font { font-size: 30px } thead { color: blue } table { border: 2px #CCCCCC solid; width: 360px; } td, th { height: 30px; border: 1px #CCCCCC solid; } </style> <!-- 美化input文本框 --> <style type="text/css"> input { border: 1px solid #ccc; padding: 7px 0px; border-radius: 3px; padding-left: 5px; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s; -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s } input:focus { border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6) } </style> <!-- button按钮美化 --> <style type="text/css"> .login-button { /* 按钮美化 */ width: 150px; /* 宽度 */ height: 40px; /* 高度 */ border-width: 0px; /* 边框宽度 */ border-radius: 3px; /* 边框半径 */ background: #1E90FF; /* 背景颜色 */ cursor: pointer; /* 鼠标移入按钮范围时出现手势 */ outline: none; /* 不显示轮廓线 */ font-family: Microsoft YaHei; /* 设置字体 */ color: white; /* 字体颜色 */ font-size: 17px; /* 字体大小 */ } .login-button:hover { /* 鼠标移入按钮范围时改变颜色 */ background: #5599FF; } </style> <meta http-equiv="Content-Type" content="text/html; 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"> <div><h1>登录</h1></div> <form action="UserServlet?method=search" method="post" onsubmit="return check()"> <table align="center" border="1" width="50%" cellpadding="6"> <thead> <tr> <th colspan="2" align="center" > 登录</th> </tr> </thead> <tr> <td align="center" >用户名</td> <td align="center" ><input type="text" name="username" clas></td> </tr> <tr> <td align="center" >密码</td> <td align="center" ><input type="text" name="password"></td> </tr> <tr> <th colspan="2" align="center" ><button type="submit" class="login-button">登 陆</button></th> </tr> </table> </form> <div><a href="zhuce.jsp"><font SIZE="4" >注册</font></a></div> </div> <script type="text/javascript"> function check() { var username = document.getElementById("username");; var password = document.getElementById("password"); //非空 if(username.value == ‘‘) { alert(‘账号为空‘); username.focus(); return false; } if(password.value == ‘‘) { alert(‘密码为空‘); password.focus(); return false; } } </script> </body> </html>
注册:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- table表格美化 --> <style type="text/css"> .font { font-size: 30px } thead { color: red } table { border: 2px #CCCCCC solid; width: 360px; } td, th { height: 30px; border: 1px #CCCCCC solid; } </style> <!-- 美化input文本框 --> <style type="text/css"> input { border: 1px solid #ccc; padding: 7px 0px; border-radius: 3px; padding-left: 5px; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s; -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s } input:focus { border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6) } </style> <!-- button按钮美化 --> <style type="text/css"> .login-button { /* 按钮美化 */ width: 150px; /* 宽度 */ height: 40px; /* 高度 */ border-width: 0px; /* 边框宽度 */ border-radius: 3px; /* 边框半径 */ background: #1E90FF; /* 背景颜色 */ cursor: pointer; /* 鼠标移入按钮范围时出现手势 */ outline: none; /* 不显示轮廓线 */ font-family: Microsoft YaHei; /* 设置字体 */ color: white; /* 字体颜色 */ font-size: 17px; /* 字体大小 */ } .login-button:hover { /* 鼠标移入按钮范围时改变颜色 */ background: #5599FF; } </style> <head> <meta http-equiv="Content-Type" content="text/html; 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> <%} %> <form action="UserServlet?method=add" method="post" onsubmit="return check()"> <table align="center" border="1" width="50%" cellpadding="10" cellspacing="0"> <thead> <tr> <th colspan="2" align="center" > 注册</th> </tr> </thead> <tr> <td align="center" >用户名</td> <td align="center" ><input type="text" name="username"></td> </tr> <tr> <td align="center" >密码</td> <td align="center" ><input type="password" name="password"></td> </tr> <tr> <td align="center" >确认密码</td> <td align="center" ><input type="password" name="spassword"></td> </tr> <tr> <th colspan="2" align="center" ><button type="submit" class="login-button">注 册</button></th> </tr> </table> </form> <div><a href="denglu.jsp"><font SIZE="4" >返回登录</font></a></div> </div> <script type="text/javascript"> function check() { var username = document.getElementById("username");; var password = document.getElementById("password"); var rpassword = document.getElementById("rpassword"); //非空 if(username.value == ‘‘) { alert(‘账号为空‘); username.focus(); return false; } if(password.value == ‘‘) { alert(‘密码不能为空‘); return false; } if(rpassword.value == ‘‘) { alert(‘确认密码为空‘); rpassword.focus(); return false; } if(rpassword.value!= password.value) { alert(‘两次密码不一致,请重新输入‘); rpassword.focus(); return false; } } </script> </body> </html>
其他:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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>Insert title here</title> </head> <body> <a href="PagerServlet">查看所有记录</a> </body> </html>
记账本主页:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page import="java.util.List"%> <%@page import="com.yds.model.Tally"%><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>所有信息</title> <!-- table表格美化 --> <style type="text/css"> .font { font-size: 20px } thead { color: red } table { border: 2px #CCCCCC solid; width: 700px; } td, th { height: 30px; border: 1px #CCCCCC solid; } </style> <!-- button按钮美化 --> <style type="text/css"> .button { /* 按钮美化 */ width: 50px; /* 宽度 */ height: 30px; /* 高度 */ border-width: 0px; /* 边框宽度 */ border-radius: 3px; /* 边框半径 */ background: #1E90FF; /* 背景颜色 */ cursor: pointer; /* 鼠标移入按钮范围时出现手势 */ outline: none; /* 不显示轮廓线 */ font-family: Microsoft YaHei; /* 设置字体 */ color: white; /* 字体颜色 */ font-size: 17px; /* 字体大小 */ } .login-button:hover { /* 鼠标移入按钮范围时改变颜色 */ background: #5599FF; } </style> </head> <body> <a href="add.jsp">每日一记</a> <table align="center" border="1" width="50%" cellpadding="10" cellspacing="0"> <thead> <tr> <th colspan="7" align="center" class="font">我的账本</th> </tr> </thead> <tr> <td align="center">ID</td> <td align="center">收支出日期</td> <td align="center">收支出方式</td> <td align="center">收支出金额</td> <td align="center">收支出类型</td> <td align="center">修改</td> <td align="center">删除</td> </tr> <% List<Tally> list = (List<Tally>) request.getAttribute("list"); for (Tally p : list) { %> <tr align="center" bgcolor="white"> <td><%=p.getId()%></td> <td><%=p.getDate()%></td> <td><%=p.getType()%></td> <td><%=p.getMoney()%></td> <td><%=p.getStyle()%></td> <td><input type="button" value="修改" class="button" onclick="return ckeck();location.href=‘TallyBookServlet?ids_1=<%=p.getId()%>‘"> </td> <td><input type="button" value="刪除" class="button" onclick="return ckeck();location.href=‘TallyBookServlet?ids_2=<%=p.getId()%>‘"></td> </tr> <% } %> <tr> <td align="center" colspan="6" bgcolor="white"><%=request.getAttribute("bar")%> </td> </tr> </table> </body> <script type="text/javascript"> function check() { if (confirm("确认执行此操作吗?")) { return true; } else { return false; } } </script> </html>
记账:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <!-- table表格美化 --> <style type="text/css"> .font { font-size: 30px } thead { color: blue } table { border: 2px #CCCCCC solid; width: 360px; } td, th { height: 30px; border: 1px #CCCCCC solid; } </style> <!-- 美化input文本框 --> <style type="text/css"> input { border: 1px solid #ccc; padding: 7px 0px; border-radius: 3px; padding-left: 5px; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s; -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s } input:focus { border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6) } </style> <!-- button按钮美化 --> <style type="text/css"> .login-button { /* 按钮美化 */ width: 150px; /* 宽度 */ height: 40px; /* 高度 */ border-width: 0px; /* 边框宽度 */ border-radius: 3px; /* 边框半径 */ background: #1E90FF; /* 背景颜色 */ cursor: pointer; /* 鼠标移入按钮范围时出现手势 */ outline: none; /* 不显示轮廓线 */ font-family: Microsoft YaHei; /* 设置字体 */ color: white; /* 字体颜色 */ font-size: 17px; /* 字体大小 */ } .login-button:hover { /* 鼠标移入按钮范围时改变颜色 */ background: #5599FF; } </style> <meta http-equiv="Content-Type" content="text/html; 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> <% } %> <a href="#" onclick="history.back()">返回上一页</a> <a href="userlist.jsp">返回主页面</a> <!-- <td width="5%"><input type="button" value="返回上一页" onclick="javascript:goback();"></td> --> <form action="TallyBookServlet?method=add" method="post" onsubmit="return check()"> <table align="center" border="1" width="50%" cellpadding="10" cellspacing="0"> <thead> <tr> <th colspan="5" align="center" class="font">每日一记</th> </tr> </thead> <tr> <td align="center">收支出日期</td> <td align="center">收支出方式</td> <td align="center">收支出金额</td> <td align="center">收支出类型</td> </tr> <tr> <td align="left"><input type="text" id="date" name="date" required oninvalid="setCustomValidity(‘此项为必填项‘)" oninput="setCustomValidity(‘‘)"></td> <td align="left"><select id="Type" name="Type" class="select"> <option value="">请选择</option> <option value="收入">收入</option> <option value="支出">支出</option> </select></td> <td align="left"><input type="number" id="money" name="money" required oninvalid="setCustomValidity(‘只能输入数字‘)" oninput="setCustomValidity(‘‘)"></td> <td align="left"><input type="text" id="style" name="style" required="required" onBlur="check()"></td> <tr> <th colspan="4" align="center"><button type="submit" class="login-button">保 存</button></th> </tr> </table> </form> </body> </html>
原文:https://www.cnblogs.com/a155-/p/12269931.html