Hello
Here is the code.
In a jsp file i call a java method:
"<jsp:useBean id="downloadSave" scope="page" class="DownloadSave" />
<%
String nameFichEur = request.getParameter("nomeFile");
downloadSave.doSave(nameFichEur,response);
%>"
The code of the class downloadSave is:
"import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
public class DownloadSave
{
public void doSave(String nameFichEur, HttpServletResponse res)throws ServletException, IOException
{
String pathFichEur = "c:\\jakarta-tomcat-3.2.3\\webapps\\PS2\\WEB-INF\\classes\\uploaddir\\" + nameFichEur;
System.out.println("nameFichEur: " + nameFichEur);
System.out.println("pathFichEur: " + pathFichEur);
//res.setContentType("application/x-filler");
res.setContentType("application/txt");
res.setHeader("Content-Disposition","attachment;filename=" + nameFichEur );
try
{
FileInputStream fileInput = new FileInputStream(pathFichEur);
int numOfBytes = fileInput.available();
byte byteArray[] = new byte[numOfBytes];
int nextByte = fileInput.read(byteArray);
fileInput.close();
OutputStream outStrm = res.getOutputStream();
outStrm.write(byteArray);
//outStrm.flush();
outStrm.close();
}
catch(IOException ioe)
{
System.out.println("download:file input exception");//..........
//ioe.printStackTrace();
}
catch(Exception e)
{
System.out.println("download: exception");//..........
}
}
}"
I hope you can help me!!!
Thanks
Claudia Vaz