二维码打印
用jquery.qrcode.js打印
需引入jquery.js和jquery.qrcode.js
1. div id="qrcode"></div> //此处div显示二维码图片
2.
3.
4.
5. $("#qrcode").qrcode({
6. text:"二维码内容",
7. size:100
8. });
用zxing打印
Spring mvc下面生成二维码显示在页面上,原理和生成验证码直接将流显示在页面上相同:
<!-- 二维码-->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.2.0</version>
</dependency>
public voidimage(HttpServletResponse resp, String id)throws IOException{
Stringurl = "要生成二维码的地址"+id;
if (url != null&& !"".equals(url)) {
ServletOutputStream stream = null;
try{
intwidth = 200;//图片的宽度
intheight = 200;//高度
stream= resp.getOutputStream();
QRCodeWriter writer = newQRCodeWriter();
BitMatrix m = writer.encode(url, BarcodeFormat.QR_CODE,height, width);
MatrixToImageWriter.writeToStream(m, "png",stream);
} catch(WriterException e) {
e.printStackTrace();
} finally{
if(stream != null){
stream.flush();
stream.close();
}
}
}
}
Jsp:<img alt="" src="/home/image.action"/>