I have a project with servlets in the back and JS in the front.
When I run servlet by pasting address in browser it works fine. But when I want to run it with button in JS, nothing happens.
Servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ExcelParser ep = new ExcelParser();
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheetl");
response.setHeader("Content-Disposition", "attachment; filename=workbook.xlsx");
XSSFWorkbook workbook = ep.getWorkbook();
ServletOutputStream out = response.getOutputStream();
workbook.write(out);
out.flush();
out.close();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
JS
Template.exportButton.events({
"click #exportButton": function (event) {
document.getElementById("exportButton").innerHTML = "Started";
$.get("https://mypage/pu/rec/build/positions/excel");
document.getElementById("exportButton").innerHTML = "Finished";
}
});
But when I click on Export Button on page, it changes text to "Finished", but servlet is not executed.
I have another servlet that look similar to above one and JS button with
$.get("https://mypage/pu/rec/build/positions/back?email=" + email, function (data) {});
and it works. How can I run this servlet with JS?
EDIT: Problem must be with servlet. I've changed the address in exportButton to second one and it works (the "back" servlet runs sh scripts on server). Is it because I try to send excel sheet in my servlet? If so, how can I send generated file to client?