zoukankan      html  css  js  c++  java
  • 1月7日 家庭小账本 开发记录

    1、阅读构建之法 现代软件工程(第三版)

    2、观看JSP+Servlet+MySql+Tomcat+JDBC项目详细讲解

    3、实现家庭小账本登录功能

    (1)Loginuserservlet

    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);
    }

    }

    (2)dao

    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;
    }

  • 相关阅读:
    线程阶段性总结——APM,ThreadPool,Task,TaskScheduler ,CancellationTokenSource
    研究BackgroundWorker后发现:AsyncOperation和SynchronizationContext的差异真的很大!
    线程同步——优势、劣势
    APM异步编程模型的优势
    DataGridView的VirtualMode,在大容量数据加载时特别有用
    【C】——C语言的位运算的优势
    【linux】——Linux tar打包命令
    【C】用文件和链表实现学生信息管理
    【C】——回调函数的好处
    【C】strcpy()需谨慎使用;
  • 原文地址:https://www.cnblogs.com/lx06/p/14280779.html
Copyright © 2011-2022 走看看