Java 代码中random.nextInt()存在 中高风险问题,代码如下。求解答 5
publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletEx...
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);
int width = 80;
int height = 30;
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, 25));
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 code = request.getParameter("code");
String sRand = code;
for (int i = 0; i < sRand.length(); ++i)
{
String rand = sRand.substring(i, i + 1);
g.setColor(
new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110)));
g.drawString(rand, 14 * i + 5, 25);
}
g.dispose();
ServletOutputStream imageOut = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(imageOut);
encoder.encode(image); } 展开
throws ServletException, IOException
{
response.setContentType("image/jpeg");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "No-cache");
response.setDateHeader("Expires", 0L);
int width = 80;
int height = 30;
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, 25));
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 code = request.getParameter("code");
String sRand = code;
for (int i = 0; i < sRand.length(); ++i)
{
String rand = sRand.substring(i, i + 1);
g.setColor(
new Color(20 + random.nextInt(110), 20 + random
.nextInt(110), 20 + random.nextInt(110)));
g.drawString(rand, 14 * i + 5, 25);
}
g.dispose();
ServletOutputStream imageOut = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(imageOut);
encoder.encode(image); } 展开
1个回答
2015-08-29
展开全部
这代码就是执行的时间长一点
追问
别闹了。。。人家的安全监测软件都查出这个东西有问题。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询