• 记账本3


    我弄了一个设置界面的背景

    <title>后面加上<style>body{background:url(images/1.jpg)}</style>,其中1.jsp是在WebContent文件目录下,自己新建了一个文件夹叫做images

    其中,jsp界面怎么设置背景可以参考链接:https://jingyan.baidu.com/article/9989c746c0d308f648ecfe09.html

    另外,登录界面的代码如下:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
     2     pageEncoding="UTF-8"%>
     3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
     4 <html>
     5 <head>
     6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     7 <title>家庭记账本</title>
     8 <style>
     9     body{background:url(images/1.jpg)}
    10 </style>
    11 </head>
    12 <body>
    13     <center>
    14     <br><br><br><br><br><br><br>
    15         <h1 style="color:black">家庭记账本</h1>
    16         <form action="Servlet?method=Login" method="post">
    17             <tr>
    18                 <td>用户名</td>
    19                 <td><input type="text" name="num" id="num"></td>
    20             </tr>
    21             <br><br>
    22             <tr>
    23                 <td>密码</td>
    24                 <td><input type="password" name="password" id="password"></td>
    25             </tr>
    26             <br><br>
    27             <tr>
    28                 <td>用户</td>
    29                 <td>
    30                     <select id="user" name="user">
    31                         <option>管理员</option>
    32                         <option>普通用户</option>
    33                     </select>
    34                 </td>
    35             </tr>
    36             <br><br>
    37             <tr>
    38                 <td><input type="submit" value="登录"></td>
    39             </tr>
    40         </form>
    41     </center>
    42 </body>
    43 </html>
    复制代码

    servlet里面的Login代码为:

    复制代码
     1     public void Login(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException {
     2         request.setCharacterEncoding("utf-8");
     3         response.setCharacterEncoding("utf-8");
     4         String num=request.getParameter("num");
     5         System.out.println(num);
     6         String password=request.getParameter("password");
     7         System.out.println(password);
     8         String user=request.getParameter("user");
     9         System.out.println(user);
    10         if(dao.Login(num,password,user)) {
    11             System.out.println("dao层验证成功");
    12             HttpSession session=request.getSession();
    13             session.setAttribute("loginnum",num);
    14             String loginnum=(String)session.getAttribute("loginnum");
    15             System.out.println(loginnum);
    16             if(user.equals("管理员")) {
    17                 System.out.println("进入管理员功能页");
    18                 request.getRequestDispatcher("admin.jsp").forward(request, response);
    19             }else if(user.equals("用户")) {
    20                 System.out.println("进入用户功能页");
    21                 request.getRequestDispatcher("user.jsp").forward(request,response);
    22             }else {
    23                 System.out.println("进入功能页失败");
    24                 request.getRequestDispatcher("login.jsp").forward(request, response);
    25             }
    26         }else {
    27             System.out.println("dao层验证失败");
    28             request.getRequestDispatcher("login.jsp").forward(request,response);
    29         }    
    30     }
    复制代码

    dao里面得Login代码:

    复制代码
     1 public boolean Login(String num,String password,String user) {
     2         String sql="select num,password,user from login";
     3         Connection conn=Database.getConnection();
     4         Statement stmt=null;
     5         try {
     6             stmt=conn.createStatement();
     7             ResultSet rs=stmt.executeQuery(sql);
     8             while(rs.next()) {
     9                 //用户输入的信息和数据库中的信息做比较,判断输入是否正确;  
    10                 String Num=rs.getString("num");
    11                 System.out.println("从数据库获取的num为:"+Num);
    12                 String pwd=rs.getString("password");
    13                 System.out.println("从数据库获取的password为:"+pwd);
    14                 String us=rs.getString("user");
    15                 System.out.println("从数据库获取的user为:"+us);
    16                 if(Num.trim().compareTo(num)==0&&pwd.trim().compareTo(password)==0&&us.trim().compareTo(user)==0) {
    17                     return true;
    18                 }
    19             }
    20             rs.close();
    21         }catch(Exception e) {
    22             e.printStackTrace();
    23         }
    24         return false;
    25     }
    复制代码

    另外,还在user里面定义了User类以及Consume类:

    User.java

    复制代码
     1 public class User {
     2     private String num;//用户名
     3     private String password;//密码
     4     private String sex;//性别
     5     private String age;//年龄
     6     private String phone;//电话
     7     private String time;//注册时间
     8     public User() {}
     9     public User(String num,String password,String sex,String age,String phone,String time) {
    10         super();
    11         this.num=num;
    12         this.password=password;
    13         this.sex=sex;
    14         this.age=age;
    15         this.phone=phone;
    16         this.time=time;
    17     }
    18     public String getNum() {
    19         return num;
    20     }
    21     public void setNum(String num) {
    22         this.num = num;
    23     }
    24     public String getPassword() {
    25         return password;
    26     }
    27     public void setPassword(String password) {
    28         this.password = password;
    29     }
    30     public String getSex() {
    31         return sex;
    32     }
    33     public void setSex(String sex) {
    34         this.sex = sex;
    35     }
    36     public String getAge() {
    37         return age;
    38     }
    39     public void setAge(String age) {
    40         this.age = age;
    41     }
    42     public String getPhone() {
    43         return phone;
    44     }
    45     public void setPhone(String phone) {
    46         this.phone = phone;
    47     }
    48     public String getTime() {
    49         return time;
    50     }
    51     public void setTime(String time) {
    52         this.time = time;
    53     }
    54 }
    复制代码

    Consume.java

    复制代码
     1 public class Consume {
     2     private String conName;//名称
     3     private String conType;//账单类型
     4     private String conTime;//时间
     5     private String conMoney;//金额
     6     private String conNote;//备注
     7     public Consume() {}
     8     public Consume(String conName,String conType,String conTime,String conMoney,String conNote) {
     9         super();
    10         this.conName=conName;
    11         this.conType=conType;
    12         this.conTime=conTime;
    13         this.conMoney=conMoney;
    14         this.conNote=conNote;
    15     }
    16     public String getConName() {
    17         return conName;
    18     }
    19     public void setConName(String conName) {
    20         this.conName = conName;
    21     }
    22     public String getConType() {
    23         return conType;
    24     }
    25     public void setConType(String conType) {
    26         this.conType = conType;
    27     }
    28     public String getConTime() {
    29         return conTime;
    30     }
    31     public void setConTime(String conTime) {
    32         this.conTime = conTime;
    33     }
    34     public String getConMoney() {
    35         return conMoney;
    36     }
    37     public void setConMoney(String conMoney) {
    38         this.conMoney = conMoney;
    39     }
    40     public String getConNote() {
    41         return conNote;
    42     }
    43     public void setConNote(String conNote) {
    44         this.conNote = conNote;
    45     }
    46     
    47 }
    复制代码
     
     
  • 相关阅读:
    【C++ OpenGL ES 2.0编程笔记】8: 使用VBO和IBO绘制立方体 【转】
    顶点缓存对象(VBO)【转】
    CompileGLShader
    VR虚拟现实的工作原理,你知道多少?【转】
    VR/AR工作原理、目前存在的技术问题
    Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
    nginx配置用户认证
    恢复阿里云RDS云数据库MySQL的备份文件到自建数据库
    阿里云rds linux平台使用wget 工具下载备份与日志文件
    screen 命令使用及示例
  • 原文地址:https://www.cnblogs.com/hanmy/p/14873634.html
Copyright © 2020-2023  润新知