aspose file tools*
The moose likes JSP and the fly likes Save a pdf or any file to client machine from server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Save a pdf or any file to client machine from server" Watch "Save a pdf or any file to client machine from server" New topic
Author

Save a pdf or any file to client machine from server

Susmitha Metlapalli
Ranch Hand

Joined: May 16, 2007
Posts: 44
Hi,

In a jsp, i have given a link to download a pdf file.

Point No:1

If we set the response content type and attachment etc, the browser pops up a default file download window with open, save and cancel buttons. User can save the respective file to the location and with a different name as per his desire.

Point No:2

Instead of this, i have written my own popup window using awt/swings with open, save, cancel buttons.

In this case, i dont know how to open the respective file, save the content/file coming from response stream to client's machine as it happens in Point No:2

Request you to help me in proceeding further.

Thanks in advance,
Susmitha.
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Hi Sushmita


i am not that familiar with saving the
file on the client machine but for opening
the file you can use the



may be it helps you to some extent.....

SCJP(1.5),SCWCD(On the way)
Dhwani:>Winning is not important but it is the only thing.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
Your point #2 sounds suspicious. Where does this Swing code live - in an applet or Java Web Start application? Otherwise, you can't embed Swing code in a JSP page, because the GUI will be shown on the server, not the client.


Ping & DNS - my free Android networking tools app
Susmitha Metlapalli
Ranch Hand

Joined: May 16, 2007
Posts: 44
Sorry i was wrong...

When user clicked on the link provided for downloading a pdf file, a html file is called up wherein applet class is called.

I have a java program extending an applet, with an open, save and cancel buttons. I need to open the pdf file when clicked on open button. Similarly, I need to save the pdf file to client machine at the specified/selected location by client.

On click of save button i have included the following.

Frame parent = new Frame();
FileDialog fd = new FileDialog(parent, "Save",FileDialog.SAVE);
fd.setDirectory(".");
fd.show();


I also have the path of file on which the user clicked for download.

Request you to help me How can i save the file?

Thanks in advance,
Susmitha.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
You can't. Applets have access to the local file system, not the server file system where the PDF file resides. This would work only if the server runs on your local machine.

Why is downloading the PDF directly -as the result of a click on a link- not sufficient?
Susmitha Metlapalli
Ranch Hand

Joined: May 16, 2007
Posts: 44
In my web application, I need to to capture

1. The users who had opened/saved the file.
2. Also whether the user had just opened the file or he saved the file.

we donot get the handle of the browser default file download open save buttons, i thought i can follow this method...

Is there any other way to proceed further...

Thanks & Regards,
Susmitha.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41843
    
  63
In my web application, I need to to capture

1. The users who had opened/saved the file.
2. Also whether the user had just opened the file or he saved the file.

#1 can be handled by keeping a server session for each user, and checking that in the servlet code that streams the PDF to the browser.

#2 sounds like a rather meaningless requirement. What is the difference between opening a file right from inside the browser, and saving the file to disk and then opening it?
Susmitha Metlapalli
Ranch Hand

Joined: May 16, 2007
Posts: 44
I do agree with you for PointNo 2...

But it needs to be implemented. If so how can i save the file? Is there any possibility in this approach?

Thanks in advance,
Susmitha.
Susmitha Metlapalli
Ranch Hand

Joined: May 16, 2007
Posts: 44
or

Please suggest if there is an other way of acheiving this.

Thanks in advance,
Susmitha.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There is no way for you to know whether or not the user has saved the file.

In order to display it, the browser has to download and store the PDF on the hard drive. If the user elects to view it directly in the browser, it is saved to a temporary directory. Either way, they have a copy of it saved to their drive.

Whoever wrote that requirement doesn't understand web programming.
It can't be implemented.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Save a pdf or any file to client machine from server