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



Home Answers Viewqa JSP-Servlet JSP Upload and Downloading files
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragavendran.R
JSP Upload and Downloading files
1 Answer(s)      6 years and 3 months ago
Posted in : JSP-Servlet



Advertisement
View Answers

September 22, 2008 at 11:37 AM


Hi friend,


Code to download file from database

Some points to be remember:

This code for download the file for specified "id" in the database.

<%@ page import="java.io.*,java.util.*,java.sql.*" %>
<%
int id=0;
if(request.getParameter("id")!=null && request.getParameter("id")!="")
{
id = Integer.parseInt(request.getParameter("id").toString());
}
String connectionURL = "jdbc:mysql://localhost/application";;
String url=request.getParameter("WEB_URL");
String Content=new String("");
Statement stmt=null;
Connection con=null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection(connectionURL,"root","root");
stmt=con.createStatement();
String qry = "select * from file where id="+id;
ResultSet rst= stmt.executeQuery(qry);
if(rst.next())
{

Content=rst.getString("file_data");
}
out.println(Content);
byte requestBytes[] = Content.getBytes();
ByteArrayInputStream bis = new ByteArrayInputStream(requestBytes);
response.reset();
response.setContentType("application/text");
response.setHeader("Content-disposition","attachment; filename=" +"data.csv");
byte[] buf = new byte[1024];
int len;
while ((len = bis.read(buf)) > 0){
response.getOutputStream().write(buf, 0, len);
}
bis.close();
response.getOutputStream().flush();
}
catch(Exception e){
e.printStackTrace();
}
%>

For read more information :

http://www.roseindia.net/jsp/downloadcsv.shtml


Thanks



Related Tutorials/Questions & Answers:
JSP Upload and Downloading files - JSP-Servlet
JSP Upload and Downloading files  Respected Sir/Madam, Very... and downloading files in JSP, I am facing a problem.. 1) The file name is getting inserted... are fixed one for all types of files what I have uploaded.. I Dont know the exact
Problem in downloading files - JSP-Servlet
Problem in downloading files  Hi, i have uploaded some files using its uploading successfully. but when downloading the same file, its giving...:148) at org.apache.jsp.downloadfile_jsp._jspService(downloadfile_jsp.java:146
Advertisements
files uploding and downloading codes
files uploding and downloading codes  any one know JSP codes for upload files,download files and delete files from a created virtual memory
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
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
How to upload files to server using JSP/Servlet?
How to upload files to server using JSP/Servlet?  How to upload files to server using JSP/Servlet
upload and download all kinds of files in jsp - Java Beginners
upload and download all kinds of files in jsp  how to upload and download all kinds of files ex: image file,pdf,.xls in jsp. your help is highly appreciated.  we can upload the all type s of files into oracle 10g
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
what are the codes for uploading and downloading files in and from database?
what are the codes for uploading and downloading files in and from database?  We are designing a student's website where they can get and post study materials. We actually need the code to upload and download files in and from
Downloading in JSP - JSP-Servlet
Downloading in JSP  Respected Sir/Madam, I am R.Ragavendran.. How are you roseindia team? I am having an irritative problem in my JSP application while downloading the uploaded file contents.. Actually my problem is I
Mutliple files upload
Mutliple files upload  Hi Sir, Am doing a project in Jsp and Servlets, i want to upload multiple files inside the grid of the table, and submit... the following link: http://www.roseindia.net/jsp/file_upload
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc... link: http://www.roseindia.net/jsp/file_upload/uploadingMultipleFiles.shtml
Creat a folder, inside it upload and download files in jsp and mysql
Creat a folder, inside it upload and download files in jsp and mysql  Create one or more folder .inside it we can upload and download multiple files   Here is an application that will upload the file and save
File Upload and Retrive files
File Upload and Retrive files  Can any body help me am getting an error in uploading file. into mysql database.... thank's in advance
Mutliple files upload
Mutliple files upload  <%@page contentType="text/html...","Struts","Hibernet","Springs","JSP","Servlet","JavaScript"); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP
Mutliple files upload
Mutliple files upload  <%@page contentType="text/html...","Struts","Hibernet","Springs","JSP","Servlet","JavaScript"); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP
Mutliple files upload
Mutliple files upload  <%@page contentType="text/html...","Struts","Hibernet","Springs","JSP","Servlet","JavaScript"); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP
Mutliple files upload
Mutliple files upload   <%@page contentType="text/html...","Struts","Hibernet","Springs","JSP","Servlet","JavaScript"); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP
Mutliple files upload
Mutliple files upload  <%@page contentType="text/html...","Struts","Hibernet","Springs","JSP","Servlet","JavaScript"); listValue = new Array("CoreJava","J2EE","J2SE","Struts","Hibernet","Springs","JSP
downloading
downloading  i doing project in php with mysql. i am using xampp.i need code for downloading file
phpmyadmin - upload csv files - SQL
phpmyadmin - upload csv files  i have database in phpmyadmin. i have upload one time in csv file. i need to another csv file in upload same table. i will try to do this but result is failed. (table rows and csv rows are same
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
files upload to apache ftp server - Ajax
files upload to apache ftp server  Please, how to upload multiple files to apache ftp server using ajax . I want to upload files using drag drop... line. but I am trying to upload files using ajax. I want you to answer to me
files upload to apache ftp server - Ajax
files upload to apache ftp server  Please, how to upload multiple files to apache ftp server using ajax . I want to upload files using drag drop... line. but I am trying to upload files using ajax. I want you to answer to me
Jsp Upload
Jsp Upload  <p>multipart\form-data; boundary...; <p>else { </p> <p>out.println("unsucessfull to upload...;<TITLE>Display file upload form to the user</TITLE></HEAD>
Source file upload by attaching multiple files
Source file upload by attaching multiple files  Hi, I am trying to develop a file upload with multiple files attached functionality in java(like in gmail or in picasa). The source I found so far will select a single file. When I
Source file upload by attaching multiple files
Source file upload by attaching multiple files  Thanks for the answer. The answer posted in this link I want to have a single text box and when i... a provision to attach multiple images/files like in gmail. Is there any solution
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
upload files to apache ftp server - Ajax
upload files to apache ftp server  hi,sir I want to upload multiple files to apache ftp server. I am using ajax framework for j2ee.Now I am okay for my customize code for my ftp testing.But I want to upload and download to ftp
upload images - JSP-Servlet
upload images  How to write the jsp code to upload images...://www.roseindia.net/jsp/upload-insert-csv.shtml Thanks... to upload any file therefor it can also upload an image and can insert
urgent need for jsp code with mysql query for uploading and downloading file - JSP-Servlet
urgent need for jsp code with mysql query for uploading and downloading file  can anyone tell me how to upload and download a doc file using jsp with mysql as the back end... and kindly help me to create the table too
 

 

 

DMCA.com