aspose file tools*
The moose likes Applets and the fly likes Writing to web space from Java applet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Writing to web space from Java applet. " Watch "Writing to web space from Java applet. " New topic
Author

Writing to web space from Java applet.

Jesse Miller
Ranch Hand

Joined: Apr 05, 2010
Posts: 37
I am a little unsure of how to approach this so I am open for suggestions. I have an Applet that pulls data from a web server. The user can change the data but when they press a SAVE button I need to write some data in the form of a XML file back to a folder on the server. Right now I have nothing but server space that houses my Applet. What is the best way to go about this? Thanks
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
What kind of access does the applet have to the server - FTP? WebDAV? Shared directory? If it's just HTTP, then the Java solution would involve servlets (and thus require a servlet container).
Jesse Miller
Ranch Hand

Joined: Apr 05, 2010
Posts: 37
I need to do this upload anonymously so doing it by FTP would probably not work. On researching some more it seems that servlets might be what im looking for. But I am still a little unsure of what is required to implement a servlet. What is required server-side to place the uploaded file in a directory and what is required client side to initiate the upload from the local computer? Thanks
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
Is it an actual file you want to upload? It sounds as if it may just be some XML data. If so, then no more than an HTTP POST is required (which the java.net.HttpURLConnection class can handle). On the server side you'd need a servlet container such as Tomcat (or Jetty, Resin, GlassFish, JBoss, WebLogic, WebSphere etc.).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18167
    
    8

Lester Burnham wrote:On the server side you'd need a servlet container such as Tomcat (or Jetty, Resin, GlassFish, JBoss, WebLogic, WebSphere etc.).


But it sounds like Jesse won't be able to install anything like that in his "nothing but server space". What he can do in that space is an open question.
Jesse Miller
Ranch Hand

Joined: Apr 05, 2010
Posts: 37
Ok, Iv researched a little bit and have been able to set up a HTML form to submit a HTTP POST request and then a PHP script on the back end to accept it and place the file in an upload directory on my server. This works 100%. But now I need to get this functionality in my Java code. The applet I wrote will create a temporary XML file on the users computer but when the user chooses to save all changes it will upload the entire file to the server. I basically need the functionality of the HTML form that I attached in Java code. I imagine I can just use the same PHP script that I have attached as well. Could anyone start me off with some code or specific examples? Thanks

HTML Form


PHP Script

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18167
    
    8

Jesse Miller wrote:Ok, Iv researched a little bit and have been able to set up a HTML form to submit a HTTP POST request and then a PHP script on the back end to accept it and place the file in an upload directory on my server. This works 100%. But now I need to get this functionality in my Java code.


In other words, you need your applet to issue a POST request with the file attached. Start by reading this tutorial; notice that the parts which cover your requirement are near the bottom of that page.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing to web space from Java applet.
 
Similar Threads
Applet won't update database
Sending data to an applet.
Passing Dynamic Data
Different java versions in same project
Pushing response back to a client