Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing file on server side through applet

 
Vrunda Joshi
Ranch Hand
Posts: 104
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am developing an application whichi will run on client-server basis.as the clients run the application which is an applet,on the server side i want to keep a log of all transactions.
so through applet how to create a file on server side.
i am using ibm logging toolkit for logging facility
thanks in advance
 
Michael Ernest
High Plains Drifter
Sheriff
Posts: 7292
Netbeans IDE VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applets are just program code that run on the client. You can of course instruct the applet to retrieve other objects from the same server (data files or images, for example), but there's no stateful "applet connection" between client and server, and no file upload capability.
To do what you want, you need ftp, or a servlet that handles uploads, or some supplemental technique. You can of course integrate this into your applet, but the applet class itself does not directly support what you want to do.
------------------
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can make an applet write a file to a server if the applet opens a URLConnection to a server application (for example, a servlet) and writes the date through the connection. The server application is responsible for storing the data it receives.
However, you were interested in logging, you said. For basic info, this is done automatically into the server's access and/or error logs. If you need to capture more info -- such as data transferred in a POST operation -- you'll need to code that in the server app. None of that requires any client-side action.
Nor should it. Clients can be hacked much easier than servers can, so it's wise to trust them no more than necessary.
 
Michael Brewer
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume one would use the getOutputStream method of the URLConnection. Does this perform a post?
If so, how do you know what property of the post contains the file data?
If no, what code would you need to write on the servlet side to accept the output stream?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17616
39
Android Eclipse IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpURLConnection can do a GET or a POST. The returned output stream is the actual data transmitted - that is, if your request resulted in an HTML response, you'd get back exactly the same data as a web browser would. The HttpURLConnection facility also has the ability to retrieve the response's associated headers, cookies, etc.
I don't do this often enough to have the details committed to memory, so I'd have to RTFM to give specifics, but the information's well enough documented.
[ March 21, 2003: Message edited by: Tim Holloway ]
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic