Avatar of clo1
clo1

asked on 

Servlet, how to download file?

I have generate an excel file from my servlet, under my document root's download directory, but how do I prompt the IE / user to save this xls file when they click on the link which will launch my servlet call. Please help. Thanks !
Java EEJava

Avatar of undefined
Last Comment
jmarrara
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Mayank S
Mayank S
Flag of India image

Does your Servlet display something on the browser? You can have a hyper-link to the excel-file there. When the user clicks on it, it will prompt for download.
Avatar of clo1
clo1

ASKER

Thanks CEHJ, it work perfectly in my OWN development environemnt, which is WinXP + Tomcat 5.0. But once I have uploaded to my production server (RedHat 9.0 + Tomcat 4.1.27), it does not success anymore. Even I have preset the filename for it, it doesn't allow me to download it. Any ideas? Please help. Thanks a lot !
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

What IS happening exactly?
Avatar of clo1
clo1

ASKER

It can prompt to save the file, but it is not the filename I preset from the servlet, it just prompt out another html page's name. And once I click on it, it gives me error message said it cannot be download, etc.... Please help. Thanks !
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Have you followed the example in that article exactly?
SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Mayank S
Mayank S
Flag of India image

>> it is not the filename I preset from the servlet

What file-name does it show and what file-name do you give in the Servlet? I guess it should show the original file-name.
Avatar of Mayank S
Mayank S
Flag of India image

Ok with me.
Avatar of jmarrara
jmarrara

It worked fine to me.
Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo