Boa tarde,
Pessoal estou com problema,
Sou novo no java, estou tentando fazer um download de um arquivo xls, para q apareça aquela tela de download, eu fiz a planilha pelo POI quero q o meu usuario clique em abaixar a planilha e la fique salve no pc dele … atravez do download …
Sei q tem q fazer servelt …
eu fiz o codigo queria q alguem me desse um apoio !
[code]public class GeraPlanilha extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
InputStream is = getClass().getClassLoader().getResourceAsStream("C:/Estatistica.xls");
byte[] b = inputStreamToBytes(is);
ServletOutputStream out = response.getOutputStream();
response.reset();
response.setHeader("Content-Disposition", "attachment;filename=Estatistica.xls");
response.setContentType("Application/xls");
response.setContentLength(b.length);
out.write(b);
out.flush();
out.close();
}
public byte[] inputStreamToBytes(InputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
byte[] buffer = new byte[1024];
int len;
while((len = in.read(buffer)) >= 0)
out.write(buffer, 0, len);
in.close();
out.close();
return out.toByteArray();
}
}
[/code]
Agradeço se alguem puder me ajudar.