Java制作验证码(Java验证码小程序)(2)

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

}

CheckCode(验证码验证servlet)

@WebServlet("/CheckCode")
public class CheckCode extends HttpServlet {
    private static final long serialVersionUID = 1L;
     
    /**
    * @see HttpServlet#HttpServlet()
    */
    public CheckCode() {
        super();
        // TODO Auto-generated constructor stub
    }

/**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setCharacterEncoding("utf-8");
        String code = request.getParameter("code").toUpperCase();//获取传来验证码并进行大小写转换
        String result=null;
        if(request.getSession().getAttribute("newCode").equals(code))
        {
            result="验证成功!";
            response.getWriter().append(result);
        }
        else {
            result="验证码错误!";
            response.getWriter().append(result);
        }
    }

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/e719e7ea50a33036e40c961826603ea6.html