How to let user download a file from server.

Hello everyone!!!
I am developing a website.I want users to download file(say mp3) from my website.
How can I do this?
I am using jsp with Tomcat server.
Is this possible using only html?
Pls reply immediately.
Looking forward for help.
Thanks in advance.

Actually it s is working only for default directory.if the file is in another directory,is is not working. Then you must have messed up something.
(I hope the clarity, the usefulness and the level of details of my answer match those in the question.)

Similar Messages

  • How to let user download multi files at the same time in WebDynpro ABAP?

    hi all:
    As you know, WeyDynpor has provided upload/download UI element, but it seems that it only support one file upload/downlaod at the same time.The following is the API method to download one file in Webdynpro:
        cl_wd_runtime_services=>attach_file_to_response(
         EXPORTING
           i_filename      = lv_filename
           i_content       = lv_content
           i_mime_type     = lv_mine_type
           i_in_new_window = abap_true
           i_inplace       = abap_false
    *      EXCEPTIONS
    *        others          = 1
    but if when use click one button, we want to provide user a html file plus 2 icons files which are used as this html file's resource file, then how to let user download these 3 files together at the same time?
    one simple way is calling the download api (cl_wd_runtime_services=>attach_file_to_response) 3 times,
    but it is very ugly that three popup windows are shown to let user select every file's download path, which is unaccepted.
    So anyone know more convienient way to handle it?
    thanks.

    Hi,
    I suggest you to zip the files and attach it to the response. Do the add file part for each of your files
         "References
         DATA lr_zip TYPE REF TO cl_abap_zip.
         "Variables
         DATA lv_zip_xstring TYPE xstring.
         DATA lv_zip_name TYPE string.
         DATA lv_file_content TYPE xstring.
         DATA lv_file_name  TYPE string.
         "Create instance
         CREATE OBJECT lr_zip.
         "Add file
         lr_zip_attachments->add(
           EXPORTING name = lv_file_name
                  content = lv_file_content ).
         lr_zip_attachments->save( RECEIVING zip = lv_zip_xstring ).
         "Attach zip file to response
         cl_wd_runtime_services=>attach_file_to_response(
           EXPORTING i_filename      = lv_zip_name
                     i_mime_type     = 'ZIP/APPLICATION'
                     i_content       = lv_zip_xstring ).

  • How to download a file from server machine to client machine using jsp

    Hi,
    In my application, I have an excel file stored on my server machine. How can I download that excel file on to my client machine using jsp. Is there any other way I can open that file from my machine and save it in my machine using jsp/java?
    Its an emergency for me to do this.
    Can anyone provide me the full code to download a file from server machine as I don't have
    time to browse through various sites.
    thanks in advance,
    Tiijnar

    Please post your code using code tags (click on CODE above the text area, when posting)
    response.setContentType("application/octet-stream");Why octet-stream? Set the correct mime-type.
    String disHeader = "Attachment; Filename=\"filename\"";The filename should just be the file's name. Not the complete path to the file! This will tell anyone where the file is located on the server. It's also inconvenient because by default,the browser will suggest it as the name for the download.
    Your way of writing to the output stream is just plain wrong. See this snippet (picked from [http://balusc.blogspot.com/2007/07/fileservlet.html])
            BufferedInputStream input = null;
            BufferedOutputStream output = null;
            try {
                // Open streams.
                input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);
                output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
                // Write file contents to response.
                byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
                int length;
                while ((length = input.read(buffer)) > 0) {
                    output.write(buffer, 0, length);
                // Finalize task.
                output.flush();
            } finally {
                // Gently close streams.
                close(output);
                close(input);
            }

  • How to upload and download any file from plsql through weblogic server

    hi all,
    how to upload and download any file from plsql through weblogic server? i am using oracle 10g express edition and jboss.
    Thanks and Regards,
    MSORA

    hi bala ,
    for a windown server u can use VNC (virtual network connection) which opens a session on u r desktop later u can drag and drop form there vice versa and for a linux box you can use Win SCP which helps to open a session with interface to u r desktop in both cases you can upload and down load files very easiy just as we drag and drop items in a simple pc .. we use the same technique...
    bye
    vamshi

  • Applet question, how to download resource files from server

    hi,
    i am new at applet world.
    i have an applet that reads some resource, data and configuration files. so i need to download these files from server to client. i did some resarch and could not find how to download files from server in an applet application.
    how can i do this task?
    thank you for your answers.

    You may want to distinguish between 'resources' and data/configuration files.
    'Resources' are non-class files that are part of your application, i.e without them the application would simply not work, just like class files.
    Those are typically images, sounds or resource bundles (GUI elements translated to different languages) that nobody except you, the developer, would touch (when releasing an upgrade or a patch).
    Those should just go into the applet jar or additional jars named in the applet tag.
    Data/configuration files, that may be changed by others than the developers, should be made available through HTTP, just like the applet jar itself. The applet will have (read) access to them using java.net.URLConnection.

  • How to download a file from server?

    Hi everyone,
    I need to download a file from my server to client machine. I got a sample code from ur forum and I modified it slightly.
    //Snippet of code:
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws
         ServletException, IOException{
    int bytesRead=0;
         int count=0;
         byte[] b1=new byte[1];
         //OutputStream out=res.getOutputStream();
         res.setContentType("application/html");
         //Create an input stream from file URL.
         String fileURL="http://localhost:8080/webapps/upload/upload.html";
         BufferedInputStream bis=null;
         BufferedOutputStream bos=null;
         boolean download=false;
         res.setHeader("Content-disposition", "attachment; filename=upload.html " );
         try{
         URL url=new URL(fileURL);
         URLConnection connection=url.openConnection();
         InputStream in=connection.getInputStream();
         bis=new BufferedInputStream(in);
         FileOutputStream fileout=new FileOutputStream("upload.html");
         bos=new BufferedOutputStream(fileout);
         while(-1 != (bytesRead = bis.read())){
         try{
         bos.write(bytesRead);
         bos.flush();
         }//end of try forwhile loop
         catch(SocketException e){
         setError(e);
         break;
    The code is getting compiled, when I run the appln using the URL,
    http://localhost:8080/upload/servlet/DownloadFile
    it opens a pop up dialog box, asking whether to "open", "save" or "cancel" buttons. When I try to open a file, I'm getting a blank page.
    I'm not getting the contents of the file.
    So pls can anyone tel me wht's wrong in the code or do i need to add few more lines in my code?
    Also pls let me know, how can I download any files of type .doc, html, .txt, .zip, or any type, without mentioning the file type?
    Thanks in advance

    Do not use a FileOutputStream (that will save it locally to the server). Call HttpServletResponse.getOutputStream(), which will send it back to the browser. Also remember to call close() on the stream at the end.
    - Saish

  • SetHeader problem when user downloads a file from a server

    Hi everyone,
    I have a question about the way to let a user download a file. A created a jsp that handles the download. This is the code:
    <%@ page import="java.io.*" %><%
        response.setHeader("Content-Disposition", "attachment; filename=" + session.getAttribute("executedCommand").toString());
        response.setContentType("text/csv");
        int iRead;
        FileInputStream stream = null;
        try {
            File f = new File(session.getAttribute("executedCommand").toString());
            stream = new FileInputStream(f);
            while ((iRead = stream.read()) != -1) {
                out.write(iRead);
            out.flush();
        }finally {
            if (stream != null) {
                stream.close();
    %>When I run this, I get a download window, so that the right file can be downloaded, but I would like the application to show me the name of that file in the download window and in my save dialog, and that's something I haven't managed to do yet, because I always get the name of the servlet (that redirects to the jsp page). So the problem is, the right file is downloaded but it's name is never shown in the download window. How can I resolve that?
    Thanks for your help!
    E_J

    I forgot to say that my session variable contains the absolute path of the file the user can download. Maybe using session variables is not the best solution in this case, but it should have to work, shouldn't it?
    Still waiting for some help. I really appreciate it...
    E_J

  • Windows 2008 : How to Restrict Users to Copy file from Shared Folder

    Hello All,
    I need to Restrict Users to Copy file from Shared Folder. Please let me know is there any method to achieve this requirement.

    If user have Read permission, they can copy it. So actually you cannot restrict user from copy your files if they could read/edit.
    Some programs could help restrict users from edit/modify/copy the content of their files such as Office files, PDF files etc as Oscar said above.
    TechNet Subscriber Support in forum |If you have any feedback on our support, please contact [email protected]

  • How can i download many file from server one times.

    Hi,
    I want to create the service to download multi-files from web server one time
    from browser. It seems no way to do it. My soulition is compressing the files
    to zip before download it. The problem is that when the user uncompresses the
    files,full path of downloaded files are setted. Look like this:
    /usr/tmp/test/file1
    /usr/tmp/test/file2
    /usr/tmp/test/file3
    My question is :
    1. Is there any way not to specify the full path of a file when
    add the file to zip.
    Here is the source
    BufferedInputStream bis
    = new BufferedInputStream(
    new FileInputStream( file ) );
    //if not full path . can is works?????
    ZipEntry target = new ZipEntry( file.getPath() );
    // zos is ZipOutputStream
    zos.putNextEntry( target );
    int c;
    while( ( c = bis.read() ) != EOF ) {
    zos.write( (byte)c );
    2. Is there any way to get and change the current work directory of my server ?
    Please help!!

    If i use file.getName(). I will lost the struct of path.
    I means that,if i compress the list of files:
    /usr/tmp/test1/file1
    /usr/tmp/test1/file2
    /usr/tmp/test2/file3
    can i keep the part of path's strcut. (usr/tmp/../.. etc.)
    I tried to do as this:
    target = new ZipEntry( file.getPath.substring(1));
    an error be reported when uncompressed the zip file.
    error message:
    warning [zt000002.zip]: extra 28 bytes at beginning or within Zip file (attempting to process anyway)
    Error in file #1: bad Zip file offset (Error local header signature not found): 0
    (attempting to re-compensate)
    Extracting 20030109.xls
    Error: unexpected end of file encountered
    Error: invalid compressed data to inflate
    Why? can i set "any" entry name??

  • Downloading Media Files from server daily at a particular time on a day

    Hi to All,
    Actually I am building an application which downloads all the
    media files from the server(includes both video and images) after
    the download is complete. I will start the slide show of the
    downloaded media files accessing them m locally.
    ow my problem is I have to download all the media files once
    in a day at a particular time on a day from the server(The time is
    set in backend).
    I can acheive this by running a process and connecting to a
    server. But if I close the application window how the process can
    run and how it can download media files from the server daily.
    Is there a way so that I can create two applications one for
    downloading the media files from the server which runs always and
    runs in the background. Another one is my main application which
    displays the media files that are downloaded and saved in the local
    filesystem.
    All suggestions are appreciated.
    Thanks.

    From what I have read you have two options.  None of them very nice.  One , allow the user to select the files he would like to download , send them out as one fat daddy zip file.  The second option is to cue up the selected downloads.  When one finishes , the other starts , basically daisy chaining them together.  However , you may be able to use javascript to get around this , I'm not sure I stay away from that stuff.

  • Getting Exception in JWS while downloading jar files from server

    Hi All,
    I am running JWS on j2re1.4.2_10(build 03). while JWS is trying to download jar files from web server, I am getting the following Exception.
    All the jar files are signed. Any idea ?
    JNLPException[category: Download Error : Exception: null : LaunchDesc: null ]
         at com.sun.javaws.cache.DownloadProtocol.doDownload(Unknown Source)
         at com.sun.javaws.cache.DownloadProtocol.getDownloadSize(Unknown Source)
         at com.sun.javaws.LaunchDownload.downloadJarFiles(Unknown Source)
         at com.sun.javaws.LaunchDownload.downloadEagerorAll(Unknown Source)
         at com.sun.javaws.Launcher.downloadResources(Unknown Source)
         at com.sun.javaws.Launcher.handleApplicationDesc(Unknown Source)
         at com.sun.javaws.Launcher.handleLaunchFile(Unknown Source)
         at com.sun.javaws.Launcher.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

    Are you able to download your *.jar files directly from server
    For example say,
    http://127.0.0.1:8080/test/testme.jarIf yes,
    Then problem should be with your *.jnlp file. Check all your *.jar with respect to context location of your url from where you are downloading *.jnlp file

  • How a User downloads .zip file from CDROM

    Im blanking out here...
    How can a user make a selection ( via button/link ) that will
    download from a CDROM to the desk top a .zip compressed file. Any
    guidance with this is greatly appreciated.
    Thanks!

    HI,
    Yes a FREE installer to do this.
    http://www.flashjester.com/?section=faq&cPath=50#225
    Regards
    FlashJester Support Team
    e. - [email protected]
    w. -
    http://www.flashjester.com
    There is a very fine line between "hobby" and
    "mental illness."

  • How to download a file from server to client m/c

    hi
    my requirement is,
    a form is displayed to user with a download button and
    onclick of download ,user will see a box with options open,save,cancel.
    if user clicks on open /save ,how to get the info about download is complete on client side because i need to set a flag in database ,
    as Downloaded once the download is complete on client side
    my problem is ,in the action of form the path given is of servlet class
    having code of
    setheader and setcontenttype as attachment but on click of download button it is opening the servlet instead of the required file,
    means it is opening the page specified in action of form ,
    what can be done abt it??/

    Please post your code using code tags (click on CODE above the text area, when posting)
    response.setContentType("application/octet-stream");Why octet-stream? Set the correct mime-type.
    String disHeader = "Attachment; Filename=\"filename\"";The filename should just be the file's name. Not the complete path to the file! This will tell anyone where the file is located on the server. It's also inconvenient because by default,the browser will suggest it as the name for the download.
    Your way of writing to the output stream is just plain wrong. See this snippet (picked from [http://balusc.blogspot.com/2007/07/fileservlet.html])
            BufferedInputStream input = null;
            BufferedOutputStream output = null;
            try {
                // Open streams.
                input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);
                output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
                // Write file contents to response.
                byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
                int length;
                while ((length = input.read(buffer)) > 0) {
                    output.write(buffer, 0, length);
                // Finalize task.
                output.flush();
            } finally {
                // Gently close streams.
                close(output);
                close(input);
            }

  • How do I batch download jpg files from a picture hosting site?

    I recently did a reset of Firefox and I am having trouble downloading a new plug-in/add on. Before the resetI I had installed FlashGot(?) which put an icon in the lower right corner of the page. To save a video, I would right click on the icon and choose my download options. I believe it was Flash Got.
    Now I have an icon which shows a greyed out downward arrow with a red X on it. I can't figure it out.
    Also, before the reset, I had an addon that would allow me to download You Tube videos by putting a red download button on any You Tube video. Simple. However, I cannot find that addon either.
    Any help would be greatly appreciated.!
    TIA,
    Jim

    Hi Jim, the icon might mean that the add-on isn't able to get video on that page, I'm not sure.
    The Reset feature usually creates a folder on your desktop named Old Firefox Data. Can you find that folder? If you drill down into your old profile folder and then into the Extensions subfolder, you will find your old extensions there. Unfortunately, the folders usually are named with IDs (long strings of numbers, letters, and dashes) rather than their friendlier names. If you run out of other options, you could Google these IDs to find out which extensions they are associated with.

  • How to upload and download a file in server side program

    Give me a sample code for the file upload and download using Server side program.

    You should try one of these forums for an answer to your question:
    http://swforum.sun.com/jive/forum.jspa?forumID=116
    http://community.java.net/netbeans
    http://linux.java.net

Maybe you are looking for

  • How can I get Photoshop CS4 to open?

    I just got the Adobe Production Suite CS4 Student Edition, I installed it onto my computer (Windows XP Media Center Edition), All of my programs run great except for Photoshop. When I try to open Photoshop it gets to the building twain portioin of th

  • HELP - My website works on everyone else's computers but not my Mac.

    I am having a terrible time trying to access my website - www.missjonesdesign.com I could access it last week, but this week its stopped working on all my browsers, Safari, Firefox and Chrome. I am also having problems with my email, sometimes mail s

  • XI 3.0 Trusted Authentication

    When setting up for Trusted Authentication, the TrustedPrincipal.conf file needs to be added to the BO install.  The documentation (Admin Guide) says that it needs to go to <drive>:\Program Files\Files\Business Objects\ BusinessObjects Enterprise 12.

  • Tab, page order

    On my website designed in adobe muse, the tab to one of my pages comes up in the wrong order.  It started about 6 weeks ago.  It's designed right but the it comes up to the second listing and not the intro page.

  • HT2534 None payment method is not included. Why?

    None Option is not found in payment method. Why?