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

Servlets and Applets

Chaveen Ekanayake

Joined: Jun 01, 2008
Posts: 15
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 ]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
An applet can communicate with a server (servlet or otherwise, doesn't matter) using the 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 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).
elay Raja

Joined: Jun 10, 2008
Posts: 27
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();
OutputStream out=con.getOutputStream();
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:
Chaveen Ekanayake

Joined: Jun 01, 2008
Posts: 15
thanks man
I agree. Here's the link:
subject: Servlets and Applets
It's not a secret anymore!