File Download in jsp

File Download in jsp

file upload code is working can u plz provide me file download

View Answers

March 26, 2011 at 12:53 AM

<%@page contentType="application/octet-stream"%>
<%@page pageEncoding="UTF-8"%>
&lt;%@ page language="java" import="java.io.<em>,java.net.</em>,java.util.<em>,javax.servlet.</em> "%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
&lt;%
BufferedInputStream filein = null;
BufferedOutputStream outputs = null;
try {
File file = new File("./path/filename.csv");//specify the file path
byte b[] = new byte[2048];
int len = 0;
filein = new BufferedInputStream(new FileInputStream(file));
outputs = new BufferedOutputStream(response.getOutputStream());
response.setHeader("Content-Length", ""+file.length());
response.setContentType("application/force-download");
response.setHeader("Content-Disposition","attachment;filename=Backup.csv");
response.setHeader("Content-Transfer-Encoding", "binary");
while ((len = fin.read(b)) > 0) {
outputs.write(b, 0, len);
outputs.flush();
}
}
catch(Exception e){
out.println(e);
}
%>
</body>
</html>

May 16, 2012 at 12:01 PM

*Create 2 Files* 

 **DownloadPage.JSP code :-** 

&lt;a href=&#039;downloadPdf.jsp?file=FILE.pdf&#039; &gt;Download PDF File&lt;/a&gt;

**downloadPdf.JSP code :-** 


&lt;%@ page import=&quot;java.util.*,java.io.*&quot;%&gt;               

&lt;%

  File f = new File (&quot;E:/PDFfiles/Downloads/&quot; + request.getParameter(&quot;file&quot;) );
  response.setContentType (&quot;application/pdf&quot;);
  response.setHeader (&quot;Content-Disposition&quot;, &quot;attachment; filename=&quot;&quot;+request.getParameter(&quot;file&quot;)+&quot;&quot;&quot;);
  String name = f.getName().substring(f.getName().lastIndexOf(&quot;/&quot;) + 1,f.getName().length());
  InputStream in = new FileInputStream(f);
  ServletOutputStream outs = response.getOutputStream();


  int bit = 256;
  int i = 0;
    try {
 while ((bit) &gt;= 0) {
 bit = in.read();
 outs.write(bit);
 }
 } catch (IOException ioe) {ioe.printStackTrace(System.out);
 }
 outs.flush();
 outs.close();
 in.close(); 
%&gt;









