?
Solved

Client side Download? Need user to be able to download files!

Posted on 2009-07-02
6
Medium Priority
?
334 Views
Last Modified: 2012-05-07
Hi Experts.

I am building a web application using Java, JSF, IceFaces, and Apache Tomcat.

In this application, at some point I need the user to be able to download a file uploaded on to the server. I have tried a few examples online but none of them have been of success.

Essentially, the user should be able to open/download the file when they click its link (usually a commandLink tag or anything similar). I have some knowledge about this topic. The examples I saw online led to the browser handling the downloading (like FireFox and IE prompting a user to either "save" or "open" the file in a pop-up box). That or anything similar would be great.

Please help me complete this task by a useful sample code, instructions, and/or some website links.

Thanks in advance!
0
Comment
Question by:kingsha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 24769238
<a href="/someaction.do?attchmntId=1&atthFileName='EE_JSP.txt'">EE_JSP.txt</a>

>>someaction.do

 byte docBytes[] =readBlob(request.getParameter("attchmntId"));
            if (docBytes != null)
            {
                response.setHeader("Content-Disposition","attachment;filename=\""+ request.getParameter("atthFileName")+ "\";");
                response.setContentType("application/save-as-dialog");
                OutputStream outStream;
                try {
                    outStream = response.getOutputStream();
                    outStream.write(docBytes);
                    outStream.close();
                } catch (IOException e) {
               //log error
                }
            }

Hope this helps.

-Murali*
0
 
LVL 7

Expert Comment

by:nikhilmenon
ID: 24787918
Well perhaps a slightly easier way to do this is to directly provide a link to the file on your webpage. If you have everything saved on the server at "MyWebApp/xyz.jpg" you could merely add code similar to:

<a href="http://mysite.com/MyWebApp/xyz.jpg">Download the file!</a>

Cheers.
0
 
LVL 2

Author Comment

by:kingsha
ID: 24790915
Hi guys. Thanks for the replies. Have been busy with other stuff but wIll try these out ASAP. Will get back to you.
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 2

Author Comment

by:kingsha
ID: 24796339
@ nikhilmenon

I tried your suggestion but cannot get it to work. I have tried placing a sample jpeg file called "pic1" into just about every folder in the apache servers directory. But still nothing doing.

For example:
<a href="http://localhost:8080/wtpwebapps/bronte/stuff/pic4.jpg">Download the file!</a>

WIll try to implement Murali's suggestion now.
0
 
LVL 2

Author Comment

by:kingsha
ID: 24796658
@ murali

What class are you using for the "request" and "response" functions you mentioned in your code. Java suggests certain libraries but all of them give me errors.

P.S...i raised points for this question to the max i have. I hope that attracts more help :(
0
 
LVL 2

Accepted Solution

by:
kingsha earned 0 total points
ID: 24798094
OK finally I got it! :D

Unfortunately none of the solutions provided worked for me. Muralis solution called for implementing a servlet to handle the downloading. I am completely unaware of how a servlet works and could not get his method to work.

The easier and most efficient solution was to use an iceFaces attribute. Its called an outputresource attribute. Here is a link for more information:
http://pillcase.blogspot.com/2008/11/how-to-use-iceoutputresource-in.html

Cheers everyone. Appreciate the input though.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
This video teaches viewers about errors in exception handling.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question