I found some code but it's not working perfectly!
In a
jsp file i have
"<form enctype="multipart/form-data" method="post" action="save.jsp">
<input type="file" name="pdfurl">
<input type="submit" value="save">
</form>"
In the save.jsp i have the following code
"<jsp:useBean id="beanSalvar" scope="page" class="salvar" />
<%
beanSalvar.doPost(request,response);
%>"
In the salvar class i have the following code:
"import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;
public class salvar
{
public void doPost( HttpServletRequest req, HttpServletResponse res)throws Exception, IOException
{
String pdf = req.getParameter("pdfurl");
String filename = pdf.substring(pdf.lastIndexOf("/")+1);
//res.setContentType("application/x-filler");
res.setContentType("application/txt");
res.setHeader("Content-Disposition","attachment;filename=" + filename );
try
{
FileInputStream fileInput = new FileInputStream(pdf);
int numOfBytes = fileInput.available();
byte byteArray[] = new byte[numOfBytes];
int nextByte = fileInput.read(byteArray);
fileInput.close();
OutputStream outStream = res.getOutputStream();
outStream.write(byteArray);
outStream.close();
}
catch(IOException ioe)
{
System.out.println("download:file input exception");//..........
//ioe.printStackTrace();
}
catch(Exception e)
{
System.out.println("download: exception");//..........
}
}
}
"
First he doesn't have the value of req.getParameter("pdfurl");
Second, if i give him the value he downloads the file, saves it but he gives the following error:
"2001-12-13 08:44:27 - Ctx( /PS2 ):
IllegalStateException in: R( /PS2 + /save.jsp
+ null) OutputStream is already being used for this request"
Can anyone help?
Thanks
Claudia Vaz