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
| <%@page import="javax.imageio.ImageIO"%> <%@page import="java.awt.image.BufferedImage"%> <%@ page import="java.awt.*" %> <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page contentType="image/jpeg; charset=UTF-8" language="java"%>
<%! public Color getColor(){ Random ran = new Random(); int r = ran.nextInt(256); int g = ran.nextInt(256); int b = ran.nextInt(256); return new Color(r,g,b); } public String getNum(){ int ran = (int)(Math.random()*9000)+1000; return String.valueOf(ran); } %> <%
response.setHeader("Prama", "no-cache"); response.setHeader("Cache-control", "no-cache"); response.setHeader("Expires", "0"); BufferedImage image = new BufferedImage(80,30,BufferedImage.TYPE_INT_BGR); Graphics graphics = image.getGraphics(); graphics.fillRect(0, 0, 80, 30); for(int i = 0;i < 60;i++){ Random ran = new Random(); int xBegin = ran.nextInt(80); int yBegin = ran.nextInt(30); int xEnd = ran.nextInt(xBegin + 10); int yEnd = ran.nextInt(yBegin + 10); graphics.setColor(getColor()); graphics.drawLine(xBegin, yBegin, xEnd, yEnd); } graphics.setFont(new Font("seif",Font.BOLD,20)); graphics.setColor(Color.BLACK); String checkCode = getNum(); StringBuffer sb = new StringBuffer(); for(int i = 0;i < checkCode.length();i++){ sb.append(checkCode.charAt(i)+" "); } graphics.drawString(sb.toString(), 15, 20); session.setAttribute("CKECKCODE",checkCode); ImageIO.write(image, "jpeg", response.getOutputStream()); out.clear(); out = pageContext.pushBody(); %>
|