Servlet download file from server

Servlet download file from server

I am looking for a Servlet download file example.

View Answers

March 18, 2008 at 8:36 PM

Example ? Servlet to download an xml file from distant server

DownloadFile.java


import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DownloadFile extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)throws
ServletException, IOException{
PrintWriter out = response.getWriter();
String filePath = "C:/JSTL-Login.zip";
String fileName = "JSTL-Login.zip";
FileInputStream fileToDownload = new FileInputStream(filePath);
ServletOutputStream output = response.getOutputStream();
response.setContentType("application/zip");
response.setHeader("Content-Disposition","attachment; filename="+fileName);
response.setContentLength(fileToDownload.available());
int c;
while((c=fileToDownload.read()) != -1){
out.write(c);
}
out.flush();
out.close();
fileToDownload.close();
}
}


web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";
version="2.4">



<servlet>
<servlet-name>DownloadServlet</servlet-name>
<servlet-class>DownloadFile</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DownloadServlet</servlet-name>
<url-pattern>/DownloadFile</url-pattern>
</servlet-mapping>

</web-app>









Related Tutorials/Questions & Answers:
File download from server to client machine - JSP-Servlet
File download from server to client machine  hi, I want to save a pdf file to my client machine from a button provoded in a jsp page.The file... the generated report in server as follow. exporter.exportIntoPdfFile("c://reports
Download file - JSP-Servlet
Servlet download file from server  I am looking for a Servlet download file example
Advertisements
upload and download files from ftp server using servlet - Ajax
for upload and download files from ftp server using servlet and how to use...upload and download files from ftp server using servlet  Hi,Sir... to disconnect from FTP server " + "after server refused connection. "+e.toString
php download file from ftp
php download file from ftp  Need to download files from ftp using php. a simple example
php download file from url
php download file from url  how to download multiple files in PHP using the URL's
how to download a file from a folder??
how to download a file from a folder??  i can upload any kind of files to a folder, and only the path of the file is saved into the database, now how a client can download the file from my folder. pls provide me the jsp code
Upload and download file - JSP-Servlet
from a database but before downloading a file, server should ask me............ Now to download the word document file, try the following code...=con.createStatement(); ResultSet rst= st.executeQuery("select file_data from file
JSP file download - JSP-Servlet
of the word file in database. when i want to download that file i am eliminating... to download word file: <% ServletOutputStream output... file_data from file "); if(rst.next()) { Content=rst.getString("file_data
download mp3 file on server in iphone
download mp3 file on server in iphone  I want to download mp3 file on the server in iphone......plz help me give me the demo code
How to download files from server to local disk using ZIP format in JSP page - JSP-Servlet
How to download files from server to local disk using ZIP format in JSP page  hi i have an application to upload and download multiple files. As i can upload multiple files .now i have to download all uploaded files on local
download a file from browser - Java Beginners
download a file from browser  How to download a file from browser and save it in local path
To download a website from a given url. - JSP-Servlet
To download a website from a given url.  write a program to download a website from a given URL.it must download all the pages from that website.it should take the depth of retrieval from user input.all the files pages must
File Upload And download JSP Urgent - JSP-Servlet
File Upload And download JSP Urgent  Respected Sir/Madam, I... Ragavendran, i am sending code of file download in jsp. Plz implement this code. file download in jsp
Capture browser file download event - JSP-Servlet
Capture browser file download event  Hi, I appreciate your help and thaanks for that.But my question was when filedownload dialog box comes in browser,how we can come to know that user has clicked on Open,save or cancel button
FTP Server : Download file
This tutorial contains description of file downloading from the FTP server using java
write to file from servlet - JSP-Servlet
write to file from servlet  Hi, I have a jsp file where I input data and retrive data through servlet. However; when I edit data it is not showing right data on the web site. I am also trying to write this data to file
how to create xls file and give download option using jsp/servlet?
how to create xls file and give download option using jsp/servlet?  Hi, how to create file and give download option to user,so that the user can save the file on defined path
Uploading file in servlet from a html form
Uploading file in servlet from a html form  Sir, I want to upload a picture from my html file and save it to my database as BLOB,but what JAR should i use for this purpose i am really confused about.And also is it possible to do
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
how to create a php script to download file from database mysql
how to create a php script to download file from database mysql  how to create a php script to download file from databse mysql
download xml file from website using java code
download xml file from website using java code  how to download xml file from website using java code
How to download and save a file from Internet using Java?
How to download and save a file from Internet using Java?  How to download and save a file from Internet using Java
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload   Dear Sir, My Question is: How display a image on servlet from file upload Your Answer: Hi... of file. like any .jpg, .txt. Servlet page dispaly empty in each cases
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload  Dear Sir, My issue is: How display a image on servlet from file upload I receive your answer today....jar and set that on classpath.I keep the servlet file in javacode package. First
How to download a file from URL in Java?
How to download a file from URL? If you are looking for example code in Java..._TO_REPLACE_1 This example can be used to download any type of file from URL... downloads the url-file-download-directory.gif from http://www.roseindia.net/java
How to add download option for openwith and saveAs on exporting file to excel in servlet
How to add download option for openwith and saveAs on exporting file to excel... my requirement I need to give download option for openwith and saveAs from... data from database into .excel formate in which i have given hard coded path
How to add download option for openwith and saveAs on exporting file to excel in servlet
How to add download option for openwith and saveAs on exporting file to excel... my requirement I need to give download option for openwith and saveAs from... data from database into .excel formate in which i have given hard coded path
How display a Image on servlet from file upload - JSP-Servlet
How display a Image on servlet from file upload  Dear Sir, I were ask a question that How display the Image on servlet through file upload. Today I get your answer. But Sir, It code not display the image on servlet
file download
file download  I uploaded a file and saved the path in database. Now i want to download it can u plz provide code
Read Text file from Javascript - JSP-Servlet
Read Text file from Javascript  plz send the code How to Retrieve the data from .txt file thru Javascript? And how to find the perticular words in that file
retrieving of value from excel file - JSP-Servlet
this message to all the employees when i upload a file then it fetch a data from that excel sheet i.e this matter will take a para meter values from the excel...retrieving of value from excel file  Dear sir, Thanks for sending
retrieving of value from excel file - JSP-Servlet
this message to all the employees when i upload a file then it fetch a data from that excel sheet i.e this matter will take a para meter values from the excel...retrieving of value from excel file  Dear sir, Thanks for sending
How display a Image on Servlet from file upload - JSP-Servlet
How display a Image on Servlet from file upload  Dear Sir, My requirement is I want to display a Image on Servlet from File Upload... Internet Browser,but problem are not solved. I already download comman-file
retrieving of value from excel file - JSP-Servlet
retrieving of value from excel file  Dear sir, Thanks for sending a code now i am getting a particular column value i.e EmailId column for snding a massmails,now i have to get a particular column values i.e Name(A),EL(B
Getting Parameter from a css styled jsp file to a java servlet file...
Getting Parameter from a css styled jsp file to a java servlet file... ...; java servlet file-- /* * To change this template, choose Tools... is it not getting the parameter??? How do i accept the value in the servlet file
Download CSV File from Database in JSP
Download CSV File from Database in JSP  ... to download CSV  file from database in JSP.  In this example, we have... and download the CSV file  from database. All CSV file will show
Create text file at client's directory from server.
Create text file at client's directory from server.  Need java code to create text file at client's directory from server..... Please Help
File transfer from client to server - Java Beginners
File transfer from client to server  hi,, I've been trying to make an application where the user select a file using JFileChooser and then the program directly send it to the server using client/server sockets, I've tried
Searching a word file on server in JSP - JSP-Servlet
Searching a word file on server in JSP  Seacrhing a word file on server side using JSP. I am Apache Tomcat Server. Please help me Sir
how to upload a file of apk format in a folder from servlet
how to upload a file of apk format in a folder from servlet  How to upload a file of apk format to a folder from servlet, i am trying to do, its getting uploaded as .zip file and not apk file
php download file code
php download file code  PHP code to download the files from the remote server
download - JSP-Servlet
download  here is the code in servlet for download a file. while...(); System.out.println("inside download servlet"); BufferedInputStream...()); out.println(""); out.println(""); out.println("Servlet download
Delete a file from FTP Server
In this section you will learn how to delete file from FTP server using java
reading a file on server side - JSP-Servlet
reading a file on server side  Thank you sir for replying... & reading a word file in JSP which is uploaded by client. please help me...: Display file upload form to the user UPLOAD THE FILE Choose the file
not able to get values from jsp file - JSP-Servlet
, her am sending the file jsp and servlet but in the servlet file am not able to get... remove encrtype from form tag its work fine please go through the file...; ================================================================= servlet file
URL file Download and Save in the Local Directory
URL file Download and Save in the Local Directory       This Program file download  from  URL and save this Url File in the specified directory. This program specifies
download code using servlet - Servlet Interview Questions
download code using servlet  How to download a file from web to our system using Servlet
how to generate the pdf file with scroolbar from jsp age - JSP-Servlet
how to generate the pdf file with scroolbar from jsp age  How to generate the pdf file with scroolbar from jsp.i am not able to see the all the columns in pdf file now .it is very urgent for me plz help
callig jsp file from javascript function - JSP-Servlet
callig jsp file from javascript function  I want to call a jsp file from javascript function. What I want to do is Whenever a user clicks... data, no button and no links. Is it possible to call jsp page from static html
how to download file
how to download file  How do I let people download a file from my page

Ads