1、代码
<%@page import="erwebma.AddCode"%> <%@page import="javax.imageio.ImageIO"%> <%@page import="java.awt.image.BufferedImage"%> <%@page import="erwebma.client.j2se.MatrixToImageWriter"%> <%@page import="com.google.zxing.common.BitMatrix"%> <%@page import="com.google.zxing.MultiFormatWriter"%> <%@page import="com.google.zxing.BarcodeFormat"%> <%@page import="com.google.zxing.EncodeHintType"%> <%@page import="java.util.Hashtable"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <% String data = request.getParameter("data"); if (data != null) { int width = 128; int height = 128; String format = "png"; Hashtable hints = new Hashtable(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); BitMatrix bitMatrix = new MultiFormatWriter().encode(data, BarcodeFormat.QR_CODE, width, height, hints); BufferedImage bufi = MatrixToImageWriter.toBufferedImage(bitMatrix); response.reset(); response.setContentType("image/png"); ImageIO.write(bufi, "png", response.getOutputStream()); out.clear(); out = pageContext.pushBody(); } %>
2、换行
换行,用“%0A”。
3、二维码图片
原文地址:http://blog.csdn.net/class_horse/article/details/45482417