package com;
import java.awt.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class PictureCheckCode extends HttpServlet {
private String ctmp = "";
public String getCtmp(){
return ctmp;
}
public PictureCheckCode() {
super();
}
public void destroy() {
super.destroy();
}
public void init() throws ServletException {
super.init();
}
// ��ȡ�����ɫ
public Color getRandColor(int s, int e) {
Random random = new Random();
if (s > 255) s = 255;
if (e > 255) e = 255;
int r = s + random.nextInt(e - s); //������RGB��ɫ�е�rֵ
int g = s + random.nextInt(e - s); //������RGB��ɫ�е�gֵ
int b = s + random.nextInt(e - s); //������RGB��ɫ�е�bֵ
return new Color(r, g, b);
}
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "No-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
int width = 86;
int height = 22;
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Graphics2D g2d = (Graphics2D) g;
Random random = new Random();
Font mFont = new Font("����", Font.BOLD, 17);
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);
g.setFont(mFont);
g.setColor(getRandColor(180, 200));
for (int i = 0; i < 100; i++) {
int x = random.nextInt(width - 1);
int y = random.nextInt(height - 1);
int x1 = random.nextInt(6) + 1;
int y1 = random.nextInt(12) + 1;
BasicStroke bs = new BasicStroke(2f, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL);
Line2D line = new Line2D.Double(x, y, x + x1, y + y1);
g2d.setStroke(bs);
g2d.draw(line);
}
String sRand = "";
// ���������֤����
int itmp = 0;
for (int i = 0; i < 4; i++) {
//random = new Random(new java.util.Date().getTime() + i);
switch (random.nextInt(4)) {
case 1:
itmp = random.nextInt(26) + 65; // ���A~Z����ĸ
ctmp = String.valueOf((char) itmp);
break;
case 2: // ��ɺ���
String[] rBase = { "0", "1", "2", "3", "4", "5", "6", "7", "8",
"9", "a", "b", "c", "d", "e", "f" };
// ��ɵ�1λ������
int r1 = random.nextInt(3) + 11; //���11��14֮��������
String str_r1 = rBase[r1];
// ��ɵ�2λ������
int r2;
if (r1 == 13) {
r2 = random.nextInt(7); //���0��7֮��������
} else {
r2 = random.nextInt(16); //���0��16֮��������
}
String str_r2 = rBase[r2];
// ��ɵ�1λ��λ��
int r3 = random.nextInt(6) + 10; //���10��16֮��������
String str_r3 = rBase[r3];
// ��ɵ�2λ��λ��
int r4;
if (r3 == 10) {
r4 = random.nextInt(15) + 1; //���1��16֮��������
} else if (r3 == 15) {
r4 = random.nextInt(15); //���0��15֮��������
} else {
r4 = random.nextInt(16); //���0��16֮��������
}
String str_r4 = rBase[r4];
System.out.println(str_r1 + str_r2 + str_r3 + str_r4);
// ����ɻ�����ת��Ϊ����
byte[] bytes = new byte[2];
//����ɵ����뱣�浽�ֽ�����ĵ�1��Ԫ����
String str_r12 = str_r1 + str_r2;
int tempLow = Integer.parseInt(str_r12, 16);
bytes[0] = (byte) tempLow;
//����ɵ�λ�뱣�浽�ֽ�����ĵ�2��Ԫ����
String str_r34 = str_r3 + str_r4;
int tempHigh = Integer.parseInt(str_r34, 16);
bytes[1] = (byte) tempHigh;
ctmp = new String(bytes); //����ֽ�������ɺ���
// System.out.println("��ɺ���:" + ctmp);
break;
default:
itmp = random.nextInt(10) + 48; // ���0~9������
ctmp = String.valueOf((char) itmp);
break;
}
sRand += ctmp;
HttpSession se=request.getSession();
se.setAttribute("sRand", sRand);
Color color = new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110));
g.setColor(color);
/** **����������ֲ���������תָ���Ƕ�* */
// ��������תָ���Ƕ�
Graphics2D g2d_word = (Graphics2D) g;
AffineTransform trans = new AffineTransform();
trans.rotate(random.nextInt(45) * 3.14 / 180, 15 * i + 8, 7);
// ��������
float scaleSize = random.nextFloat() +0.8f;
if (scaleSize > 1f) scaleSize = 1f;
trans.scale(scaleSize, scaleSize);
g2d_word.setTransform(trans);
/** ********************* */
g.drawString(ctmp, 15 * i + 18, 14);
}
// ����ɵ���֤�뱣�浽Session��
HttpSession session = request.getSession(true);
session.setAttribute("randCheckCode", sRand);
g.dispose();
ImageIO.write(image, "JPEG", response.getOutputStream());
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于javaweb的人事管理系统 (316个子文件)
PictureCheckCode.class 6KB
AlterDao.class 5KB
StaffDao.class 5KB
TrainRecordDao.class 4KB
AgreementDao.class 4KB
TrainGradeDao.class 4KB
FileDao.class 4KB
StaffCertDao.class 3KB
TrainGradeAddServlet.class 3KB
TrainRecord.class 3KB
TrainRecordUpdateServlet.class 3KB
TrainTypeDao.class 3KB
TrainGradeUpdateServlet.class 3KB
Staff.class 3KB
StaffCertUpdateServlet.class 3KB
AlterInputServlet.class 3KB
AgreementRegisterServlet.class 3KB
Alter.class 3KB
FileRegisterServlet.class 3KB
TrainRecordAddServlet.class 3KB
TrainTypeUpdateServlet.class 3KB
AlterUpdateServlet.class 3KB
StaffInfoServlet.class 3KB
StaffCertAddServlet.class 3KB
StaffUpdateServlet.class 3KB
StaffLoginServlet.class 3KB
AgreementUpdateServlet.class 3KB
StaffRegisterServlet.class 3KB
AgreementDeleteServlet.class 2KB
FileUpdateServlet.class 2KB
StaffDeleteServlet.class 2KB
FileDeleteServlet.class 2KB
Agreement.class 2KB
DeleteAlterServlet.class 2KB
File.class 2KB
TrainTypeAddServlet.class 2KB
StaffCertDeleteServlet.class 2KB
CertSelect.class 2KB
TrainGradeDeleteServlet.class 2KB
TrainGrade.class 2KB
TrainRecordDeleteServlet.class 2KB
CertSelectDao.class 2KB
TrainTypeDeleteServlet.class 2KB
StaffCertQueryAllServlet.class 2KB
TrainGradeQueryAllServlet.class 2KB
TrainRecordQueryAllServlet.class 2KB
AdminDao.class 2KB
StaffCert.class 2KB
StaffService.class 2KB
AgreementQueryAllServlet1.class 2KB
AgreementQueryAllServlet.class 2KB
AlterService.class 2KB
TrainRecordService.class 2KB
TrainTypeQueryAllServlet.class 2KB
StaffQueryAllServlet1.class 2KB
AlterQueryAllServlet1.class 2KB
StaffQueryAllServlet.class 2KB
AlterQueryAllServlet.class 2KB
TrainGradeService.class 2KB
FileQueryAllServlet1.class 2KB
FileQueryAllServlet.class 2KB
TrainTypeService.class 2KB
StaffCertService.class 2KB
AgreementService.class 2KB
Admin.class 2KB
ConnectionUtil.class 2KB
FileService.class 2KB
TrainType.class 1KB
AdminService.class 770B
.classpath 456B
org.eclipse.wst.jsdt.ui.superType.container 49B
css.css 16KB
style.css 11KB
head.css 6KB
control.css 5KB
common1.css 4KB
style0.css 1KB
style.css 862B
welcome.gif 164KB
logo.gif 40KB
success.gif 38KB
top03.gif 23KB
register_04.gif 22KB
register_08.gif 18KB
ico15.gif 8KB
ico14.gif 8KB
ico16.gif 8KB
register_03.gif 7KB
ico13.gif 7KB
pic05.gif 5KB
bu13.gif 4KB
bu10.gif 4KB
nav03.gif 4KB
nav01.gif 4KB
bu09.gif 4KB
bu07.gif 4KB
bu04.gif 4KB
bu05.gif 3KB
bu11.gif 3KB
bu06.gif 3KB
共 316 条
- 1
- 2
- 3
- 4
资源评论
筑梦学长ya
- 粉丝: 1827
- 资源: 21
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
- 车类型数据集6250张VOC+YOLO格式.zip
- The PyTorch implementation of STGCN.STGCN-main.zip
- 092300108.cpp
- 车类型数据集6000张VOC+YOLO格式.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功