Java-Vue使用浏览器调用本地exe服务

Java-浏览器调用本地exe服务

Java+Vue编写的BS服务调用本地的exe服务,从技术来说介绍这块的内容本来就很少,浏览器访问本地文件从安全限制上又存在诸多限制,本文章也是本人在实际开发过程中遇到了需要这种应用的场景,花费一些时间实践出的一种解决方案。

1.Vue画面-button按钮

<el-button type="primary" size="small" @click="buttonClick">读卡</el-button>

2.Vue画面-buttonClick点击事件

buttonClick(){
    const that = this;
    //调用本地的test.html画面
    setTimeout(() => {
    that.cardNoUrl = "http://127.0.0.1:8000/test.html";
    that.frameIF = true;
        window.addEventListener('message', function (e) {
        let data = "";
        data = e.data;
        if(data!=null && data!=undefined && data!=""){
        var arr;
        arr = data.split(";");
        that.formOne.plateNo = arr[1];
        that.formOne.crdNo = arr[0];
        }
        return;
    })
    }, 100);
},

3.Test.html文件内容

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <script type="text/javascript">
      addEventListener("load", function () {
        //初始化加载本地exe服务
        var temp ="000000;000000"
        const xhr = new XMLHttpRequest();
        xhr.open('GET', 'http://127.0.0.1:8000/read', true);
        xhr.onreadystatechange = function () {
          if (xhr.readyState === 4 && xhr.status === 200) {
            temp = xhr.responseText;
            window.parent.postMessage(temp, '*')
          }else{
            window.parent.postMessage(temp, '*')
          }
        };
        xhr.send();
      })
    </script>
</body>
</html>

4.请求对应的exe服务

依据实际需求编写读取IC卡信息的exe服务
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值