• 2.15 使用web 编写一个简单记事本


    首先陈列问题  (等待解决):

    1. 界面是使用 H5   iframe 标签合并而成的,当窗口化之后点击任务栏,显示的内容会在任务栏的下边

     希望可以找其他方式替代 (其他方法不熟练,不能应用)

    如图:

     2. 界面的布局不是很美观,需要学习一些和布局有关的插件

    3.对于录入界面当前只是简单的手动录入,对于某些条件的限制没有添加,比如需要按照某种格式来添加信息,或者提供一个选择日期的表格等等都没有添加。

    4.功能不是很多。需要继续增加,没有一般手机记事本那样的方便(希望界面紧凑一点,将那些文字换成图标)

    制作的简单图形效果如下:

    效果图如下:

     

    dao 层:

      1 package com.Dao;
      2 
      3 import java.sql.Connection;
      4 import java.sql.ResultSet;
      5 import java.sql.SQLException;
      6 import java.sql.Statement;
      7 import java.util.ArrayList;
      8 import java.util.List;
      9 
     10 
     11 import com.Bean.info;
     12 import com.DBUtil.DBUtil;
     13 
     14 public class dao {
     15 
     16     public static void add(String name, String money, String place, String shijian) throws Exception {
     17         Connection conn = DBUtil.getConn();
     18         Statement state =null;
     19         String sql="insert into info(name,money,place,shijian) values('"+name+"','"+money+"','"+place+"','"+shijian+"')";
     20         state = conn.createStatement();
     21         state.executeUpdate(sql);
     22         DBUtil.close(state, conn);
     23         
     24     }
     25 
     26     public static List<info> show() throws Exception {
     27         List<info> list= new ArrayList<>();
     28         Connection conn=DBUtil.getConn();
     29         Statement state=null;
     30         
     31         String sql="select * from info";
     32         
     33         state = conn.createStatement();
     34         ResultSet rs=state.executeQuery(sql);
     35         info use=null;
     36         while(rs.next()) {
     37             //遍历获取的信息
     38             String name=rs.getString("name");
     39             String cost=rs.getString("money");
     40             String place=rs.getString("place");
     41             String time=rs.getString("shijian");
     42             
     43             /*System.out.println(name);
     44             System.out.println(cost);
     45             System.out.println(place);
     46             System.out.println(time);*/
     47             use = new info(name, cost, place, time);
     48             list.add(use);
     49         }
     50         
     51             rs.close();
     52             state.close();
     53             conn.close();
     54         return list;
     55     }
     56 
     57     public static void update(String name, String money, String place, String shijian) throws Exception {
     58         Connection conn=DBUtil.getConn();
     59         Statement state=null;
     60         String sql="update info set money='"+money+"',place='"+place+"',shijian='"+shijian+"'   where name='"+name+"' ";
     61         state=conn.createStatement();
     62         state.executeUpdate(sql);
     63         state.close();
     64         conn.close();
     65         }
     66 
     67     
     68     public static void delete(String name, String time) throws Exception {
     69         Connection conn = DBUtil.getConn();
     70         Statement state=null;
     71         String sql="delete from info where name='"+name+"' and shijian='"+time+"'";
     72         state=conn.createStatement();
     73         state.executeUpdate(sql);
     74         state.close();
     75         conn.close();
     76         
     77     }
     78 
     79     public static List<info> find(String type1, String info) throws Exception {
     80         Connection conn = DBUtil.getConn();
     81         List<info> list=new ArrayList<>();
     82         Statement state=null;
     83         String sql="select * from info where "+type1+" = '"+info+"'";
     84         state=conn.createStatement();
     85         ResultSet rs=state.executeQuery(sql);
     86         info infos=null;
     87         while(rs.next()) {
     88             String name=rs.getString("name");
     89             String money=rs.getString("money");
     90             String place=rs.getString("place");
     91             String time=rs.getString("shijian");
     92             infos =new info(name,money,place,time);
     93             list.add(infos);
     94         }
     95         return list;
     96     }
     97 
     98     
     99     
    100     /*public static void main(String[] args) throws Exception {
    101         dao.show();
    102     }*/
    103 
    104 }

     Servt 层

      1 package com.Servlet;
      2 
      3 import java.io.IOException;
      4 import java.io.UnsupportedEncodingException;
      5 import java.util.List;
      6 
      7 import javax.servlet.ServletException;
      8 import javax.servlet.annotation.WebServlet;
      9 import javax.servlet.http.HttpServlet;
     10 import javax.servlet.http.HttpServletRequest;
     11 import javax.servlet.http.HttpServletResponse;
     12 
     13 import com.Bean.info;
     14 import com.Dao.dao;
     15 
     16 /**
     17  * Servlet implementation class MainServlet
     18  */
     19 @WebServlet("/MainServlet")
     20 public class MainServlet extends HttpServlet {
     21     private static final long serialVersionUID = 1L;
     22        
     23     /**
     24      * @see HttpServlet#HttpServlet()
     25      */
     26     protected void service(HttpServletRequest req,HttpServletResponse resp)throws ServletException,IOException
     27     {
     28         req.setCharacterEncoding("UTF-8");
     29        
     30         String method = req.getParameter("method");
     31         if(method.equals("add"))
     32         {
     33             try {
     34                 add(req,resp);
     35             } catch (Exception e) {
     36                 // TODO Auto-generated catch block
     37                 e.printStackTrace();
     38             }
     39         }
     40         if(method.equals("show"))
     41         {
     42             try {
     43                 show(req,resp);
     44             } catch (Exception e) {
     45                 // TODO Auto-generated catch block
     46                 e.printStackTrace();
     47             }
     48         }
     49         if(method.equals("update"))
     50         {
     51             try {
     52                 update(req,resp);
     53             } catch (Exception e) {
     54                 // TODO Auto-generated catch block
     55                 e.printStackTrace();
     56             }
     57         }
     58         if(method.equals("delete"))
     59         {
     60             try {
     61                 delete(req,resp);
     62             } catch (Exception e) {
     63                 // TODO Auto-generated catch block
     64                 e.printStackTrace();
     65             }
     66         }
     67         if(method.equals("find"))
     68         {
     69             try {
     70                 find(req,resp);
     71             } catch (Exception e) {
     72                 // TODO Auto-generated catch block
     73                 e.printStackTrace();
     74             }
     75         }
     76         
     77         
     78     }
     79 
     80     private void find(HttpServletRequest req, HttpServletResponse resp) throws Exception {
     81         req.setCharacterEncoding("utf-8");
     82         String type1=req.getParameter("type1");
     83         String info=req.getParameter("find");
     84         List<info> list =dao.find(type1,info);
     85         req.setAttribute("list", list);
     86         req.getRequestDispatcher("shownote.jsp").forward(req, resp);
     87         
     88         
     89         
     90     }
     91 
     92     private void delete(HttpServletRequest req, HttpServletResponse resp) throws Exception {
     93         req.setCharacterEncoding("UTF-8");
     94         String name=req.getParameter("name");
     95         String time=req.getParameter("time");
     96         System.out.println(name+time);
     97         dao.delete(name,time);
     98         
     99         
    100     }
    101 
    102     private void update(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    103         
    104         req.setCharacterEncoding("UTF-8");
    105         String name=req.getParameter("name");
    106         String money=req.getParameter("cost");
    107         String place=req.getParameter("place");
    108         String shijian=req.getParameter("time");
    109         /*System.out.println(name);
    110         System.out.println(money);
    111         System.out.println(place);
    112         System.out.println(shijian);*/
    113         dao.update(name,money,place,shijian);
    114         
    115         //req.getRequestDispatcher("updatenote.jsp").forward(req, resp);
    116     }
    117 
    118     private void show(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    119         req.setCharacterEncoding("UTF-8");
    120         List<info> list =dao.show();
    121         req.setAttribute("list", list);
    122         req.getRequestDispatcher("shownote.jsp").forward(req, resp);
    123         
    124     }
    125 
    126     private void add(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    127         req.setCharacterEncoding("UTF-8");
    128         
    129         String name=req.getParameter("name");
    130         String money=req.getParameter("cost");
    131         String place=req.getParameter("place");
    132         String shijian=req.getParameter("time");
    133         /*System.out.println(name);
    134         System.out.println(money);
    135         System.out.println(place);
    136         System.out.println(shijian);*/
    137         dao.add(name,money,place,shijian);
    138         req.getRequestDispatcher("addnote.jsp").forward(req, resp);
    139     }
    140 
    141 }

    index.jsp

     1 <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <!DOCTYPE html>
     4 <html>
     5 <head>
     6 <meta charset="UTF-8">
     7 <title>账本管理</title>
     8 
     9 <style type="text/css">
    10 
    11 .headframe{
    12     100%;
    13     height:130px;
    14     border:0;
    15 }
    16 
    17 .leftframe{
    18     float:left;
    19     250px;
    20     height:600px;
    21     border:0;    
    22 }
    23 
    24 .mainframe{
    25     float:right;
    26     1200px;
    27     height:600px;
    28     border:0;
    29 }
    30 
    31 </style>
    32 
    33 <script type="text/javascript">
    34 
    35 
    36 
    37 </script>
    38 
    39 </head>
    40 <body onload="onload()">
    41 </body>
    42 
    43 <iframe src="head.jsp" class="headframe" scrolling="no"></iframe>
    44 <iframe src="MenuLeft.jsp" class="leftframe" scrolling="no"></iframe>
    45 <iframe src="main.jsp" name="mainAction" class="mainframe"></iframe>
    46 
    47 
    48 </html>

    show.jsp

     1 <%@ page language="java" contentType="text/html; charset=utf-8"
     2     pageEncoding="utf-8"%>
     3     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
     4 <!DOCTYPE html>
     5 <html>
     6 <head>
     7 <meta charset="utf-8">
     8 <title>账单浏览</title>
     9 </head>
    10 
    11 <body onload="onload()">
    12 <div align="left">
    13 <h1>账单浏览:</h1>
    14 
    15 <form action="MainServlet?method=show" method="post" >
    16 <table border="1">
    17 <tr>
    18 <td>消费名称</td>
    19 <td>消费金额</td>
    20 <td>消费地点</td>
    21 <td>消费时间</td>
    22  <td align="center" colspan="1">操作</td>
    23 </tr>
    24 <c:forEach items="${list}" var="item">
    25 <tr>
    26  <td>${item.name}</td>
    27  <td><a href="updatenote.jsp?name=${item.name}&money=${item.cost}&place=${item.place}&time=${item.time}">${item.cost}</a></td>
    28  <td>${item.place}</td>
    29  <td>${item.time}</td>
    30   <td><a href="MainServlet?method=delete&name=${item.name }&time=${item.time}">删除账单</a></td>
    31 </tr>
    32 </c:forEach>
    33 </table>
    34 </form>
    35 </div>
    36 
    37 </body>
    38 </html>
  • 相关阅读:
    口袋摸球
    后渗透(四)数据包捕获
    后渗透(二)权限提升
    文件上传11-21
    MySQL之UDF提权
    《白帽子讲Web安全》读书笔记(一)
    XSS盲打获取cookies&&XSS钓鱼&&XSS键盘记录
    nginx目录穿越漏洞复现&&nginx目录遍历漏洞复现
    python教程(一)·简介
    DataPipeline如何实现数据质量管理?
  • 原文地址:https://www.cnblogs.com/cxy0210/p/12318182.html
Copyright © 2020-2023  润新知