electron打包后页面有ajax,javascript - download a file on ajax success electron, jsp - Stack Overflow...

i connected electron, jsp for login, sign up. electron is front side(html,js), jsp(jsp, java) is server side.

now i'm trying to download a file from server to electron.

(here i set a file (bullet01.png) for test.)

flow:

when user clicks a button(ajax get request)

server find file which from url parameter

success method gets result

myscript.js

function downloadClick() {

$.ajax({

url: 'http://localhost:8090/curriculum1.4/login_controller.jspx?cmd=downloadFile&bFile=bullet01.png',

type: 'get',

//dataType: 'json',

success: function(resp) {

console.log("success");

console.log(resp);

//window.open("C:\Users\CP\Desktop\테스트\core5.0.14\out\artifacts\unnamed\curriculum1.4\filedir\bullet01.png");

},

error: function(xhr, status, error) {

alert("err")

}

});

}

when i execute on jsp it downloads ok but from electron it doesn't download anything.

here is the code

public void downloadFile(ViewMeta view) throws IOException {

DataSet input = view.getInputDataSet();

HttpServletRequest request = view.getHttpServletRequest();

HttpServletResponse response = view.getHttpServletResponse();

String bFile = new String(input.getText("bFile").getBytes("UTF-8"), "ISO-8859-1");

String filePath = request.getServletContext().getRealPath("/curriculum1.4/filedir");

response.setHeader("Content-Disposition", "attachment;filename=\"" + bFile + "\";");

File file = new File(filePath + "/" + bFile);

FileInputStream fileInputStream = new FileInputStream(file);

ServletOutputStream servletOutputStream = response.getOutputStream();

byte b[] = new byte[1024];

int data = 0;

while ((data = (fileInputStream.read(b, 0, b.length))) != -1) {

servletOutputStream.write(b, 0, data);

}

servletOutputStream.flush();

servletOutputStream.close();

fileInputStream.close();

}

test.html in electron

Insert title here

if (typeof module === 'object') {window.module = module; module = undefined;}

if (window.module) module = window.module;

test page

file

FyLZY.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值