views:

48

answers:

4

Generally, how does a java applet manipulate user data? Take for instance "shopping carts" on shopping websites - after a user enters the data, is the data then preloaded each time a user accesses a website? Or is the data retrieved as the user is on the page?

A: 

Question is not clear since you can have many ways to store data in a website.

Usually shopping carts are not Java Applets but just pages that have been dynamically created by the webserver. In this case most of the information is stored directly into the server, sent and received together with normal http requests.

When talking about Java Applets you have to remember that it is a application embedded into a webpage that has its own virtual machine. So it stores the data inside the memory and it can receive parameters from the webpage during loading, from javascript dynamically and using real TCP sockets opened around (for http or more low level things).

Jack
A: 

More often than not, the shopping cart information is handled by JavaScript, rather than a Java Applet (at least from what I've seen around). But an applet could do interesting things, I think. The Java Applet's VM only exists as long as the tag is alive in the browser, so the applet would have to collect its data from the server when the page is loaded, then do whatever it does with it. If the user navigates away, it'll have to start over.

One alternative would be to use framesets in order to keep the applet active while the user navigates about in a separate frame. Since there's not a great way to communicate with the applet AFAIK, it would have to "ping" the server periodically to check for updates to the shopping cart. This request could be made pretty lightweight, though - perhaps the applet sends a session ID to the server, and the server responds with the last time that session's shopping cart changed. Then the applet can re-request the updated shopping cart contents only when needed.

Curtis
A: 

I've never seen an applet which does shopping cart like stuff, it would have been an inefficient and userunfriendly approach. So there must somewhere be a huge misconception. Also, Java should really not be confused with JavaScript.

Such information is usually stored in the server side memory in the session. In PHP, it's stored in $_SESSION and in JSP/Servlet in HttpSession. The session is in turn backed by a server-managed cookie which lives as long as the user is active on the webpage within the same browser instance. Some websites even couples this to a login and a database so that the information can be stored/retrieved in/from the database depending on the currently logged in user which in turn is stored in the session.

In a nut: the server side code (PHP, Java/JSP/Servlet, C#/.NET/ASP, etc) just stores the information itself and displays the information in the page.

BalusC
A: 

In general, applets are forbidden from storing any data client-site.

So, all data would inevitably be stored server-side. The rest depends on how the client-server interaction is organized for such applet, both approaches you've listed are doable.

Vanya