Salut,
Mon but c'est qu'un client télecharge une fichier (extension ".rules") du serveur , alors je declare dans mon bean la fonction:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
public void downloadFile(){
File file = new File(getOptionModifier());
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext() ;
ServletContext context = (ServletContext) externalContext.getContext();
HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
response.setContentType("application/rules");
String downloadFile =getOptionModifier() ;
response.addHeader("Content-Disposition", "attachment; filename=\"" + downloadFile + "\"");
byte[] buf = new byte[1024];
try{
long length = file.length();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));
ServletOutputStream out = response.getOutputStream();
response.setContentLength((int)length);
while ((in != null) && ((length = in.read(buf)) != -1)) {
out.write(buf, 0, (int)length);
}
in.close();
out.flush();
out.close();
FacesContext.getCurrentInstance().responseComplete();
}catch (Exception exc){
exc.printStackTrace();
}
} |
et je fais l'appelle
<ice:commandButton style="font-style: italic;font-size: larger;font-family: cursive;" id="download" value="Télecharger" action="#{signature.downloadFile}" />
Mais rien ne se passe 
Svp y a-t-il une idée??
Merci.
Partager