jsp显示二维码

二维码打印

用jquery.qrcode.js打印

需引入jquery.jsjquery.qrcode.js

1.  div id="qrcode">

  //此处div显示二维码图片  

2.    

3.    

4.    

5.  $("#qrcode").qrcode({                            

6.                  text:"二维码内容",  

7.          size:100                            

8.  });  

用zxing打印

Spring mvc下面生成二维码显示在页面上,原理和生成验证码直接将流显示在页面上相同:

   

     com.google.zxing

     core

     3.2.0

   

   

     com.google.zxing

     javase

     3.2.0

   

 

 

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:

你可能感兴趣的:(常用技术)