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

Servlet to applet communication

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello guys

I am developing an applet which displays the current weather. The applet gets the data from a database through a servlet.
The servlet sends a data to the applet only when a request is invoked by the applet.
Is there a way that the servlet sends data to the applet whenever there is a change in weather without the applet sending request.

thank you
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

It's not possible in general for a server to make contact with an applet. But it's not much overhead for the applet to send a short request every few minutes or so to check if something has changed (or maybe even longer timeframes, depending on how often the server data is updated).

But is an applet really the right tool for a job like this? It would rely on a web page being continuously open.
 
Jemal Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer for the fast response

I was thinking a continuous request would have a great impact on the performance. I will try it.

I am choosing an applet for this application becuase 1)it is web based
2)I need the applet to plot a waveform(chart) accordingly.

Is there any other way to do the plotting on a web browser.

Thank you
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jemal Mohammed:

I am choosing an applet for this application becuase 1)it is web based
2)I need the applet to plot a waveform(chart) accordingly.


Pooling for new data from time to time would be good for you application.

You can even try AJAX for this kind of situations.From javascript only you can make HTTP requests to the server asynchronously and then you get the response back.Using that response data ,you can again use javascript for making graphs.

There might be many ready to use AJAX components might be available for this purpose.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rahul Bhattacharjee:
you can again use javascript for making graphs.


Can you point us to an example of this? I always thought of graphing as being outside of the realm of HTML/CSS (and thus JavaScript). I'd be very interested in seeing that in action.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rahul Bhattacharjee:


You can even try AJAX for this kind of situations.From javascript only you can make HTTP requests to the server asynchronously and then you get the response back.Using that response data ,you can again use javascript for making graphs.



If he's already got an applet on the page, there is no need for AJAX.
Applets have been able to make HTTP calls to the server for a lot longer that Javascript can. Furthermore, with an applet, you can eliminate the need to build and parse JSON, XML, etc.. by streaming serialized Java objects back and forth.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This would be outside the realm of servlets but, if your traffic isn't too high you might want to consider keeping a socket open between the applet and your server.

This is how AIM, and YIM work.
Another example would be the atomic clock at http://www.time.gov.

One downside to this is that it requires another port to be open.
This can be a hassle for a lot of companies with strict firewall policies.

If I were doing this, I would probably follow Ulf's advice and have the applet poll the server every n seconds.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the following link ,

URL-1 , This might not be using ajax , but if we can make out a graph in the client side then we should be able to use AJAX to fetch changing data from server time to time.

There are many third parties (http://www.activewidgets.com/) which sell ready to use AJAX based GUI components.There might be something like this for making graphs.
Well I have never used graphs , but used data grids though.

Ben Souther: If he's already got an applet on the page, there is no need for AJAX.

Thats true.I just wanted to let him know that there might exists ready to use AJAX based component for his graph requirement.

[ July 06, 2007: Message edited by: Rahul Bhattacharjee ]
 
Jemal Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you all for your suggestions.
 
Jemal Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello guys I am done with the database access. Now I am now developing a chat using applets and servlets. I am having a difficulty in sending the a user name to to the applet.
the first html page accepts user name and this will be sent to a servlet which will then redirect to the applet page. now my problem is in sending the user name to the applet. Note that my applet's get and post methods are used for requesting new message and sending a message.

Thank you
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you create the applet tag dynamically, and add a "<param name="username" value="...">" to it?
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the OP Jemal Mohammed,

Why dont you try Google Maps? I heard that its useful for plotting Graphs into the Web Applications. (if its not too late).
 
Jemal Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
that is my problem. How can I make the 'value' field in the
<param name="username" value="..."> a varaible so that the value of this variable be changed dynamically

any help
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, you have the username in the servlet, correct? If you make the page containing the applet a JSP page, you can pass the username from the servlet to the JSP page as a request attribute.
 
Jemal Mohammed
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Ulf Dittmer it works!!

Now i have another problem in the chat application.
How can i get the names and number of users online who are chatting.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's not mix different topics in the same thread. I see you have created another thread for that question already, so any discussion should happen there.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic