• 登录页面跳转与错误提示信息


    ---恢复内容开始---

    //主界面信息的处理

     package day13;

    import java.io.IOException;
    import java.sql.SQLException;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.commons.dbutils.QueryRunner;
    import org.apache.commons.dbutils.handlers.BeanHandler;

    public class Myservlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    //解决乱码
    request.setCharacterEncoding("UTF-8");
    //1 2判断用户名和密码
    String username = request.getParameter("username");
    String password = request.getParameter("password");

    bank qyuser=null;
    //2 调用login(username,password); 进行查询用户是否存在
    try {
    qyuser=login1(username,password);
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    //3 通过接结果值 是否为null 判断用户名是否正确
    if(qyuser!=null){
    //用户名密码正确 登录首页
    //3获得用户输入的验证码
    String check_client = request.getParameter("checkCode");
    //4 获得这个成语
    String checkOde =(String) request.getSession().getAttribute("checkcode_session");
    if(!checkOde.equals(check_client)){
    request.setAttribute("loginFo", "您的验证码不正确");
    request.getRequestDispatcher("/login.jsp").forward(request, response);

    }
    else{
    request.getRequestDispatcher("/index.jsp").forward(request, response);
    }


    }else{
    //用户名错误

    request.setAttribute("loginInfo", "用户名或者密码错误");
    request.getRequestDispatcher("/login.jsp").forward(request, response);

    }
    }

    public bank login1(String username, String password) throws SQLException {
    QueryRunner qu = new QueryRunner(JDBCUtils.getDataSource());
    String sql="select * from bank where username=? and password=?";

    bank query = qu.query(sql, new BeanHandler <bank>(bank.class),username,password);
    return query;

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    doGet(request, response);
    }

    }

    //错误信息的处理

    <div><%=request.getAttribute("loginFo")==null?"":request.getAttribute("loginFo") %></div>

    <div><%=request.getAttribute("loginInfo")==null?"":request.getAttribute("loginInfo") %></div>

  • 相关阅读:
    java表达式中运算符优先级
    数据库建表规则
    linux 安装java环境
    springboot指定端口的三种方式
    服务器监控
    Dubbo 的配置主要分为三大类
    oracle数值函数 abs()、 ceil()、 cos()、 cosh()
    linux基础命令总结
    redis+sentinel集群部署
    centos7制作本地yum源
  • 原文地址:https://www.cnblogs.com/Fisherman13/p/10480252.html
Copyright © 2020-2023  润新知