• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Save a pdf or any file to client machine from server

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Susmitha Metlapalli
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or

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

Thanks in advance,
Susmitha.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic