Я подключил электрон, JSP для входа в систему, зарегистрироваться.электрон - это лицевая сторона (html, js), jsp (jsp, java) - это сторона сервера.
Сейчас я пытаюсь загрузить файл с сервера на электрон.(здесь я устанавливаю файл (bullet01.png) для теста.)
flow:
- , когда пользователь нажимает кнопку (запрос ajax get)
- поиск серверафайл, который из параметра URL
- метод успеха получает результат
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")
}
});
}
, когда я выполняю на jsp, он скачивает нормально, но с электрона он не '
вот код
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 в электронном виде
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
<script language="JavaScript" type="text/javascript" src="js/jquery-3.2.1.js"></script>
<script src="js/myscript.js"></script>
<script>if (window.module) module = window.module;</script>
<body>
<h1 class="signUpTitle">test page</h1>
<!-- <input type="button" value="버튼" class="signUpButton" onclick="showOk()" > -->
<a onclick="downloadClick()">file</a>
</body>
</html>
![enter image description here](https://i.stack.imgur.com/FyLZY.png)