I'm trying to select some rows in datatable, put it in txt file to be downloaded and redirect to a jsp page, but it is not redirecting. it give me an exception
private void generateFicheiro(HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException {
String outputText = "";
for(String name : request.getParameterValues("selectedItems")) {
Conta conta = contaService.getContaByName(name);
outputText = outputText + conta.getNome() + "|" + conta.getEmail() + "|" + conta.getIdEstrutura() + "\\n";
//System.out.println(conta.getNome());
}
response.setContentType("text/plain");
response.setHeader("Content-Disposition", "attachment; filename = example.txt");
try {
//InputStream in = request.getServletContext().getResourceAsStream("/WEB-INF/example.txt");
OutputStream outputStream = response.getOutputStream();
//String outputResult = "This is Test";
outputStream.write(outputText.getBytes());
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
response.sendRedirect("list-ficheiro");
return;
}