Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. how to transfer PDF file from servlet on server to client

how to transfer PDF file from servlet on server to client

Scheduled Pinned Locked Moved Java
sysadmintutorialquestion
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    williamroma
    wrote on last edited by
    #1

    hi how are you all (SORRY FOR MY BAD ENGLISH) i have a server (localhost) and want to send pdf file from my servlet on server to the client how can i do it thank you very much :)

    B 1 Reply Last reply
    0
    • W williamroma

      hi how are you all (SORRY FOR MY BAD ENGLISH) i have a server (localhost) and want to send pdf file from my servlet on server to the client how can i do it thank you very much :)

      B Offline
      B Offline
      bennis98
      wrote on last edited by
      #2

      response.setHeader("Content-type","application/pdf");
      response.setHeader("Content-Disposition","attachment; filename=\"destination filename\"");
      BufferedOutputStream bo=new BufferedOutputStream(response.getOutputStream());
      byte buffer[]=new byte[1024];
      FileInputStream fis=new FileInputStream("File in server");
      while(fis.read(buffer)>0){
      bo.write(buffer);
      }
      fis.close();
      bo.close();

      W 1 Reply Last reply
      0
      • B bennis98

        response.setHeader("Content-type","application/pdf");
        response.setHeader("Content-Disposition","attachment; filename=\"destination filename\"");
        BufferedOutputStream bo=new BufferedOutputStream(response.getOutputStream());
        byte buffer[]=new byte[1024];
        FileInputStream fis=new FileInputStream("File in server");
        while(fis.read(buffer)>0){
        bo.write(buffer);
        }
        fis.close();
        bo.close();

        W Offline
        W Offline
        williamroma
        wrote on last edited by
        #3

        ty very much for help plz can u tell me how to catch the in the client

        B 1 Reply Last reply
        0
        • W williamroma

          ty very much for help plz can u tell me how to catch the in the client

          B Offline
          B Offline
          bennis98
          wrote on last edited by
          #4

          The codes written is used to send back response to client and it is compliant with html... So you just use the browser, surf to the site with the above code and you will get the file...

          W 1 Reply Last reply
          0
          • B bennis98

            The codes written is used to send back response to client and it is compliant with html... So you just use the browser, surf to the site with the above code and you will get the file...

            W Offline
            W Offline
            williamroma
            wrote on last edited by
            #5

            but first i have to catch the file in Client side have i use Inputstream or what ? ty for help

            B 1 Reply Last reply
            0
            • W williamroma

              but first i have to catch the file in Client side have i use Inputstream or what ? ty for help

              B Offline
              B Offline
              bennis98
              wrote on last edited by
              #6

              In fact, this question may not be in this forum. Because, it is all about web and html you can use .... to upload the file ... and in server side, you can use request.getInputStream()..... or use third party library to handle upload request as ref site: ref: http://www.andowson.com/posts/list/197.page

              D 1 Reply Last reply
              0
              • B bennis98

                In fact, this question may not be in this forum. Because, it is all about web and html you can use .... to upload the file ... and in server side, you can use request.getInputStream()..... or use third party library to handle upload request as ref site: ref: http://www.andowson.com/posts/list/197.page

                D Offline
                D Offline
                David Skelly
                wrote on last edited by
                #7

                But he doesn't want to upload the file from the client to the server. He wants to download the file from the server to the client. Completely the opposite way round from your answer.

                B 1 Reply Last reply
                0
                • D David Skelly

                  But he doesn't want to upload the file from the client to the server. He wants to download the file from the server to the client. Completely the opposite way round from your answer.

                  B Offline
                  B Offline
                  bennis98
                  wrote on last edited by
                  #8

                  So you need the permission of that client and he/she open a port for you : java.net.Socket s=new Socket(); s.connect(new InetSocketAddress(InetAddress.getByName(hostname),portNo)); s.getInputStream(); ...... Or remote login to that computer, it is depends on what methods that computer use to get the connection.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups