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>