点击图片可以刷新二维码
spring 中
1 @RequestMapping(value = "/getLoginQR") 2 @ResponseBody 3 public void getqr(HttpSession session,Model model) throws Exception { 4 response.setContentType("image/*"); 5 //wifi ip 6 String ip=RequestUtils.getlocalIP(); 7 //login sid 8 System.out.println("session:"+session.getId()); 9 //app sid 10 String sid= UUID.fastUUID().toString(true).toUpperCase(); 11 System.out.println("getLoginQR sid:"+sid); 12 13 String uri = "ws://"+ip+":80/xxx/ws/"+session.getId()+"_"+sid; 14 String content=uri; 15 if(StrUtil.isEmpty(ip)) 16 content="IP does not exist."; 17 QrUtils.createQRCode2Stream(content,response); 18 }
jsp 中
<img id="qrimg" src="${ctx}/images/qr.jpg" width="166" height="166"> <script> var httpfullurl='${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}'; $(function(){ $("#qrimg").click(function(){ // var qrpath="http://"+httpfullurl+'/getLoginQR?t='+new Date().getTime(); $("#qrimg").attr('src',qrpath); }) $("#qrimg").click(); }); // 阻止浏览器默认右键点击事件 document.oncontextmenu = function() { return false; } </script>