zoukankan      html  css  js  c++  java
  • 每日日报2021.2.3

    今天完成内容:

    开发家庭小账本:登录

    1.编写代码

    package com.edu.servlet;

    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.edu.dao.Luserdao;
    import com.edu.entity.Luser;


    @WebServlet("/Loginuserservlet")
    public class Loginuserservlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.setCharacterEncoding("utf-8");
    String lname = request.getParameter("lname");
    String lpwd = request.getParameter("lpwd");
    Luser luser = new Luser();
    if(lname!=null && lpwd!=null) {
    luser.setLname(lname);
    luser.setLpwd(lpwd);
    Luserdao luserdao = new Luserdao();
    if(luserdao.login(luser)) {
    request.getRequestDispatcher("/Menu.jsp").forward(request, response);
    }else {
    request.getRequestDispatcher("/elogin.jsp").forward(request, response);
    }
    }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    }

    }

    public boolean login(Luser luser) {
    Connection conn = DbHelper.getConnection();
    String sql = "select * from uselogin where lname=?";
    boolean flag = false;
    PreparedStatement pst = null;
    Luser lu = new Luser();
    ResultSet rst = null;
    try {
    pst = conn.prepareStatement(sql);
    pst.setString(1,luser.getLname());
    rst = pst.executeQuery();
    while(rst.next()) {
    lu.setLname(rst.getString("lname"));
    lu.setLpwd(rst.getString("lpwd"));
    }
    if(luser.getLpwd().equals(lu.getLpwd())) {
    flag = true;
    }
    rst.close();
    pst.close();
    } catch (SQLException e) {
    // TODO 自动生成的 catch 块
    e.printStackTrace();
    }

    // TODO 自动生成的方法存根
    return flag;
    }

    遇到问题:

    明日目标:

    学习Android studio的开发

  • 相关阅读:
    InvokeRequired和Invoke
    DataGrid 得到DataGridRow 和DataGridColumn
    DataGrid 如何得到DataGridRow 和DataGridCell 对象
    安装Extended WPF Toolkit
    WPF DataGrid绑定一个组合列
    允许Root登录Docker ubuntu(MAC主机,使用portainer管理)
    photoshop人物美白教程:暗沉肤色提亮美白
    django中聚合aggregate和annotate GROUP BY的使用方法
    Django Model 基础数据库操作应用
    如何在mac上安装gitlab
  • 原文地址:https://www.cnblogs.com/leiyu1905/p/14905709.html
Copyright © 2011-2022 走看看