How to Download a file from web server using servlets

how do we download a file from Java Web Server connecting to oracle database
it should start as soon a i click a button in my html browser
please reply as it is needed to complete my project to submited to the collage

With SQLJ you can do it.
When you look at:
http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/basic/basic.htm
or
http://otn.oracle.com/sample_code/tech/java/sqlj_jdbc/files/advanced/advanced.htm
There are samples for reading LONGRAW / BLOB from Database. If you want use it in servlet you have to pass the result to the responce object, set the correct mime-type and set the response.setContentLength( xx). This is for some PlugIns nessessary (pdf).
regards Dietmar

Similar Messages

  • How to download a file from other server using servlet

    Hi All....
    Good Morning....
    right now,i am facing a problem..i am trying to download a file which is in other server..i tried somany ways and i couldnt succeed in this...
    will u pls give me solution for this..
    because it is very urgent for me...
    i am very much thankful if u provide me the code samples also....
    i am seeking ur help...
    Regards,
    sathya

    right now,i am facing a problem..i am trying to download a file which is in other server..i tried somany ways and i couldnt succeed in this...If you can tell some of our approaches and the failures you faced, someone might be able to help you.
    I dont think anyone will just give the code samples.

  • How to download a file from the internet using terminal

    how to download a file from the internet using terminal
    does any one know how to download afile from the internet using the Terminal application?

    Use curl. Something like this:
    curl -O http://www.example.com/filename.zip
    For more info, type +man curl+.

  • How to download a file from application server to presentation server

    Hi experts,
    I want to download a file from application server to presentaion server, file contaims three fields customer name, customer email id and status..
    help me out i m new into sap.

    Dear Aditya,
    Please check below thread
    http://scn.sap.com/thread/1010164
    it will help you.
    BR
    Atul

  • How to download a file from application server in webdynpro

    Hi Experts,
                       I am trying to download a file through Web Dynpro file download UI element..The file is stored in application server in binary format ..in my code i am reading the file in binary mode,converting Binary File into Xstring(Using FM SCMS_BINARY_TO_XSTRING) ..getting its Mime type and binding the UI element properties (data with XString, Mime type and file name) with respective context attributes..But the problem is file is getting opened but Junk data is getting displayed on it..Not sure where i am making the mistake.

    Hi Lukas,thanks for the reply..please find the code
    here '/tmp/accenturedocs'  is the folder name on application server,and zdocs_list_tab is the table that contains file URL.File upload is on the BSP page (custom logic to upload the file ) where they are storing local file path in ztable.Same i am extracting in my code to get File URL.
    DATA: i_file TYPE rlgrap-filename .
      DATA:v_path TYPE zlist.
      DATA:i_datatab TYPE STANDARD TABLE OF tbl1024,
           wa_datatab TYPE   tbl1024.
      DATA  file TYPE  string.
      DATA dot_offset TYPE i.
      DATA extension TYPE mimetypes-extension.
      DATA mimetype TYPE mimetypes-type.
      SELECT SINGLE description
        FROM  zdocs_list_tab
        INTO v_path.
      CONCATENATE '/tmp/accenturedocs' v_path INTO i_file.
      FIELD-SYMBOLS <hex_container> TYPE x.
      OPEN DATASET i_file FOR INPUT IN LEGACY BINARY MODE.
      IF sy-subrc NE 0.
        MESSAGE e999(00) WITH 'Error opening file' .
      ENDIF.
      ASSIGN  wa_datatab TO <hex_container> CASTING.
      DO.
        READ DATASET i_file INTO <hex_container>.
        IF sy-subrc = 0.
          APPEND wa_datatab TO i_datatab.
        ELSE.
          EXIT.
        ENDIF.
      ENDDO.
      CLOSE DATASET i_file.
      DATA:l_count TYPE i,
            l_len TYPE i.
      DESCRIBE TABLE i_datatab LINES l_count.
      READ TABLE i_datatab INTO wa_datatab INDEX l_count.
      l_len = XSTRLEN( wa_datatab-line ).
      l_len = l_len + ( l_count - 1 ) * 1022.
    DATA: v_xstring TYPE xstring.
      CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
        EXPORTING
          input_length = l_len
        IMPORTING
          buffer       = v_xstring
        TABLES
          binary_tab   = i_datatab
        EXCEPTIONS
          failed       = 1
          OTHERS       = 2.
      IF sy-subrc <> 0.
      ENDIF.
    file = i_file.
      " Find out file name extension
      FIND FIRST OCCURRENCE OF REGEX '\.[^\.]+$' IN file MATCH OFFSET
      dot_offset.
      ADD 1 TO dot_offset.
      extension = file+dot_offset.
      " Get mime type
      CALL FUNCTION 'SDOK_MIMETYPE_GET'
        EXPORTING
          extension = extension
        IMPORTING
          mimetype  = mimetype.
    DATA lv_file_content TYPE wd_this->element_context-file_content.
    get element via lead selection
      lo_el_context = wd_context->get_element( ).
    set single attribute
      lo_el_context->set_attribute(
        name =  `FILE_CONTENT`
        value =  v_xstring ).
    same way i am assigning file name and file mime type to context attributes.
    please suggest where is the mistake.

  • How to download a file from Middleware server

    Hi,
    I have a requirement to list file names in a table layout and when user clicks on file name, file must be downloaded to the client tier. Source files are located in 11i Apps middletier.
    I did not find any examples on how to achieve this using OAF. All I see is downloading file from BLOB inside a database.
    please help..

    OAMessageDownloadBean is the bean that lets you download a file from middletier.
    Please see the File Upload and Download chapter in devguide for implementation details.
    Thanks
    Tapash

  • How to download a file from Oracle UCM using OSB

    Hi,
    How can I download a file from Oracle UCM and save it on a filesystem using OSB 11.1.1.5.
    Thanks

    UCM supplies webservice interfaces which let you retrieve the filecontent by soap calls from UCM (http://ucmhost/_dav/cs/idcplg for example). (maybe you should enable some settings on ucm to have this webservice interface getting published).
    This services for example has 2 operations getFileByID and getFileByName.
    So you can just call these services from within OSB.
    After that you need to do some tests if you eitherway need to create a file-transport business-service and call this one from your proxy service or create a messageType proxyservice (binary)  which calls this file-transport business service to be able to write fo filesystem.
    I think for the OSB book i used a jca file adapter generated in Jdeveloper and used that one to write to filesystem.

  • How to download UCM file from adf UI using fileDownloadActionListener  ?

    Hi All,
    I need to download file from UCM.can any one please give some code snippet.
    my use-case is:
    In ADF UI I have table so from one of the column having link.when I click on link I have to download the file.I my table I have resourceId as a field.Please give me some code for the same.
    If I use fileDownloadActionListener on command link on the resourceID.
    Regards
    Shankar

    Hi Ramadeep,
    Thanks for your quick help.I am able to do the same with dDocName.but I m facing problem while setting contentType means MIME type to file. I am usig the below code for the same but contentType is taking null value.
    please take a lookinto code and give mw some solution.
    is this code is file or can I optimized.
        public void downloadFileUCM(FacesContext facesContext,
                                    OutputStream outputStream) {
            IdcClientManager manager = new IdcClientManager();
            IdcClient idcClient;
            try {
                idcClient = manager.createClient(IDC_URL);
                IdcContext userContext = new IdcContext(USER);
                DataBinder dataBinder = idcClient.createBinder();
                dataBinder.putLocal("IdcService", "GET_FILE");
                 dataBinder.putLocal("dDocName", ucmResourceId);
                dataBinder.putLocal("RevisionSelectionMethod", "LatestReleased");
                ServiceResponse responseString =
                    idcClient.sendRequest(userContext, dataBinder);
               setContentType(responseString.getHeader("Content-Type"));
                String contentType=responseString.getHeader("Content-Type");
                System.out.println("contentType:"+contentType);
                 InputStream inputStream = responseString.getResponseStream();
                byte[] buf = new byte[1024 * 256];
                long i = 0;
                int len;
                System.out.println("Downloading File from UCM Server");
                while (true) {
                    i++;
                    len = inputStream.read(buf);
                    if (len == -1) {
                        break;
                    outputStream.write(buf, 0, len);
                outputStream.flush();
                inputStream.close();
                outputStream.close();
                facesContext.responseComplete();
            } catch (IdcClientException ice) {
                System.out.println("IDC Client Exception occured. Exception message: " +
                                   ice.getMessage());
            } catch (IOException ioe) {
                System.out.println("IO Exception occurred. Unable to retrieve file. Message: " +
                                   ioe.getMessage());
            } catch (Exception ex) {
                System.out.println("Exception message: " + ex.getMessage());
        }Regards
    Siva

  • How to download a file from a server path?

    Is it possible to attach files on the server to a web dynpro response with cl_wd_runtime_services=>attach_file_to_response? All the examples I have seen assume you have the file content as an XSTRING. But how can one just send a file from a known path?
    Is it really necessary to first load the file (e.g. a 50Mb TIFF) as an XSTRING before downloading it? If so, how is this done?

    Hi Marc,
    Try using this FM to convert String to Xstring.
    SCMS_STRING_TO_XSTRING
    HR_KR_STRING_TO_XSTRING
    and also check this...Error document.getElementById(...)  in function 'SCMS_STRING_TO_XSTRING'
    Might Helps you.
    Cheers,
    Kris.

  • How to download a file from a server

    Hi,
    I have a question with a general design implementation. Hope anyone more skilled than me helps me.
    I want to do an application based on an android client and a java server. Local wifi transmission, no 3G.
    Basically, the client must connect to the server and request a file to download using a code.
    How can I do that?
    Things I know:
    * I must create a background thread in the client to create a file in the SD card and update a progress bar using a Handler to communicate with the UI thread.
    * The server must be multithread and non-blocking.
    * The file is a binary file like a mp3 audio. So the server has to:
    1. Send information about the file: name and total length.
    2. Open the file, read and send bytes while it does not reach the end.
    * The client has to:
    1. Receive the information about the file and create an empty file.
    2. Read bytes and dump them into the empty file. Update progress bar.
    3. When all bytes are recieved close the file.
    I have knowledge implementing a client and server in C (very awful) but I am beginning with a real client-server application done in java.
    Questions:
    * How can I download a binary file like an mp3 from a server to a client?
    * Where I have to put my server application? I supose that I must create a jar, save it on a folder and execute it at PC start-up, right?
    Thanks!
    PD: I know this is not an android forum but I only need help with the download process.
    Edited by: user13425637 on 06-dic-2010 11:08

    Questions:
    * How can I download a binary file like an mp3 from a server to a client?There are a ton of examples on the internet on how to download files. If you are having a problem, please post your code.
    >
    * Where I have to put my server application? I supose that I must create a jar, save it on a folder and execute it at PC start-up, right?Your server application will exist on a server and will run the application. hence the reason for the server. The best best for you is to read some online tutorials on client/server and how it works.

  • How to download a file from Web-URL to local HD

    Hy,
    I am trying to download a picture from a specific URL such as
    "http://ia.imdb.com/media/imdb/01/I/66/16/02m.jpg"
    to my local HD, but I only have experience in downloading text based files, such as HTML using the BufferedReader method and a URL object to read the text based HTML file and PrintWriter to write the file on my HD. I have a hard time finding a good tutorial on this, so I would be more than happy to get any help from you guys, the cherry on the cake would of course be a code sample for demonstration...
    Please!

    Use BufferedOutputStream and BufferedInputStream rather than
    BufferedReader and BufferedWriter.
    Should be the same otherwise.

  • Help Downloading a file from a server using FTP with only URL methods

    Hi All
    I have written this code and it is not working I dod not know why the download is not working please help is there anything that's missing?
    * Download the file
    public void download(String fileName, String destination)
           BufferedInputStream bis = null;
           BufferedOutputStream bos = null;
          // File destDir = null;
           try
               String urlString = "ftp://"+userName+":"+password+"@"+hostName+"/"+fileName;
               URL url = new URL(urlString);
               URLConnection conn = url.openConnection();
               conn.setDoOutput(true);
         conn.setDoInput(true);
               conn.connect();
           //set the destination directory
           File destDir = new File("U:\\2004\\"+fileName.trim());
            System.out.print("\n\n");
            System.out.print("Destination set to :" +destDir);
            System.out.print("\n\n");
              bis = new BufferedInputStream( conn.getInputStream() );
              bos = new BufferedOutputStream( new FileOutputStream(destDir.getName()));
              System.out.print("get file name :" +destDir.getName());
              System.out.print("\n\n");
              int i;
              while ((i = bis.read()) != -1)
                 bos.write( i );
              System.out.println("Trying to download...");
              bis.close();
              bos.close();
           catch (IOException ie)
         System.out.println( "Input not available" );
    This is what I get after runing this code.
    get umlcourse.txt U:\2004
    Destination set to :U:\2004\umlcourse.txt
    get file name :umlcourse.txtTrying to download...

    AceV wrote:
         String urlString = "ftp://"+userName+":"+password+"@"+hostName+"/"+fileName;
    You probably need to specify the transfer mode. For example:
    String url = "ftp://sam:spade@ftphost/myfile.txt;type=a";
    // Specify type=i for binary.

  • How to attach a file to tomcat server using SERVLETS

    Hello friends,
    I want to enable users to attach a file and send it to my server. This is a very common feature seen anywhere like e-mail attachments.
    Iam using tomcat server. I tried HTTP put but it did not work.
    Please give some suggessions.
    Thanks
    Goldy

    check this url:
    http://www.servlets.com/cos/index.html
    follow the link MultiPartRequest
    Spieler

  • 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

  • How to delete a file on web server without using FTP

    Hi All
    I hv given a facility to a site user to upload some files..
    And an interface to web administrator to view all the files..
    I want to know how can i write a code in JSP which allow the web administrator to delete any of that file which is not of his/her interest through provided interface only.
    OR
    Is it possible to delete a particular file from web server without getting login into FTP account
    Thanx

    new File(strFileName).remove;
    Simply as this.
    Don't forget to import java.io.FileInputStream.

Maybe you are looking for

  • Logic Pro 9.1.4 crashes after upgrading to Snow Leopard (10.6.8)

    After upgrading my operating system from Leopard to Snow Leopard, Logic crashed on me just I got into the arrange screen. I'm not sure what the problem is. I tried reinstalling it but it doesn't seem to work. I am running it in 32-bit mode on a Imac

  • Creating Dependent Radio Boxes in Acrobat 9 Std

    When creating a form in Acrobat 9 Standard, how can you make radio boxes dependent on each other? For instance, one item in my form asks a question and the user can choose a "Yes" or "No" radio box.  I want to prevent the user from being able to chec

  • How to create greater_or_equal condition for file_io storage

    Dear experts, Please tell me the how to create greater_or_equal condition for query in file_io as RationalOperatorType.GREATER_OR_EQUAL is not supported for file_IO storage. thanks n regards, Kapoorchand.

  • Web sites containing mms links work in IE but not Firefox 4.0

    Web sites containing mms links work in IE but not Firefox 4.0. when I play the video in IE, I go into IE, and locate the mms link under properties, when I right click. If I copy the mms link form IE directly into firefox, it will work. There ought to

  • Mac mini with laptop PC

    Hey! Have tried to find answers on this with google, but have not find an satisfying answer, so I hope you guys can help me. I have a laptop PC with no external keyboard, mouse and monitor. I really want to start making iOS apps using xcode and was t