This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Requests to server

 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Rob
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read this part of the Oracle tutorial regarding Applets?
 
Maki Jav
Ranch Hand
Posts: 446
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Hunter
Ranch Hand
Posts: 832
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 446
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The http://www.coderanch.com/how-to/java/CodeBarnApplets 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.
 
Maki Jav
Ranch Hand
Posts: 446
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is the code:


This is a text file readme.txt qhich has

Maki
Jav




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.


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






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.


Thanks,

Maki Jav
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic