验证码
1. 本质:图片
2. 目的:防止恶意表单注册
案例说明
1、绘制一个矩形,然后在矩形上面随机生成4个字符,然后在矩形上随机生成5条以上的先。
2、点击图片或者图片旁边的的字符都会刷新图片
RespnseDemo05.java
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
@WebServlet("/ResponseDemo05")
public class RespnseDemo05 extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//resp.setContentType("text/http;charset=utf-8");
int width = 100;
int height = 50;
//第一步、在内存中创建一个图片对象
BufferedImage buff