• 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 write a file to local machine?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The application is running on Server "A", I am working on client machine "B". How to write a file to the directory of local machine (for example, c:\myDoc)?
If using File and FileWriter (or FileOutputStream), it can not work cross network. So file is write to the Server "A" instead of Client machine "B". If using ServletResponse.getOutputStream(), no file directory can be specified.
How can I do that?
Thanks a lot.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Short answer: you can't. This is not strictly a SErvlet or JSP thing, its a HTTP security thing.
Otherwise visiting a web page could result in people writing viruses, overwriting properties, or even have Microsoft detect a Linux operating system and overwrite it with Windows
One thing you can do is have someone make a request to a Servlet, then have the Servlet return a file to the client. The default for web pages is to return content with the mime-type of text/html and for the browser to handle this (by showing it on the screen)
There are other mime-types that browsers can handle (like images and movies), but if the browser doesn't know what to do with the file, it will prompt the user to save it on the harddrive (and they get to decide where to save it).
This isn't a complete solution (and may not work cos I ripped from the middle of an existing class) but it should give an idea... The only tricky bit is the Disposition Header, which changes the name of the file to the real filename.

Dave
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing u can do is to have a digital signature. This means asking the client to give permissions to access his machine. If the client accepts, then the server can be able to do IO operations on the client machine.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David O'Meara:

Otherwise visiting a web page could result in people writing viruses, overwriting properties, or even have Microsoft detect a Linux operating system and overwrite it with Windows


... and charge the webmaster for licence and consulting fees
 
Gudavy Hu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to all your guys!
 
mustang india
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are lots of commercial digital sinatures available in the market. U have to include this in ur applet/html (client). When the page loads, it will prompt the user to grant permissions for IO. U can get more technical info on this in the web. I have used this long back and I really dont remember it now.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic