package sunyang.vote.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
@SuppressWarnings("serial")
public class SafeCode extends HttpServlet {
public SafeCode() {
}
public void init() throws ServletException {
super.init();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("image/jpeg");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires", 0L);
HttpSession session = request.getSession();
int width = 60;
int height = 20;
BufferedImage image = new BufferedImage(width, height, 1);
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200, 250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Arial", 0, 19));
g.setColor(getRandColor(160, 200));
for (int i = 0; i < 155; i++) {
int x = random.nextInt(width + 100);
int y = random.nextInt(height + 100);
int xl = random.nextInt(10);
int yl = random.nextInt(12);
g.drawOval(x, y, x + xl, y + yl);
}
String sRand = "";
for (int i = 0; i < 4; i++) {
String rand = getRandChar(random.nextInt(36));
sRand = sRand + rand;
g.setColor(new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110)));
g.drawString(rand, 13 * i + 6, 16);
}
session.setAttribute("rand", sRand);
g.dispose();
javax.servlet.ServletOutputStream imageOut = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(imageOut);
encoder.encode(image);
}
public void destroy() {
}
private Color getRandColor(int fc, int bc) {
Random random = new Random();
if (fc > 255)
fc = 255;
if (bc > 255)
bc = 255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r, g, b);
}
private String getRandChar(int randNumber) {
return CHARARRAY[randNumber];
}
//private static final String CONTENT_TYPE = "image/jpeg";
private static final String CHARARRAY[] = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z" };
}
没有合适的资源?快使用搜索试试~ 我知道了~
struts2完整工程项目
共201个文件
java:55个
class:55个
xml:24个
5星 · 超过95%的资源 需积分: 10 162 下载量 20 浏览量
2011-04-20
14:18:03
上传
评论 5
收藏 9.96MB RAR 举报
温馨提示
<defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" /> <cache name="sampleCache1" maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="300" timeToLiveSeconds="600" overflowToDisk="true" /> <cache name="sampleCache2" maxElementsInMemory="1000" eternal="true" timeToIdleSeconds="0" timeToLiveSeconds="0" overflowToDisk="false" />
资源推荐
资源详情
资源评论
收起资源包目录
struts2完整工程项目 (201个子文件)
SafeCode.class 4KB
VoteDaoImpl.class 3KB
VoteRoot.class 3KB
ShowVotingResult.class 3KB
VoteContextRoot.class 3KB
Login.class 3KB
VotecontextDaoImpl.class 3KB
AdminDaoImpl.class 3KB
SearchVote.class 2KB
NewVote.class 2KB
FindVote.class 2KB
ShowVote.class 2KB
AdminRoot.class 2KB
VoteServiceImpl.class 2KB
UpdateVoteContext.class 2KB
VoteContextServiceImpl.class 2KB
AdminServiceImpl.class 2KB
NewVoteContext.class 2KB
ShowVotingContext.class 2KB
DelVoteContext.class 2KB
Vote.class 2KB
Createadmin.class 2KB
VoteInfo.class 2KB
VoterDaoImpl.class 2KB
ChangePwd.class 2KB
Voting.class 1KB
CheckVoter.class 1KB
UpdateVote.class 1KB
Votecontext.class 1KB
AddVoter.class 1KB
Admin.class 1KB
ShowVoting.class 1KB
SessionInterceptor.class 1KB
AddOneVoteContext.class 1KB
FindOneVote.class 1KB
Voter.class 1KB
VoterServiceImpl.class 1KB
VotingInfo.class 1KB
ChangePwdValidate.class 1003B
CreateAdminValidate.class 997B
LoginValidate.class 985B
Count.class 967B
VoterRoot.class 904B
Locales.class 891B
NewvoteValidate.class 883B
Logout.class 821B
VoteService.class 722B
VoteDao.class 710B
VoteContextService.class 638B
VoteContextDao.class 626B
SearchVoteValidate.class 615B
AdminService.class 571B
AdminDao.class 559B
VoterService.class 271B
VoterDao.class 259B
.classpath 2KB
spring.jar 2.43MB
struts2-core-2.0.11.jar 2.22MB
hibernate3.jar 2.08MB
freemarker-2.3.8.jar 784KB
commons-collections.jar 546KB
c3p0-0.9.0.4.jar 479KB
mysql-connector-java-3.1.14-bin.jar 448KB
xwork-2.0.4.jar 445KB
antlr-2.7.6.jar 433KB
log4j-1.2.13.jar 350KB
cglib-nodep-2.1_3.jar 317KB
dom4j-1.6.1.jar 307KB
ognl-2.6.11.jar 164KB
commons-logging-1.0.4.jar 37KB
jta.jar 9KB
struts2-spring-plugin-2.0.8.jar 8KB
SafeCode.java 3KB
VoteRoot.java 2KB
VoteContextRoot.java 2KB
VoteDaoImpl.java 2KB
ShowVotingResult.java 2KB
Login.java 2KB
VotecontextDaoImpl.java 2KB
AdminRoot.java 2KB
AdminDaoImpl.java 2KB
SearchVote.java 2KB
FindVote.java 1KB
VoteInfo.java 1KB
Vote.java 1KB
VoteContextServiceImpl.java 1KB
NewVote.java 1KB
VoteContextDao.java 1KB
VoteDao.java 1KB
ShowVote.java 1KB
AdminService.java 1KB
AdminDao.java 1KB
UpdateVoteContext.java 1KB
NewVoteContext.java 1KB
ShowVotingContext.java 1KB
VoteServiceImpl.java 1KB
AdminServiceImpl.java 1KB
Createadmin.java 1004B
DelVoteContext.java 990B
Votecontext.java 990B
共 201 条
- 1
- 2
- 3
qqzj-ztq
- 粉丝: 0
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页