Amigos,
Eu acabo de ler o tutorial sobre geração de arquivos (Aprendendo a manipular arquivos) de Guilherme Silveira, e tentei fazer um teste, gerando um arquivo no servidor e enviar um link para download deste arquivo, mas tem algo errado.. Alguém pode me ajudar?
Vejam os fontes: 1) Formulário que chama o Bean que gera o arquivo:<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<body>
<f:view>
<h:form>
<h:panelGrid columns="1" border="0" cellspacing="5">
<h:commandLink id="geraArq" title="Gerar o arquivo de Folha" value="Gera o arquivo" action="#{mbProcessFile.geraArq}" />
</h:panelGrid>
</h:form>
</f:view>
<a href="FormUpload.jsp">Back</a>
</body>
</html>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<html>
<body>
<f:view>
<h:panelGrid columns="2" border="0" cellspacing="5">
<h:outputText value="Result:"/>
<h:outputLink value="http://localhost:8084/TimeCard/saida.txt" id="arq" target="http://localhost:8084/TimeCard/saida.txt" />
</h:panelGrid>
</f:view>
<a href="FormUpload.jsp">Back</a>
</body>
</html>
3) E, o Bean que gera o arquivo (somente os métodos)
public String geraArq() {
TimeCardFileProcessor tcfp = new TimeCardFileProcessor();
try{
tcfp.geraArq();
} catch (Exception ex){
ex.printStackTrace();
return "erro";
}
return "gravou";
}
public String geraArq() throws IOException {
FileWriter writer = new FileWriter("saida.txt", true);
PrintWriter saida = new PrintWriter(writer,true);
saida.println("teste1");
saida.println("teste2");
saida.print("teste final");
saida.close();
writer.close();
return "gravou";
}
O que está faltando? Onde está o meu erro?
Ah, e claro, tem alguma forma mais inteligente de fazer isso?
obrigado.