Solved

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

Posted on 2009-07-02
6
333 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
Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

 
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

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

687 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