jquery-qrcode生成二维码

  本文是学习慕课网课程《Java生成二维码》(http://www.imooc.com/learn/531)的笔记。javascript

  1、下载jquery-qrode文件html

    下载网址:https://github.com/jeromeetienne/jquery-qrcodejava

  2、jquery-qrode生成二维码jquery

    首先,将下载好的压缩包解压到指定文件夹,解压后建议使用jquery.qrcode.min.js(压缩过的),减小占用大小,加快访问速度。git

    而后在新建的web项目webroot下新增文件夹js,将jquery.qrcode.min.js文件放在里面,以及使用jquery时须要的jquery.min.js文件也放在此目录下。github

    建立qrcode.jsp,在头部导入两个js文件web

    具体代码以下:浏览器

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%
 3 String path = request.getContextPath();  4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  5 %>
 6 
 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 8 <html>
 9   <head>
10       <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
11     <title>生成二维码</title>
12     <script type="text/javascript" src="<%= request.getContextPath() %>/js/jquery-3.3.1.min.js"></script>
13     <script type="text/javascript" src="<%= request.getContextPath() %>/js/jquery.qrcode.min.js"></script>
14   </head>
15   
16   <body>
17     生成的二维码以下: <br>
18     <div id="qrcode"></div>    
19     
20     <script type="text/javascript">
21  $("#qrcode").qrcode("www.baidu.com"); 22     </script>
23     
24   </body>
25 </html>

   3、运行微信

     开启服务运行成功后,可看到界面生成的二维码。jsp

     使用手机浏览器上的扫一扫,扫码后会进入指定的页面;使用微信扫一扫,扫码后显示的是网址文本而不是连接。

     产生上述状况是因为qrcode()中填写的是www.baidu.com,若加上http://则会进入连接页面。