首页>代码>java web开发简单实用的图片验证码功能>/One/src/com/jy/servlet/RegisterServlet.java
package com.jy.servlet;

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 RegisterServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
				//中文乱码处理
				req.setCharacterEncoding("utf-8");	
				//获取表单上输入的验证码
				String checkcode = req.getParameter("checkCode");
				System.out.println(checkcode);
				//获取自动生成的验证码
				String str = (String) req.getSession().getAttribute("number");
				//去大小写字母比较
				boolean rstr = (checkcode.equalsIgnoreCase(str));			
				if(rstr){
					System.out.println("输入正确");
				}else{
					String msg = "你输入的验证码错误!";
					req.setAttribute("msg", "<font color='red'>" + msg + "</font>");
					req.getRequestDispatcher("reg.jsp").forward(req, resp);
				}
	}

}
最近下载更多
846488283  LV4 2023年5月28日
lvhongquan  LV11 2022年5月22日
JohnAlex  LV9 2022年2月22日
gezellig  LV6 2021年10月21日
messi_Liu  LV1 2019年12月4日
qq348438222  LV1 2019年10月18日
qianxinyue  LV1 2019年7月5日
李七七  LV1 2019年7月2日
嘎嘎嘎01  LV1 2019年6月25日
ldd5333333  LV4 2019年6月16日
最近浏览更多
asddwh  LV12 2023年12月26日
zj20020510  LV5 2023年9月18日
936684178  LV2 2023年6月26日
Merdan_810 2023年6月9日
暂无贡献等级
846488283  LV4 2023年5月28日
Akail003 2023年4月6日
暂无贡献等级
cyn123456 2023年2月13日
暂无贡献等级
3174233007 2022年12月19日
暂无贡献等级
与哲rhcy  LV6 2022年12月4日
2890440805  LV3 2022年8月4日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友