Related Tutorials/Questions & Answers:
File Download in jsp
File Download in jsp  file upload code is working can u plz provide me file download
Download file - JSP-Servlet
Servlet download file from server  I am looking for a Servlet download file example
Advertisements
JSP file download - JSP-Servlet
JSP file download  Hi! I am saving (webapp/docs/sample.docx) path of the word file in database. when i want to download that file i am eliminating... to download word file: <% ServletOutputStream output
Upload and download file - JSP-Servlet
Upload and download file  What is JSP code to upload and download............ Now to download the word document file, try the following code...(); response.getOutputStream().flush(); %> Thanks   I want to download a file
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
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 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 that was generated by jasper libraries.In my code i can give path for save
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
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
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
Upload and Download in JSP - JSP-Servlet
and downloading a file in JSP.. When the admin clicks upload, he must be able to upload.... Please visit for more information. http://www.roseindia.net/jsp/file_upload...Upload and Download in JSP  Respected Sir/Madam, I am
download or save jsp page
download or save jsp page  hii.., this is my jsp page .. This page is theater ticket. i want to download this page. so i need to save this page or download.. that depend on user wish how to make this page save or download <
download or save jsp page
download or save jsp page  hii.., this is my jsp page .. This page is theater ticket. i want to download this page. so i need to save this page or download.. that depend on user wish how to make this page save or download <
php download file script
php download file script  PHP script to download file in IE
Download PDF file
Download PDF file  How to download PDF file with JSF
how to download file
how to download file  How do I let people download a file from my page
php download file code
php download file code  PHP code to download the files from the remote server
php download file browser
php download file browser  limiting downloading file system via browser only through my web application
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
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
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
JSP File
JSP File  Hi, What is JSP File? How to create JSP file? Thanks   Hi, JSP file is simple text file with .jsp extenstion. You can run JSP file on tomcat server. Read more at JSP tutorials section. Thanks
upload and download files - JSP-Servlet
and download files in JSP visit to : http://www.roseindia.net/jsp/file_upload...upload and download files  HI!! how can I upload (more than 1 file) and download the files using jsp. Is any lib folders to be pasted? kindly
download - JSP-Servlet
download  here is the code in servlet for download a file. while downloading the file the file is getting downloaded but content is not present... code you have written is just creating a file with the same name for download
Download Button - JSP-Servlet
Download Button  HI friends, This is my maiden question.... And i want the Bank customers to DOWNLOAD the mini statement. Can any one help me how to implement the download button so that on clicking that the mini
Download LINK - JSP-Servlet
Download LINK  sorry i am the new1 to java. I am learning and doing the project, can you please send me the complete code. So that i can understand easily. i want the code like by Clicking DOWNLOAD button the SAVE as dialog box
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
jsp-file
jsp-file  i want to upload a file by browse button and the file should be save in ms access database.....how i can implement trough jsp plz help me sir
java/jsp code to download a video
java/jsp code to download a video  how can i download a video using jsp/servlet
download image using url in jsp
download image using url in jsp  how to download image using url in jsp
upload and download a file - Java Beginners
upload and download a file  how to upload a file into project folder in eclipse and how to download the same using jsp   Hi Friend, Try the following code: 1)page.jsp: Display file upload form to the user
Upload and Download Large files in jsp
Upload and Download Large files in jsp  I am not able to download large files (>200mb) from any server. I need a code to download and upload large files (atleast 4 gb) to a server using jsp page
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
Uploading and download pdf or .txt file.
Uploading and download pdf or .txt file.  I want admin user to upload pdf file into database and the users can download those pdf format from database
How to upload and download file in hadoop?
How to upload and download file in hadoop?  Hi, I am trying to learn to upload the file on the Hadoop HDFS and then download the same file for learning the process. How to upload and download file in hadoop? What
file upload download - Java Beginners
file upload download  how to upload and download files from one system to another using java.io.* and java.net.* only please send me code
jsp file - JSP-Servlet
jsp file  org.apache.jasper.JasperException: /jsp/admin/UserRegistration.jsp(155,4) According to the TLD or the tag file, attribute valu e... org.apache.jasper.JasperException: /jsp/admin/UserRegistration.jsp(155,4) According
org.jfree package download - JSP-Servlet
org.jfree package download  I saw a code in roseindia but that code requires a package "org.jfree.chart.*" and "org.jfree.ui.*" Please give me the packages .  Hi friend, Plz download the jar files
java code to upload and download a file - Java Beginners
and Download visit to : http://www.roseindia.net/jsp/file_upload/index.shtml http... to upload a file and download a file from databse, My requirement is how can i..., one user send one a.doc file to x ,he has to download his a.doc another
how to upload and download images using buttons in jsp?
how to upload and download images using buttons in jsp?  how to upload and download images using buttons in jsp
File download security.
File Download Security  This script prevents the file to be linking to other file as this script force the file to be downloaded well before...; In this script, filter_var() is used for filtering the file and valid
written in jsp file
written in jsp file  how to create and write in a jsp file through simple core java code
how to download the uploaded folder files using jsp
how to download the uploaded folder files using jsp  how to download the uploaded folder files using jsp
download file Error in struts2 action class
download file Error in struts2 action class  Hi, i am using bellow block of code for download file : public void downloadGreeting(String... strPrefix = System.getProperty("astsoundsfolderoriginal"); File
jsp upload file to server
jsp upload file to server  How to create and upload file to server in JSP?   Find the given example that explains how to upload single and multiple file on server using JSP
parsing xml file in jsp
parsing xml file in jsp  example that pars XML file in JSP
Creating dynamic jsp file in java file to include another jsp file
Creating dynamic jsp file in java file to include another jsp file  I am able to create jsp file in java that includes ; table tr td and img tags..... Need to include jsp file in the same content. The below code doesn't help me

Ads