Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

How Applet communicates with the Servlet?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Someone please tell me , how to make applet to communicate with Servlet. please give me a sample to explain. please.
meng
 
Sheriff
Posts: 440
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to the "Applet" forum.
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Applet if you created a button then the actionPerformed
for the button can contain
URL urlobj=new URL("webserver/servletpath");
Try this and do get back
Suneel
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I know one way how the communication works. It is something like this:
<pre><code>
//create URL for get and pass name=value pair if you need to
String serverurl=serveraddress+"?name=value&name=value";
URL url=new URL(getDocumentBase(),serverurl);
URLConnection connect=url.openConnection();
//for writing through post enter the date in the body
DataOutputStream out=new DataOutputStream(con.getOutputStream());
//optional
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
//bytes is an array of byte
out.writeBytes(bytes);
out.flush();
out.close();
//for reading from the servlet
InputStram in=con.getInputStream();
</code></pre>
see the applet-servlet communication chapter in O'reilly's Servlet Programming for more details.
bye
Tanveer
 
Ranch Hand
Posts: 347
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hanmeng,
Please be sure to register with a proper name.
"hanmeng" does not follow the conventions.
See here for details: http://www.javaranch.com/name.jsp
If you do not register properly, your account will be disabled.
I would hate to see that happen.
Thank you.
Stephanie
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic