当前位置:网站首页>OA system -- save the verification code to session
OA system -- save the verification code to session
2022-06-24 22:18:00 【Coke with chicken wings】
package com.bjsxt.controller;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.sql.rowset.serial.SerialException;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
@WebServlet("/codeServlet")
class CodeServlet extends HttpServlet{
@override
protected void service(HttpServletRequest req,HttpServletResponse resp)throws SerialException, IOException {
// Create images in memory
int width = 110,height = 30;
BufferedImage image = new BufferedImage(width,herght,BufferedImage,TYPE_INT_RGB);
// Get the image context
Graphics g = image.getGraphics();
// Set background color
g.setColor(getRandColor(fc:200,bc:250));
g.fillRect(x:0,y:0,width,height);
// set font
g.setFont(new Font(name:"Times New Roman", Font.PLAIN,size:20));
// Randomly generated 155 Interference lines , Make the authentication code in the image difficult to be detected by other software
g.setColor(getRandColor(fc:160,bc:200));
for(int i=0;i<155;i++){
int x = randdom.nextInt(width);
int y = randdom.nextInt(height);
int x1 = randdom.nextInt(12);
int y1 = randdom.nextInt(12);
g.drawLine(x,y,x2:x+x1,y2:y+y1);
}
// Randomly generated authentication code (6 Digit number )
String sRand = "";
for(int i = 0;i<6;i++){
String rand = String.valueOf(randm.nextInt(10));
sRand+=rand;
// Display the authentication code in the image
g.setColor(new Color(20 + random.nextInt(100),20 + rand.nexInt(110),20 + rand.nextInt(110)));
// Call the function out of the same color , Maybe because the seed table is close to , So we can only generate
g.drawString(rand,13 * i +6,16);
}
// Image generation
g.dispose();
try{
InmageIO.write(image,image,"JPEG",response.getOutputStream());
}catch(Exception e){
System.out.println(" Error in captcha image generation :"+e.toString());
}
// Save the verification code to Session
request.getSession().setAttribute("randStr",sRand);
}
}
边栏推荐
猜你喜欢

Want to be a test leader, do you know these 6 skills?
![[notes of Wu Enda] multivariable linear regression](/img/b1/60a702aaca58b0afa57ac2f552dabf.png)
[notes of Wu Enda] multivariable linear regression
![[notes of wuenda] fundamentals of machine learning](/img/71/6192a75446fa7f79469a5483ececc6.jpg)
[notes of wuenda] fundamentals of machine learning
![[200 opencv routines] 209 Color image segmentation in HSV color space](/img/fa/9a40015cbcf9c78808f147e510be4c.jpg)
[200 opencv routines] 209 Color image segmentation in HSV color space

YGG 近期游戏合作伙伴一览

一个女孩子居然做了十年硬件。。。

系统测试主要步骤

leetcode:45. 跳跃游戏 II【经典贪心】

降低pip到指定版本(通過PyCharm昇級pip,在降低到原來版本)

985测试工程师被吊打,学历和经验到底谁更重要?
随机推荐
Industrial development status of virtual human
socket(1)
学习笔记23--多传感器信息融合基础理论(上)
磁盤的結構
Process communication mode
leetcode1720_ 2021-10-14
[notes of Wu Enda] convolutional neural network
PostMan工具介绍及安装使用
Ideal L9, new trend of intelligent cockpit
树莓派初步使用
leetcode_ 191_ 2021-10-15
St Table + two points
[untitled]
EasyBypass
短视频商城系统,scroll-view如何自适应页面剩余高度
Minimum spanning tree based on Kruskal
Balanced binary search tree
Main steps of system test
Publicity of the second batch of shortlisted enterprises! Annual Top100 smart network supplier selection
You are using pip version 21.1.2; however, version 22.1.2 is available