how to transfer PDF file from servlet on server to client
-
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 :)
-
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 :)
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(); -
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();ty very much for help plz can u tell me how to catch the in the client
-
ty very much for help plz can u tell me how to catch the in the client
-
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...
but first i have to catch the file in Client side have i use Inputstream or what ? ty for help
-
but first i have to catch the file in Client side have i use Inputstream or what ? ty for help
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
-
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
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.
-
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.
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.