struts2返回登陆验证码
来源:互联网 发布:excel表格找出相同数据 编辑:程序博客网 时间:2024/06/05 07:57
[1].[代码] 验证码跳至[1]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
public
final
class
ImageUtil {
private
static
final
String[] chars = {
"0"
,
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
,
"7"
,
"8"
,
"9"
,
"A"
,
"B"
,
"C"
,
"D"
,
"E"
,
"F"
,
"H"
,
"M"
,
"N"
,
"X"
,
"Y"
,
"W"
,
"T"
};
private
static
final
int
SIZE =
4
;
private
static
final
int
LINES =
6
;
private
static
final
int
WIDTH =
100
;
private
static
final
int
HEIGHT =
30
;
private
static
final
int
FONT_SIZE =
20
;
public
static
Map<String,BufferedImage> getImage() {
StringBuffer sb =
new
StringBuffer();
BufferedImage image =
new
BufferedImage(WIDTH, HEIGHT,
BufferedImage.TYPE_INT_RGB);
Graphics graphic = image.getGraphics();
graphic.setColor(Color.LIGHT_GRAY);
graphic.fillRect(
0
,
0
, WIDTH, HEIGHT);
Random ran =
new
Random();
for
(
int
i=
1
;i<=SIZE;i++){
int
r = ran.nextInt(chars.length);
graphic.setColor(getRandomColor());
graphic.setFont(
new
Font(
null
,Font.BOLD+Font.ITALIC,FONT_SIZE));
graphic.drawString(chars[r],(i-
1
)*WIDTH/SIZE , HEIGHT/
2
);
sb.append(chars[r]);
}
for
(
int
i=
1
;i<=LINES;i++){
graphic.setColor(getRandomColor());
graphic.drawLine(ran.nextInt(WIDTH), ran.nextInt(HEIGHT), ran.nextInt(WIDTH),ran.nextInt(HEIGHT));
}
Map<String,BufferedImage> map =
new
HashMap<String,BufferedImage>();
map.put(sb.toString(), image);
return
map;
}
public
static
Color getRandomColor(){
Random ran =
new
Random();
Color color =
new
Color(ran.nextInt(
256
),ran.nextInt(
256
),ran.nextInt(
256
));
return
color;
}
--------------------------------------------------
public
class
ImageAction
extends
BaseAction{
private
InputStream imageStream;
public
String execute(){
Map<String,BufferedImage> map =
ImageUtil.getImage();
String code =
map.keySet().iterator().next();
session.put(
"code"
, code);
BufferedImage image = map.get(code);
ByteArrayOutputStream bos =
new
ByteArrayOutputStream();
JPEGImageEncoder encoder =
JPEGCodec.createJPEGEncoder(bos);
try
{
encoder.encode(image);
byte
[] bytes = bos.toByteArray();
imageStream =
new
ByteArrayInputStream(bytes);
return
"success"
;
}
catch
(Exception e) {
e.printStackTrace();
return
"f"
;
}
}
public
InputStream getImageStream() {
return
imageStream;
}
public
void
setImageStream(InputStream imageStream) {
this
.imageStream = imageStream;
}
-------------------------------------------------------
public
class
BaseAction
implements
SessionAware{
protected
Map<String,Object> session;
public
void
setSession(Map<String, Object> session) {
this
.session = session;
}
}
0 0
- struts2返回登陆验证码
- Struts2返回验证码
- 登陆验证码(struts2实现)
- Struts2 实现验证码 登陆
- 登陆验证码(struts2实现)
- struts2验证码登陆实现
- struts2实现验证码登陆
- struts2 实战 登陆验证
- struts2过滤器验证登陆状态
- Struts2:自定义返回视图类型-返回图形验证码
- 如何在struts2中实现登陆的验证码功能
- 如何在struts2中实现登陆的验证码功能
- Struts2连接数据库实现登陆(验证码)、注册
- struts2 验证 json 返回 fielderrors
- struts2拦截器验证登陆状态
- Struts2使用过滤器验证登陆状态
- Hibernate+Struts2+Ajax实现用户登陆验证
- Struts2使用过滤器验证登陆状态
- 百 度 失 效 连 接
- 数塔问题
- 编译c文件出现的小bug--错误:程序中有游离的'\302'
- 认识Mock
- layout_centerHorizontal、layout_gravity、gravity的区别
- struts2返回登陆验证码
- 20140715 「博弈 - Nim(尼姆)博弈」 HDOJ 2509 Be the Winner
- 图像锐化(增强)和边缘检测
- 12.6.1 栈轨迹
- https详解和SSL详解
- 树莓派选购
- PetShop项目总结
- 程序员”脑筋急转弯”
- 12.6.2 重新抛出异常