通过jQuery的qrcode结合springmvc生成二维码

java代码

@RequestMapping("/goGroupQRCode")
	public String goGroupQRCode(HttpServletRequest request){
		String groupId = request.getParameter("groupId");//群组id
		request.setAttribute("code", groupId);
		return "user/QRCode/groupCode.jsp";
	}

jsp页面

 <%@ page contentType="text/html; charset=utf-8"%>
<!doctype html>
<html>
<head>
<!-- <link rel="stylesheet" type="text/css" href="../css/main.css" /> -->
<style type="text/css">
.demo{width:100%; height:100%; }
/*margin:40px auto 0 auto; min-  */
#code{margin-top:10px}
</style>

<script src="./js/qrCode/jquery-1.7.2.min.js"
	type="text/javascript"></script>
<script src="./js/qrCode/jquery.qrcode.js"
	type="text/javascript"></script>
<script src="./js/qrCode/qrcode.js"
	type="text/javascript"></script>
<script type="text/javascript" 
src="./js/qrCode/jquery.qrcode.min.js"></script> 


<script type="text/javascript">
$(function(){
	var str=$("#codeVal").val();
	console.log("str=="+str);
	if(str){
		var wid=document.body.clientWidth-20;
		var hei=document.body.clientWidth-20;
        
     	$(".demo").css("width",wid+"px").css("height",hei+"px");
		/* $('#code').qrcode(str); */
		$("#code").qrcode({
			render: "canvas",
			width: wid/2,
			height:wid/2,
			text:str
		});
		
		
		$("#code").css("margin-top",hei-wid/2+"px ");
		$("#code").css("margin-left",wid/4+"px ")
		/* + right+"px "+  bottom+"px "+  left+"px " */
	}else{
		alert("请重新打开页面");
	}
})
 function toUtf8(str) {   
    var out, i, len, c;   
    out = "";   
    len = str.length;   
    for(i = 0; i < len; i++) {   
    	c = str.charCodeAt(i);   
    	if ((c >= 0x0001) && (c <= 0x007F)) {   
        	out += str.charAt(i);   
    	} else if (c > 0x07FF) {   
        	out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));   
        	out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));   
        	out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));   
    	} else {   
        	out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));   
        	out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));   
    	}   
    }   
    return out;   
} 

/* background-image:url('./images/QRCode/codeBackground.jpg');
background-size:contain */
</script>
<title>推荐注册的二维码</title>
</head>
<body style="background-color:Light grey">
  <div class="demo">
   		<div id="code"><h2 align="center">扫一扫</h2></div>
   		<input type="hidden"  id="codeVal" value="${code}"/>
   </div>
</body>
</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值