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 hereif (typeof module === 'object') {window.module = module; module = undefined;}
if (window.module) module = window.module;
test page
file