String userAgent = request.getHeader("user-agent").toLowerCase();
PrintWriter writer = response.getWriter();
StringBuilder sb = new StringBuilder();
//微信客户端
if(userAgent.indexOf("micromessenger") != -1){
sb.append("<html>");
sb.append("<script type='text/javascript' src='https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js'></script>");
sb.append("<script type='text/javascript' src='https://res.wx.qq.com/open/js/jweixin-1.2.0.js'></script>");
sb.append("<script>");
sb.append("if(typeof window.WeixinJSBridge=='undefined'){$(document).on('WeixinJSBridgeReady',function(){WeixinJSBridge.call('closeWindow')})}");
sb.append("</script>");
sb.append("</html>");
}
//支付宝
else if(userAgent.indexOf("alipay") != -1){
sb.append("<html>");
sb.append("<script type='text/javascript' src='https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js'></script>");
sb.append("<script type='text/javascript' src='https://a.alipayobjects.com/g/h5-lib/alipayjsapi/3.0.6/alipayjsapi.min.js'></script>");
sb.append("<script>");
sb.append("if(typeof window.AlipayJSBridge=='undefined'){$(document).on('AlipayJSBridgeReady',function(){AlipayJSBridge.call('closeWebview')})}");
sb.append("</script>");
sb.append("</html>");
}
writer.write(sb.toString());