I have a file to dowmnload from servlet and i need to download it when user clicks download button without being page refreshed.Hiw can i achieve this. Here is my jsp code.I m allowing user to dpownload the file by inputting the credentials in search box.So my file searching logic is in servlet.
<form action="Download_Servlet" class="download" method="post">
Search:<input type="text" name="dropdown" id="datedropdown">
<input type="submit" id="downloadRecords" value="Download">
Here is my servlet code
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment;filename=abc.csv");
ServletOutputStream out = res.getOutputStream();
for (Order traverse : orderMap.values())
{
out.write(traverse.toString().getBytes());
out.write("\n".getBytes());
out.flush();
}
Reason for using for loop is to write hundreds of records into file and then flush it..Nbow the concern is when user clicks download button page is trying to be redirect but there is no code in servlet for redirecting the response so why this is happening..I want is when download button clicked, file only should be downloaded without page being redirected.