wood burning stoves 2.0
The moose likes Servlets and the fly likes file down loading(very very urgent) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "file down loading(very very urgent)" Watch "file down loading(very very urgent)" New topic

file down loading(very very urgent)

kalyan kiran

Joined: Aug 21, 2001
Posts: 5
I Want to know whether a file is properly downloaded or not
at client side from server and also i would like to know how many bytes are being downloaded and i wil be very happy if any one of u can give me a sample code for downloading a file,
my client side is html page and middle tier is a servelt .pls reply me immediately
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hope this helps...
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
public class DownloadFile2 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException{
ServletOutputStream sos = null;
BufferedInputStream bis = null;
/*String id_usuario = request.getParameter("id_usuario");
String id_carpeta = request.getParameter("id_carpeta");
String ruta_objeto = request.getParameter("ruta_objeto");
File f = new File(FILE_PATH);
response.setHeader("Content-Disposition","attachment;filename="+ f.getName());
bis = new BufferedInputStream( new FileInputStream(f));
byte buffer2[] = new byte[bis.available()];
bis.read(buffer2, 0, buffer2.length);
sos = response.getOutputStream();
sos.write(buffer2, 0, buffer2.length);
good luck.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
...of course dont forget to call DownloadFile2
via a submit button in a form:
<form action=\"http://localhost:8080/servlet/DownloadFile2\" enctype=\"multipart/form-data\" method=get>
<input type=submit>
I agree. Here's the link: http://aspose.com/file-tools
subject: file down loading(very very urgent)
It's not a secret anymore!