zoukankan      html  css  js  c++  java
  • session的应用----验证码

    昨天登录功能中叙述了密码 用户名的数据库验证以及转发 那么这篇文章在昨天的基础上 处理验证码的验证功能,今天需要用到session域,session用于一次会话。

    package cn.lijun.demo;

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class LoginServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    //0解决乱码
    request.setCharacterEncoding("UTF-8");

    //验证码校验
    //获得页面输入的验证
    String checkCode_client = request.getParameter("checkCode");
    //根据验证码存储的session 数据 取出对应的数据

    String checkCode_session = (String) request.getSession().getAttribute("checkcode_session");
    //对比数据
    if(!checkCode_session.equals(checkCode_client)){
    request.setAttribute("loginInfo", "您的验证码不正确请重新输入");
    //跳转
    request.getRequestDispatcher("/login.jsp空间").forward(request, response);
    return;
    }


    //昨天讲的密码 用户名验证
    //......

    }

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

  • 相关阅读:
    jar 常用操作
    linux 加载新的磁盘(卷组)
    apache 代理配置
    spring boot datasource 参数设置
    svn 常用命令
    最详细的maven教程
    centos 用户组操作
    ubuntu命令行操作mysql常用操作
    Ruby-Clamp
    maven使用备忘
  • 原文地址:https://www.cnblogs.com/lijun6/p/10478463.html
Copyright © 2011-2022 走看看