|
|
@@ -1,16 +1,15 @@
|
|
|
package com.uas.sso.util;
|
|
|
|
|
|
-import com.sun.image.codec.jpeg.JPEGCodec;
|
|
|
-import com.sun.image.codec.jpeg.JPEGImageEncoder;
|
|
|
-
|
|
|
-import javax.servlet.ServletException;
|
|
|
-import javax.servlet.ServletOutputStream;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-import java.awt.*;
|
|
|
+import java.awt.Color;
|
|
|
+import java.awt.Font;
|
|
|
+import java.awt.Graphics2D;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Random;
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
/**
|
|
|
* 图片验证码工具类
|
|
|
@@ -39,7 +38,7 @@ public class CaptchaUtil {
|
|
|
*/
|
|
|
private static String getRandomString()
|
|
|
{
|
|
|
- StringBuffer buffer = new StringBuffer();
|
|
|
+ StringBuilder buffer = new StringBuilder();
|
|
|
for(int i = 0; i < 4; i++)
|
|
|
{
|
|
|
buffer.append(CHARS[random.nextInt(CHARS.length)]);
|
|
|
@@ -69,11 +68,10 @@ public class CaptchaUtil {
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @param key 放到session中的key值
|
|
|
- * @throws ServletException
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
public static void outputCaptcha(HttpServletRequest request, HttpServletResponse response, String key)
|
|
|
- throws ServletException, IOException
|
|
|
+ throws IOException
|
|
|
{
|
|
|
|
|
|
response.setContentType("image/jpeg");
|
|
|
@@ -98,8 +96,7 @@ public class CaptchaUtil {
|
|
|
|
|
|
// 转成JPEG格式
|
|
|
ServletOutputStream out = response.getOutputStream();
|
|
|
- JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
|
|
|
- encoder.encode(bi);
|
|
|
+ ImageIO.write(bi, "jpeg", out);
|
|
|
out.flush();
|
|
|
}
|
|
|
}
|