关闭

jsp显示二维码

标签: 二维码jsp
980人阅读 评论(0) 收藏 举报
分类:

二维码打印

用jquery.qrcode.js打印

需引入jquery.jsjquery.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"/>

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:5440次
    • 积分:221
    • 等级:
    • 排名:千里之外
    • 原创:12篇
    • 转载:32篇
    • 译文:0篇
    • 评论:0条