Pessoal,
Estou tentando criar uma forma onde o usuário gere um arquivo txt e apareça pra ele um link para baixa-lo. Não posso usar popups pra isso. Alguém conhece alguma forma bacana? Estou usando o Jboss.
Já tenho esse código para gerar o arquivo:
public ActionForward gerarArquivo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response,List<ItemDomain> listItensJson)
throws Exception,BusinessException {
String itens = request.getParameter("itens");
ItemDelegate delegate = new ItemDelegate();
List<ItemDomain> listItens = null;
List<TmpControleItemFiscalDomain> listTmpControle = null;
String saida = null;
String retorno = "";
try{
response.setContentType("text/plain");
response.setHeader("Content-Disposition", "attachment;filename=\"teste.txt\"");
String caminho = "C:/teste.txt";
//String caminho = this.getServlet().getServletContext().getRealPath("/Temp/")+"teste.txt";
System.out.println(caminho);
PrintWriter pw = new PrintWriter(new FileOutputStream(caminho));
if(listItensJson != null){
for(int i=0;i<listItensJson.size();i++){
pw.println(listItensJson.get(i).getCodItem()+"|"+listItensJson.get(i).getDscItem());
}
}
pw.flush();
saida = "[{retorno: 'Arquivo criado com sucesso!',tiporetorno:'1',caminho:'"+caminho.replaceAll("\\", "\\\\")+"'}]";
incluirTmp(request,listItensJson);
}catch (Exception e) {
e.printStackTrace();
saida = "[{retorno: '"+e.toString()+"',tiporetorno:'2'}]";
}
response.setContentType("application/json;charset=UTF-8");
PrintWriter out = response.getWriter();
out.print(saida);
out.flush();
return mapping.findForward(Constants.FWD_GERAR);
}