网贷有哪些容易借钱吗

JAVA Web Servlet生成验证码 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 21时,
有两个不同版本的代码。第二个代码块为优化后的。都可直接拿来使用。URL地址如:http://localhost:8080/exam/safecode
代码片段(2)
1.&[代码]初始粗糙代码&&&&
import java.awt.C
import java.awt.F
import java.awt.Graphics2D;
import java.awt.image.BufferedI
import java.io.IOE
import java.util.R
import javax.servlet.ServletE
import javax.servlet.ServletOutputS
import javax.servlet.annotation.WebS
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import com.sun.image.codec.jpeg.*;
* 验证码图片生成Servlet类,直接调用该Servlet即可使用
* 取值的时候调用session.getAttribute("code")得到生成的值
* @author &a href="mailto:"&Ajunboys&/a&
@WebServlet("/safecode")
public class SafeCodeImageServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private Color getRandColor(int fc, int bc) {// 给定范围获得随机颜色
Random random = new Random();
if (fc & 255)
if (fc & 0)
if (bc & 255)
if (bc & 0)
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);
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// 设置输出
response.setContentType("image/jpeg");
int width = 80;
int height = 30;
// 产生随机数
Random r = new Random();
// 把随机数绘制成图像
BufferedImage imgbuf = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);// 产生缓冲图像,80宽30高
Graphics2D g = imgbuf.createGraphics();// 取得缓冲的绘制环境
// 开始绘制
g.setColor(getRandColor(200, 250));// 设定背景色
g.fillRect(0, 0, width, height);// 矩形图
// 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
g.setColor(getRandColor(160, 200));
for (int i = 0; i & 155; i++) {
int x = r.nextInt(width);
int y = r.nextInt(height);
int xl = r.nextInt(12);
int yl = r.nextInt(12);
g.drawLine(x, y, x + xl, y + yl);
g.setColor(getRandColor(120, 240));
// 随机产生100个干扰点,使图像中的验证码不易被其他分析程序探测到
for (int i = 0; i & 100; i++) {
int x = r.nextInt(width);
int y = r.nextInt(height);
g.drawOval(x, y, 0, 0);
g.setFont(new Font("Times New Roman", Font.PLAIN, 26));
String scode = "";
for (int i = 0; i & 4; i++) {
String rand = String.valueOf(r.nextInt(10));
String rand = randomCode();
g.setColor(new Color(20 + r.nextInt(110), 20 + r.nextInt(110),
20 + r.nextInt(110)));
// 调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成
g.drawString(rand+" ", (0==i) ? 12 : (12 * (i+1)+5), 23);
request.getSession().setAttribute("safecode", scode);
// 输出图像
ServletOutputStream out = response.getOutputStream();// 得到HTTP的流
// JPEGCodec.createJPEGEncoder(out);转码
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);// 产生JPEG的图像加码器
encoder.encode(imgbuf);
out.flush();
private static String randomCode(){
char[] dictionary = {
'2','3','4','5','6','7','8','9'
,'a','b','c','d','e','f','g','h','i','j'
,'k','m','n','p','q','r','s','t'
,'u','v','w','x','y','z'
,'A','B','C','D','E','F','G','H','J'
,'K','L','M','N','P','Q','R','S','T'
,'U','V','W','X','Y','Z'
/*'1','l','0','O','o','#','@','$','%','&','(',')','|','/','*'//暂时不用特殊字符(包括:数字1,0;字母:l,o,O)
,'^','!','~','\\'*/
StringBuffer code = new StringBuffer();
Random r = new Random();
code.append(dictionary[r.nextInt(dictionary.length)]);
return code.toString();
2.&[代码]优化后的全代码&&&&
import java.awt.C
import java.awt.F
import java.awt.Graphics2D;
import java.awt.image.BufferedI
import java.io.IOE
import java.util.R
import javax.servlet.ServletE
import javax.servlet.ServletOutputS
import javax.servlet.annotation.WebS
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import com.sun.image.codec.jpeg.JPEGC
import com.sun.image.codec.jpeg.JPEGImageE
* 验证码图片生成Servlet类,直接调用该Servlet即可使用
* 取值的时候调用session.getAttribute("code")得到生成的值
* @author &a href="mailto:"&Ajunboys&/a&
@WebServlet("/safecode")
public class SafeCodeImageServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
static final char[] dictionary = {
'2','3','4','5','6','7','8','9'
,'a','b','c','d','e','f','g','h','i','j'
,'k','m','n','p','q','r','s','t'
,'u','v','w','x','y','z'
,'A','B','C','D','E','F','G','H','J'
,'K','L','M','N','P','Q','R','S','T'
,'U','V','W','X','Y','Z'
/*'1','l','0','O','o','#','@','$','%','&','(',')','|','/','*'//暂时不用特殊字符(包括:数字1,0;字母:l,o,O)
,'^','!','~','\\'*/
static Random random = new Random();
* 产生n[4,4+]个随机数
* @param n
static String getRandomString(int n){
StringBuffer buffer = new StringBuffer();
if (n & 4) {
for (int i = 0; i & i++) {
buffer.append(dictionary[random.nextInt(dictionary.length)]);
return buffer.toString();
* 随机颜色
static Color getRandomColor(){
return new Color(random.nextInt(255), random.nextInt(255), random.nextInt(255));
* 颜色反色
* @param c
static Color getReverseColor(Color c){
return new Color(255 - c.getRed(), 255 - c.getGreen(), 255 - c.getBlue());
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("image/jpeg");
String randomString = getRandomString(6);
request.getSession(true).setAttribute("code", randomString);
int width = 100; //验证码图片宽度
int height = 30; //验证码图片高度
Color color = getRandomColor();
Color reverse = getReverseColor(color);
//创建一个彩图
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
//绘图对象
Graphics2D g = bi.createGraphics();
g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 16));
g.setColor(color);
g.fillRect(0, 0, width, height);
g.setColor(reverse);
g.drawString(randomString, 18, 20);
//绘制最多100个噪音点
for (int i = 0, n = random.nextInt(100); i & i++) {
g.drawRect(random.nextInt(width), random.nextInt(height), 1, 1);
ServletOutputStream out = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(bi);
out.flush();
out.close();
开源中国-程序员在线工具:
相关的代码(182)
1回/2810阅
com.sun的包就知道是复制别人的代码的了
2楼:OSC小红薯 发表于
引用来自“NestleCaau”的评论一看到有
com.sun的包就知道是复制别人的代码的了你确定你是搞java开发的? sun公司提供的jdk/jre中的rt.jar包 笑死人了。
3楼:高跟男爵 发表于
我一般不懂 &是不发表技术方面的评论&&&& & 因为容易脸红&&&
4楼:hanzhankang 发表于
这个效率高吗?我以前也是这样设计的,但是运行过程中,偶尔会出现了空指针异常。思索着验证码系统,腾讯是专门用一个服务器生产的,我就想者能否开发一个验证码生成池,这样效率也就高了,系统压力也小一些。&&
5楼:OSC小红薯 发表于
引用来自“hanzhankang”的评论这个效率高吗?我以前也是这样设计的,但是运行过程中,偶尔会出现了空指针异常。思索着验证码系统,腾讯是专门用一个服务器生产的,我就想者能否开发一个验证码生成池,这样效率也就高了,系统压力也小一些。&&当然,如果并发量过大,肯定需要分布式来处理业务的。
6楼: 发表于
推荐技术网:
7楼:NestleCaau 发表于
引用来自“Ajunboys”的评论引用来自“NestleCaau”的评论一看到有
com.sun的包就知道是复制别人的代码的了你确定你是搞java开发的? sun公司提供的jdk/jre中的rt.jar包 笑死人了。最近我也是在看这个,自己思考做的不会用sun的,因为sun的有可能在jre里弃置,这些sun的都被看成是旧代码,早就有ImageIO了
8楼:anjero 发表于
// 设置不缓存图片
response.setHeader(&Pragma&, &No-cache&);
response.setHeader(&Cache-Control&, &No-cache&);
response.setDateHeader(&Expires&, 0);
// 指定生成的相应图片
response.setContentType(&image/jpeg&);
IdentifyingCode idCode = new IdentifyingCode();
BufferedImage image = new BufferedImage(idCode.getWidth(), idCode.getHeight(), BufferedImage.TYPE_INT_BGR);
Graphics2D g = image.createGraphics();
// 定义字体样式
Font myFont = new Font(&黑体&, Font.BOLD, 22);
// 设置字体
g.setFont(myFont);
g.setColor(idCode.getRandomColor(200, 250));
// 绘制背景
g.fillRect(0, 0, idCode.getWidth(), idCode.getHeight());
g.setColor(idCode.getRandomColor(180, 200));
idCode.drawRandomLines(g, 50);
String idcode = idCode.drawRandomString(4, g);
request.getSession().setAttribute(SESSION_CODE, idcode);
g.dispose();
ImageIO.write(image, &JPEG&, response.getOutputStream());
开源从代码分享开始
OSC小红薯的其它代码java ZXing生成二维码及条码实例分享
作者:丶默默
字体:[ ] 类型:转载 时间:
本文分享了java ZXing生成二维码及条码的实例代码,具有很好的参考价值,需要的朋友一起来看下吧
1、jar包:&& ZXing-core-3.3.0.jar   
     &&ZXing-javase-3.3.0.jar &
BufferedImageLuminanceSource.java
package com.webos.
import java.awt.Graphics2D;
import java.awt.geom.AffineT
import java.awt.image.BufferedI
import com.google.zxing.LuminanceS
public class BufferedImageLuminanceSource extends LuminanceSource {
private final BufferedI
public BufferedImageLuminanceSource(BufferedImage image) {
this(image, 0, 0, image.getWidth(), image.getHeight());
public BufferedImageLuminanceSource(BufferedImage image, int left, int top, int width, int height) {
super(width, height);
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();
if (left + width & sourceWidth || top + height & sourceHeight) {
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
for (int y = y & top + y++) {
for (int x = x & left + x++) {
if ((image.getRGB(x, y) & 0xFF000000) == 0) {
image.setRGB(x, y, 0xFFFFFFFF); // = white
this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY);
this.image.getGraphics().drawImage(image, 0, 0, null);
this.left =
this.top =
public byte[] getRow(int y, byte[] row) {
if (y & 0 || y &= getHeight()) {
throw new IllegalArgumentException("Requested row is outside the image: " + y);
int width = getWidth();
if (row == null || row.length & width) {
row = new byte[width];
image.getRaster().getDataElements(left, top + y, width, 1, row);
public byte[] getMatrix() {
int width = getWidth();
int height = getHeight();
int area = width *
byte[] matrix = new byte[area];
image.getRaster().getDataElements(left, top, width, height, matrix);
public boolean isCropSupported() {
public LuminanceSource crop(int left, int top, int width, int height) {
return new BufferedImageLuminanceSource(image, this.left + left, this.top + top, width, height);
public boolean isRotateSupported() {
public LuminanceSource rotateCounterClockwise() {
int sourceWidth = image.getWidth();
int sourceHeight = image.getHeight();
AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth);
BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY);
Graphics2D g = rotatedImage.createGraphics();
g.drawImage(image, transform, null);
g.dispose();
int width = getWidth();
return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width);
QRCodeUtil.java
package com.webos.
import java.awt.BasicS
import java.awt.G
import java.awt.Graphics2D;
import java.awt.I
import java.awt.S
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedI
import java.io.F
import java.io.OutputS
import java.util.H
import java.util.R
import javax.imageio.ImageIO;
import com.google.zxing.BarcodeF
import com.google.zxing.BinaryB
import com.google.zxing.DecodeHintT
import com.google.zxing.EncodeHintT
import com.google.zxing.MultiFormatR
import com.google.zxing.MultiFormatW
import com.mon.BitM
import com.mon.HybridB
import com.google.zxing.qrcode.decoder.ErrorCorrectionL
* @ClassName: QRCodeUtil
* @Description: 二维码编码
* @author Liuy
* @date 日 下午3:03:24
public class QRCodeUtil {
// 设置二维码编码格式
private static final String CHARSET = "utf-8";
// 保存的二维码格式
private static final String FORMAT_NAME = "JPG";
// 二维码尺寸
private static final int QRCODE_SIZE = 800;
// LOGO宽度
private static final int LOGO_WIDTH = 80;
// LOGO高度
private static final int LOGO_HEIGHT = 80;
* @Title: createImage
* @Description: 将二维码内容创建到Image流
* @param content 二维码内容
* @param imgPath logo图片地址
* @param needCompress 是否压缩logo图片大小
* @throws Exception 参数说明
* @return BufferedImage 返回类型
private static BufferedImage createImage(String content, String logoPath, boolean needCompress) throws Exception {
Hashtable&EncodeHintType, Object& hints = new Hashtable&EncodeHintType, Object&();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x & x++) {
for (int y = 0; y & y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
if (logoPath == null || "".equals(logoPath)) {
// 插入logo
QRCodeUtil.insertImage(image, logoPath, needCompress);
* @Title: insertImage
* @Description: 将logo插入到二维码中
* @param source 二维码Image流
* @param imgPath logo地址
* @param needCompress 是否压缩大小
* @throws Exception 参数说明
* @return void 返回类型
private static void insertImage(BufferedImage source, String logoPath, boolean needCompress) throws Exception {
File file = new File(logoPath);
if (!file.exists()) {
System.err.println("" + logoPath + " 该文件不存在!");
Image src = ImageIO.read(new File(logoPath));
int width = src.getWidth(null);
int height = src.getHeight(null);
if (needCompress) { // 压缩LOGO
if (width & LOGO_WIDTH) {
width = LOGO_WIDTH;
if (height & LOGO_HEIGHT) {
height = LOGO_HEIGHT;
Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH);
BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = tag.getGraphics();
g.drawImage(image, 0, 0, null); // 绘制缩小后的图
g.dispose();
// 插入LOGO
Graphics2D graph = source.createGraphics();
int x = (QRCODE_SIZE - width) / 2;
int y = (QRCODE_SIZE - height) / 2;
graph.drawImage(src, x, y, width, height, null);
Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
graph.setStroke(new BasicStroke(3f));
graph.draw(shape);
graph.dispose();
* @Title: mkdirs
* @Description: 创建文件夹
* @param destPath 文件夹地址
* @return void 返回类型
private static boolean mkdirs(String destPath) {
File file = new File(destPath);
// 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
if (!file.exists() && !file.isDirectory()) {
file.mkdirs();
* @Title: encode
* @Description: 生成二维码
* @param content 二维码内容
* @param imgPath logo图片地址
* @param destPath 目标保存地址
* @param needCompress 是否压缩logo图片大小
* @throws Exception 参数说明
* @return void 返回类型
private static void encode(String content, String logoPath, String destPath, boolean needCompress) throws Exception {
BufferedImage image = QRCodeUtil.createImage(content, logoPath, needCompress);
if (mkdirs(destPath)) {
String file = new Random().nextInt() + ".jpg";
ImageIO.write(image, FORMAT_NAME, new File(destPath + "/" + file));
* @Title: encode
* @Description: 生成二维码
* @param content 二维码内容
* @param destPath 目标保存地址
* @throws Exception 参数说明
* @return void 返回类型
public static void encode(String content, String destPath) throws Exception {
QRCodeUtil.encode(content, null, destPath, false);
* @Title: encode
* @Description: 生成二维码
* @param content 二维码内容
* @param imgPath logo图片地址
* @param output 输出流
* @param needCompress 是否压缩logo图片大小
* @throws Exception 参数说明
* @return void 返回类型
public static void encode(String content, String logoPath, OutputStream output, boolean needCompress) throws Exception {
BufferedImage image = QRCodeUtil.createImage(content, logoPath, needCompress);
ImageIO.write(image, FORMAT_NAME, output);
* @Title: encode
* @Description: 生成二维码
* @param content 二维码内容
* @param output 输出流
* @throws Exception 参数说明
* @return void 返回类型
public static void encode(String content, OutputStream output) throws Exception {
QRCodeUtil.encode(content, null, output, false);
* @Title: decode
* @Description: 对二维码解码
* @param file 文件对象
* @return 解码后的二维码内容字符串
* @throws Exception 参数说明
* @return String 返回类型
private static String decode(File file) throws Exception {
image = ImageIO.read(file);
if (image == null) {
BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Hashtable&DecodeHintType, String& hints = new Hashtable&DecodeHintType, String&();
hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
return new MultiFormatReader().decode(bitmap, hints).getText();
* @Title: decode
* @Description: 对二维码解码
* @param path 文件路径
* @throws Exception 参数说明
* @return String 返回类型
public static String decode(String path) throws Exception {
return QRCodeUtil.decode(new File(path));
QRCodeServlet.java
package com.webos.
import java.io.IOE
import javax.servlet.ServletE
import javax.servlet.annotation.WebS
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import com.webos.util.QRCodeU
* Servlet implementation class QRCodeServlet
@WebServlet("/QRCodeServlet")
public class QRCodeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
* @see HttpServlet#HttpServlet()
public QRCodeServlet() {
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String text = "?timestamp=" + System.currentTimeMillis();
QRCodeUtil.encode(text, response.getOutputStream());
} catch (Exception e) {
e.printStackTrace();
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持脚本之家!
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具java开发微信二维码
要用到一个jar包QRcode.jar
主要用到了com.swetake.util.Qrcode这个类。API链接如下:
以本人博客首页为例:
代码如下:(生成一个固定内容的二维码以图片形式输出到文件中)
CreateTwoBarImage.java(一个普通的java类)
package com.
import java.awt.C
import java.awt.Graphics2D;
import java.awt.image.BufferedI
import java.io.F
import javax.imageio.ImageIO;
import com.swetake.util.Q
public class CreateTwoBarImage {
public void creatTxm(String param) throws Exception {
Qrcode qrcode = new Qrcode();
qrcode.setQrcodeErrorCorrect('M');
qrcode.setQrcodeEncodeMode('B');
qrcode.setQrcodeVersion(7);
byte[] bstr = param.getBytes("UTF-8");
BufferedImage bi = new BufferedImage(139, 139,
BufferedImage.TYPE_INT_RGB);
Graphics2D g = bi.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, 139, 139);
g.setColor(Color.BLACK);
if (bstr.length & 0 && bstr.length & 123) {
boolean[][] b = qrcode.calQrcode(bstr);
for (int i = 0; i & b. i++) {
for (int j = 0; j & b. j++) {
if (b[j][i]) {
g.fillRect(j * 3 + 2, i * 3 + 2, 3, 3);
g.dispose();
bi.flush();
String FilePath = "F:/私人物品刘梦冰/学习资料/exercise/" + param + ".jpg";
File f = new File(FilePath);
ImageIO.write(bi, "jpg", f);
public static void main(String args[]) {
new CreateTwoBarImage().creatTxm("lmb");
} catch (Exception e) {
e.printStackTrace();
运行结果:
扫码之后显示的就是一个字符串“lmb”,如果我们想通过扫码访问一个网址,该怎么改进呢?
代码如下:(生成二维码显示到网页上)
PrintTwoBarCodeServlet、qrcode.jsp
PrintTwoBarCodeServlet.java
package com.
import java.awt.C
import java.awt.Graphics2D;
import java.awt.image.BufferedI
import java.io.IOE
import java.io.PrintW
import javax.imageio.ImageIO;
import javax.servlet.ServletE
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import com.swetake.util.Q
public class PrintTwoBarCodeServlet extends HttpServlet {
* 专门用来生成二维码图片的servlet
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doPost(req, resp);
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String code = request.getParameter("code");
Qrcode testQrcode = new Qrcode();
testQrcode.setQrcodeErrorCorrect('M');
testQrcode.setQrcodeEncodeMode('B');
testQrcode.setQrcodeVersion(7);
byte[] d = code.getBytes("gbk");
BufferedImage image = new BufferedImage(98, 98,
BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g = image.createGraphics();
g.setBackground(Color.WHITE);
g.clearRect(0, 0, 98, 98);
g.setColor(Color.BLACK);
if (d.length & 0 && d.length & 120) {
boolean[][] s = testQrcode.calQrcode(d);
for (int i = 0; i & s. i++) {
for (int j = 0; j & s. j++) {
if (s[j][i]) {
g.fillRect(j * 2 + 3, i * 2 + 3, 2, 2);
g.dispose();
image.flush();
ImageIO.write(image, "jpg", response.getOutputStream());
qrcode.jsp
language="java" import="java.util.*" pageEncoding="utf-8"%&
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
&!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&
&显示页面&
http-equiv="pragma" content="no-cache"&
http-equiv="cache-control" content="no-cache"&
http-equiv="expires" content="0"&
http-equiv="keywords" content="keyword1,keyword2,keyword3"&
http-equiv="description" content="This is my page"&
type="text/css"&
.box{width:400px;height:300px;margin:0 auto;
border:1px solid #39b2e2;text-align:center;
color:red;}
class="box"&
&扫一扫开启爱的密码&
src="printTwoBarCode.do?code=http://blog.csdn.net/lmb55"&
生成的二维码:
扫一扫的显示:
看过本文的人也看了:
我要留言技术领域:
取消收藏确定要取消收藏吗?
删除图谱提示你保存在该图谱下的知识内容也会被删除,建议你先将内容移到其他图谱中。你确定要删除知识图谱及其内容吗?
删除节点提示无法删除该知识节点,因该节点下仍保存有相关知识内容!
删除节点提示你确定要删除该知识节点吗?

我要回帖

 

随机推荐