473,407 Members | 2,314 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Download

Hi
Actually I have a functionality that can upload a file to some loaction and the name of the file to the database.
Now I want to download that file through java struts.
Is that possible.Can any one help me out.

What i did is i retrieved the name of the file from databse and displayed it int the form of a table using jsp.Now i have to create a link for the file name and be able to view it
please help me out in this regard..

Thanks
Feb 7 '08 #1
6 1477
i wrote a code like this....

File fileUpload = new File(strUploadDirectory+"\\"+strFile_Name);
FileInputStream fileIn = new FileInputStream(fileUpload);
OutputStream fout=response.getOutputStream();
//((ServletResponse) fout).setContentLength((int) fileUpload.length());
byte[] buffer = new byte[8192];
int bytesRead = fileIn.read(buffer);

while (bytesRead >= 0) {
if (bytesRead > 0)
fout.write(buffer, 0, bytesRead);
bytesRead = fileIn.read(buffer);
}

the file which i want to retrieve is comming but the problem is the actual data in the file is displayed as some other form which we cant understand...

how to resolve this problem?????

fout.flush();
fout.close();
fileIn.close();
Feb 8 '08 #2
BigDaddyLH
1,216 Expert 1GB
Have you HttpServletRespose.setContentType?
Feb 8 '08 #3
Have you HttpServletRespose.setContentType?

Hi
Thank u for the reply i tries implementing it but im getting an exception
java.lang.ClassCastException: com.planetj.servlet.filter.compression.Compressing ServletOutputStream

what could be the problem????
Feb 11 '08 #4
Hi
I could resolve the problem.Now its working very fine with .doc , .txt,.xls etc but there is some problem with the .pdf files... when im trying to download it is throwing this exception
java.net.SocketException: Connection reset by peer: socket write error

What could be teh problem???

Thanks
Feb 11 '08 #5
r035198x
13,262 8TB
Hi
Thank u for the reply i tries implementing it but im getting an exception
java.lang.ClassCastException: com.planetj.servlet.filter.compression.Compressing ServletOutputStream

what could be the problem????
That means you are trying to type cast to a type that is incompatible with the type you are casting from.
Are using a servlet?
Feb 11 '08 #6
That means you are trying to type cast to a type that is incompatible with the type you are casting from.
Are using a servlet?

Hi
I could resolve that problem. i used the HttpServletResponse obj only..Now its working very fine with .doc , .txt,.xls etc but there is some problem with the .pdf files... when im trying to download it is throwing this exception
java.net.SocketException: Connection reset by peer: socket write error

What could be teh problem???

Thanks
Feb 11 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: chon | last post by:
I have an ASP page that is sent a file location as a parameter. It opens this file, loads the ADODB.Stream object and does a binary write to the page forcing the download dialog to appear. This...
0
by: jmd | last post by:
Hello. I want to write a C# program that does completely automatically what, until now, I do manually, witch is describe below : 1. I launch IE (6) 2. I browse to my desired download page, say...
0
by: Buddy Ackerman | last post by:
I am trying to implment a file download via a link such that when clicked, instead of starting the default application for that type of file the user will be presented with a download dialog...
3
by: Nathan Sokalski | last post by:
I have a webform that contains a button which I want to do three things: 1. Delete a record from a database 2. Let the user download a text file that is generated 3. Refresh the page to show...
18
by: jmd | last post by:
Hello, I posted the following in the C# forum but without one answer. But perhaps now in vb.net someone has some guidelines ! This is my question : I want to write a vb.net program that does...
1
by: a.r.austin | last post by:
Hello, I am trying to download a few files one after another from a remote server. Problem is that I don't know how to, or if I am able at all, set a time out for download. I don't want to time...
16
by: matt | last post by:
I have used some free code for listing files for download, but I want to send an email to the administrator when the file has been downloaded. I have got some code in here that does it, but it will...
1
by: JayLembeck | last post by:
Over 50,000 Free Ringtone. Get the Latest Ringtone. Download now- Fast, Free and Easy. Get your FREE surprise RINGTONE now! http://seekoutfast.info/free-ringtone/ free ringtone free ringtone new...
5
by: Khafancoder | last post by:
Hi guys, i am building a FileSharing website, i wanna allow users to be able using download managers such as DAP to download files from webserver but don't allow them to retrive files url......
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.