protected void doGet(HttpServletRequest req, HttpServletResponse response)
throws IOException, ServletException {
// Expire response
try {
//
ByteArrayOutputStream imgOutputStream = new ByteArrayOutputStream();
byte[] captchaBytes;
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = image.createGraphics();
Hashtable<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
Random r = new Random();
String token = Long.toString(Math.abs(r.nextLong()), 36);
String ch = token.substring(0, 6);
Color c = new Color(0.6662f, 0.4569f, 0.3232f);
GradientPaint gp = new GradientPaint(30, 30, c, 15, 25,
Color.white, true);
graphics2D.setPaint(gp);
Font font = new Font("Verdana", Font.CENTER_BASELINE, 26);
graphics2D.setFont(font);
graphics2D.drawString(ch, 2, 22);
graphics2D.dispose();
HttpSession session = req.getSession(true);
session.setAttribute(CAPTCHA_KEY, ch);
OutputStream outputStream = response.getOutputStream();
ImageIO.write(image, "jpeg", imgOutputStream);
captchaBytes = imgOutputStream.toByteArray();
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Max-Age", 0);
response.setContentType("image/jpeg");
outputStream.write(captchaBytes);
outputStream.close();
utils.PQSoftLogger.getInstance().log(
"Captch servlet: " + image.toString());
} catch (Exception e) {
utils.PQSoftLogger.getInstance().log(
e.toString() + ":" + e.getMessage());
for (StackTraceElement s : e.getStackTrace()) {
utils.PQSoftLogger.getInstance().log(
s.getLineNumber() + ":" + s.getMethodName() + ":"
+ s.getFileName());
}
} finally {
utils.PQSoftLogger.getInstance().log("temp dir-"+System.getProperty("java.io.tmpdir"));
utils.PQSoftLogger.getInstance().log("Captch servlet executed");
}
}
다음과 같은 예외가 ImageIO.write
방법에 발생합니다 출력 스트림을 작성합니다.ImageIO에서 쓰기 방법 - javax의 ImageIO에서 사용해 IIOException 캔트 바람둥이 서버 환경에 서블릿을 호출하지만 로컬 시스템에 뜻을 작업 할 때
javax.imageio.IIOException: Can't create output stream!
몇 줄의 스택 추적이 있습니까? – haraldK