• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Servlets and Applets

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I m designing a chat program for web. since I haven't had much experience I designed chat interface by HTML. Then I realized with HTML only inputs can be made to server but no outputs from server ( I want to show the messages of chatters on a textarea ). Now I am going to use Applet instead of HTML form. But I don't know how to put a connetion with servlets for Applet ( or can I ??). Is there anything that can be used other than HTML or Applet?? (ie :- JSP )

Please help
[ September 04, 2008: Message edited by: Bear Bibeault ]
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An applet can communicate with a server (servlet or otherwise, doesn't matter) using the java.net.URLConnection class. You may also want to look into the Apache Commons HttpClient package, which provides more features for HTTP communication.

It would also be possible to use raw TCP/IP sockets using the java.net.Socket class (and a corresponding ServerSocket on the server). Come to think of it, that would be a better fit than using HTTP.

These days it would be more natural to do this in HTML and JavaScript using AJAX technologies, though. That's what the XMLHttpRequest JavaScript object does (which is supported by all major browsers).
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Applet can connect with servlet using HttpURLConnection.
You have to make connection to servlet using HttpURLConnection API to a servlet.For example...the above code will be written in Applet

URL url=new URL("http://localhost:8080/Chat/ChatServlet");
HttpUrlConnection con=url.openConnection();
con.setDoInput(true);
OutputStream out=con.getOutputStream();
out.write(data);
You can wrap the outputstream to any stream. Try this.If you can't get it,i will send the code in detail.
View this Link:http://www.j-nine.com/pubs/applet2servlet/Applet2Servlet.html
 
Chaveen Ekanayake
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks man
 
please buy my thing and then I'll have more money:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic