验证码图片

开发工具与关键技术:MyEclipse 10、java
作者:梁添荣
撰写时间:2019-07-18

做登录时,不免会需要验证码。具体思路是:先随机生成几个数字或字母保存,再用BufferedImage和Graphics生成一张图片,再把生成的验证码放进图片中,
具体代码如下:
public class pictureLoginT extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request,response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//设置响应头
		response.setHeader("Pragma", "No-Cache");
		response.setHeader("Cache-Control", "no_cache");
		response.setDateHeader("Expries", 0);
		
		//生成验证码
		Random random=new Random();
		int size=3;
		String code="";
		char c;
		for (int i = 0; i 

你可能感兴趣的:(验证码图片)