Meaningless Drivel is fun!*
The moose likes Applets and the fly likes Requests to server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Requests to server" Watch "Requests to server" New topic

Requests to server

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 815
How can I have an applet that can request data from a server directly? I have a JApplet that displays some drawings made through AWT. I want to have some links on the drawing that can "lookup" data from the server, directly from the applet and return it. What choices do I have to accomplish this? Suggestions are appreciated. Thanks.

Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Have you read this part of the Oracle tutorial regarding Applets?

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Well You can have those drawings put up in icons or labels and call mouseClicked events on the and have a method that sends request to some servlet on the server. The servlet then returns some data in string or Object form and the Applet then displays it in its assigned place. If that is an Object that server sends and applet reads, then you have to have the Class file of that Object too with the applet.

I can further help you if you tell me what you need...

Maki Jav

Help gets you when you need it!
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 815
If I had a simple as possible example I could work from that. So basically a JApplet that (upon clicking a JButton) would make a call directly to the server, read a textfile with first name and last name in it, and display a popup with those 2 values in it. I've read about RMI but with RMI you would need to download a jar file onto the client (correct?) and that's not something I want to do (don't want to have people download additional requirements). I just want to have an app in JApplet app that resembles a html page that utilizes AJAX (i.e. doesn't need to refresh and can directly grab info from the server behind the scenes). Does that help? If you have any additional info I'd appreciate it if you could pass it along. Thanks for your post as well.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Well it is either JApplet or Ajax; not Applet and Ajax; got me?

Well that is easy to build.

Have a server response on your server side like Servlet...

Heard that JApplet can read file from that same url from which it is loaded. And I have worked on it too.

Read textfile from url through applet and display it.

I will have to write code for you?

Maki Jav
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41186
The page has an example applet that reads a file from a server and processes its contents. Instead of a static URL, the applet could as well access a servlet that returns dynamic content.

Ping & DNS - my free Android networking tools app
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Ok here is the code:

This is a text file readme.txt qhich has


and the Applet we have for reading is:

and to put this applet in html

you will need to have an index.html file with applet tag.

<APPLET CODE="TestIO" codebase="." WIDTH=800 HEIGHT=300></APPLET>

The text file and applet class and index.html will all be in the top folder of your web application.

If you need more help, please ask.


Maki Jav
jQuery in Action, 2nd edition
subject: Requests to server
Similar Threads
calling msaccess application from an applet?
JNDI lookup from Applet
Java and databases
jsp-applet-jsp communication
applet write file to IIS - URGENT