• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

download a file from the server an save it to the client disk

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello
I would like to download a file from the server and save it to the client disk. But i don't know how. Can you help me!!!???
Thanks
Claudia
 
Claudia Vaz
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from server to client? hmmm?
begin irony;
There is a real tricky way but it is coded in HTML. look
<a href="file.txt">click here</a>
as you can see it is not an easy task to do it
end irony;
if you mean client to server then go there for some tool http://servlets.com/cos/index.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic