Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Servlet download file from server
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


escamba
Servlet download file from server
1 Answer(s)      6 years and 8 months ago
Posted in : JSP-Servlet


I am looking for a Servlet download file example.


Advertisement
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
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
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
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
FTP Server : Download file
This tutorial contains description of file downloading from the FTP server using java
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 a file from browser - Java Beginners
download a file from browser  How to download a file from browser and save it in local path
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
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
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
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
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 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
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
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
php download file code
php download file code  PHP code to download the files from the remote server
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.... This example can be used to download any type of file from URL. It can be text...); } } Above example code downloads the url-file-download-directory.gif from
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
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
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
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... file  from database. All CSV file will show as hyperlink. 2
Delete a file from FTP Server
In this section you will learn how to delete file from FTP server using java
how to download file
how to download file  How do I let people download a file from my page
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
Advertisements
 

 

 

DMCA.com