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



Home Answers Viewqa JSP-Servlet Servlet download file from server

Have Programming Question? Ask it here!
 
 
 


escamba
Servlet download file from server
1 Answer(s)      6 years and 2 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
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
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
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
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
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
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
php download file code
php download file code  PHP code to download the files from the remote server
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
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
Delete a file from FTP Server
In this section you will learn how to delete file from 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
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
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
how to download file
how to download file  How do I let people download a file from my page
Application server to download
Application server to download  Which Application server can be downloaded for free to use personally at home to practice JSP,EJB etc
Download a file - Java Beginners
Download a file   Hi, I need a java code to download a file from a website and before downloading it should give me an option to browse and select the location to put the file. Thanks in advance
download code using servlet - Servlet Interview Questions
download code using servlet  How to download a file from web to our system using Servlet
php download file script
php download file script  PHP script to download file in IE
File Download in jsp
File Download in jsp  file upload code is working can u plz provide me file download
Download PDF file
Download PDF file  How to download PDF file with JSF
php download file browser
php download file browser  limiting downloading file system via browser only through my web application
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
file download in struts - Struts
file download in struts  Hello... I've designed an application where i need to download an xml file by creating it... so...i used dom for it.. I... an xml file from database.. Everything's going on well... Now what my problem is i
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
download code from database
download code from database  how to download files from database
csv file download
csv file download  Hello Every one, when user clicks download button I want to retrieve data from mysql database table in csv format using java.if... the following link: JSP Retrieve data from MySQL Database
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 to upload zip file from android to server programmatically?????
How to upload zip file from android to server programmatically?????  hi , I want to upload zip file from android phone sdcard to server programmatically. So any one do this task in past so please share your experience with me
File Download Security
File Download Security   Hello, I trying to create an application in PHP to prevent or provide file download security. So, I need the help of senior... files downloading. Please read this article about File Download Security
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
Advertisements
 

 

 

DMCA.com