国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

驗證碼的代碼

2020-05-09 11:08 作者:小垃圾kiki  | 我要投稿
package cn.itcast.servlet.web;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;

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;

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

?? ?/**
?? ? * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
?? ? */
?? ?protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
?? ??? ?//1.創(chuàng)建一個對象,這個對象在內(nèi)存中就代表圖片(驗證碼圖片對象)
?? ??? ?int width=100;
?? ??? ?int height=50;
?? ??? ?BufferedImage image=new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
?? ??? ?//2.美化圖片
?? ??? ?//2.1填充圖片顏色
?? ??? ?Graphics g = image.getGraphics();//獲取畫筆的對象
?? ??? ?g.setColor(Color.pink);//設(shè)置畫筆的顏色
?? ??? ?g.fillRect(0, 0, width, height);//填充圖片
?? ??? ?//2.2畫邊框
?? ??? ?g.setColor(Color.blue);
?? ??? ?g.drawRect(0, 0, width-1, height-1);
?? ??? ?
?? ??? ?String str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
?? ??? ?//生成隨機角標(biāo)
?? ??? ?Random ran=new Random();
?? ??? ?for (int i = 1; i <=4; i++) {
?? ??? ??? ?int index = ran.nextInt(str.length());
?? ??? ??? ?//獲取字符
?? ??? ??? ?char ch = str.charAt(index);
?? ??? ??? ?//2.3寫驗證碼
?? ??? ??? ?g.drawString(ch+"",width/5*i,height/2);
?? ??? ?}
?? ??? ?//2.4畫干擾線
?? ??? ?g.setColor(Color.green);
?? ??? ?//隨機生成坐標(biāo)點
?? ??? ?for (int i = 0; i < 10; i++) {
?? ??? ??? ?int x1=ran.nextInt(width);//生成一個0-width的隨機值,不包括width
?? ??? ??? ?int x2=ran.nextInt(width);
?? ??? ??? ?int y1=ran.nextInt(height);
?? ??? ??? ?int y2=ran.nextInt(height);
?? ??? ??? ?g.drawLine(x1, x2, y1, y2);
?? ??? ?}
?? ??? ?
?? ??? ?
?? ??? ?
?? ??? ?//3.將圖片輸出到頁面展示
?? ??? ?//將內(nèi)存中的圖片輸出到頁面
?? ??? ?ImageIO.write(image, "jpg", response.getOutputStream());
?? ?}

?? ?/**
?? ? * @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);
?? ?}

}

驗證碼的代碼的評論 (共 條)

分享到微博請遵守國家法律
云梦县| 闻喜县| 格尔木市| 大理市| 中山市| 双桥区| 十堰市| 永丰县| 本溪市| 探索| 古田县| 石狮市| 连城县| 交城县| 英吉沙县| 龙陵县| 漳平市| 齐河县| 上虞市| 葵青区| 扎囊县| 通城县| 武夷山市| 西宁市| 夹江县| 克什克腾旗| 定远县| 石泉县| 富锦市| 易门县| 海兴县| 将乐县| 新泰市| 绥滨县| 安阳县| 九龙县| 沙雅县| 平泉县| 连云港市| 咸宁市| 红原县|