File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes how to post data from applet to servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to post data from applet to servlet." Watch "how to post data from applet to servlet." New topic

how to post data from applet to servlet.

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I am trying to set up a simple mail server, when some one sign up i want a servlet to be invoked which give the form for a new user and when he log's in the mail box should open. but my confusion is how on the press of a button (ie and applet button)
while i perform this task. please me with this query. thanks .
Van Glass
Ranch Hand

Joined: Nov 18, 2000
Posts: 110
Look at using the URLConnection classes. You will need these to post your data. You may want to try using JHTTP 1.1 at Handles most all HTTP related functionality.

JFind - Your Java Resource
Senthil Nathan

Joined: Nov 22, 2000
Posts: 3
Inside the Applet, u instantiate a URL object by passing the url of the servlet which is going to handle the request as a parameter. Invoke a method called open request on the URL object which would give u URLConnection Object. Using connection object, get input & output streams and then write into the stream the datas which u want to pass to the servlet.
I would give u the code (frame work)
URL url = new URL("servlet url");
URLConnection con = url.openConnection();
OutputStream out = con.getOutputStream();
out.write("date to be sent");
Does this clears ur doubt?
le taylom
Ranch Hand

Joined: Dec 01, 2000
Posts: 44
Applet to servlet communication is a great way (and more pure Java) to reproduce 2 components of the model-view-controller.
Take a look at the following article for a good overview, with code, on how to do it.
I won't repeat it by writing any more here!
Good luck
I agree. Here's the link:
subject: how to post data from applet to servlet.
jQuery in Action, 3rd edition