• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to handle randomly generated files?

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My servlet will generate a different file for each client.
And I want the client to be able to download it and save it with a certain extension, say, *.PDF
The generated file is small, probably just about 1K, and it does not need to stay long on the server.
Somebody in this forum told me that I can store it in a session object, but then how can I have the user save that file as PDF by default?
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could, for example,
1- generate your file and give it a unique filename (if I understand correctly, in your situation you have 1 file per client). Store the filename in the client's session so you can retreive it later.
2- put the file in a directory where the client has read access (ex: webapp/yourWebAppName/pdf/)
3- when your client needs to download the file, you generate a page that has a link to the file. You use the filename that you stored in your client's session to get the complete path to your file.
Hope this helps
Dominic
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another trick is to have any URL in your applet that ends in .pdf map to a servlet that feeds the data on the fly. This is a trick which I use in TimeCzar for PalmDoc and iCalendar downloads. In your web.xml, specify the following:
<servlet-mapping>
<servlet-name>
MyPDFServlet
</servlet-name>
<url-pattern>
*.pdf
</url-pattern>
</servlet-mapping>
 
Mark Lau
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1- generate your file and give it a unique filename (if I understand correctly, in your situation you have 1 file per client). Store the filename in the client's session so you can retreive it later.
This is what I wanna do, but I do not know how.
[ April 04, 2003: Message edited by: Gene Chao ]
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gene Chao:
1- generate your file and give it a unique filename (if I understand correctly, in your situation you have 1 file per client). Store the filename in the client's session so you can retreive it later.
This is what I wanna do, but I do not know how.
[ April 04, 2003: Message edited by: Gene Chao ]

 
Stephanie Spike
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gene,
Sorry about the blank post - haven't quite got the hang of this. If you haven't solved your problem yet, I have a suggestion. If you don't have to save the file on the server at all - I would suggest using the response output stream. If you set the response type as application instead of html, most browsers will ask the user if they'd like to open the response with an application.
Here's an example in a servlet doGet()-
response.setContentType("application/octet-stream");
PrintWriter out = response.getWriter();
out.println("Thanks User...");
out.println("Here's your file.");
 
reply
    Bookmark Topic Watch Topic
  • New Topic