aspose file tools*
The moose likes Servlets and the fly likes store applet session using servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "store applet session using servlet" Watch "store applet session using servlet" New topic
Author

store applet session using servlet

Sutharshan bala
Greenhorn

Joined: Jul 31, 2008
Posts: 7
I'm sutharshan and i'm developing a small game applet.

I have a problem that when a user logs in to the website, i need to restore the old game apple state to the user and when he logs out i need to store it using servlet or any other way.

Every user id have different applet state and i need to restore them according to the user id.

I dont know how to use the HttpSession in this issue.

Please help me in this issue, with sample codes. i dont have any idea how to implement this.

please help me.


Sutha
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

"Sutha",
Please see your private messages about an important administrative matter.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42281
    
  64
HTTP sessions are not a good way to store state between logins. Sessions are generally used to store state during logins, but not for prolonged periods. That's why they're generally set to expire after an hour or so if they're not accessed.

Maybe the servlet can store the state in a more permanent place, like a file or database?


Ping & DNS - my free Android networking tools app
Sutharshan bala
Greenhorn

Joined: Jul 31, 2008
Posts: 7
Friends,

I'm not having a idea how i'm going to do this project. But i have to store the current state of the game applet associated to every user id. It doesnt matter to use servlet or anything. I dont wont to use cookies. I need a solution with example source code. Please help me in this
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42281
    
  64
We'll try to help you, but not by handing out code. You'll learn much more by figuring this out on your own.

So: You were talking about servlets - does that mean you have you have a servlet container running on the same machine from where the applet is hosted? If so, the applet can use the HttpUrlConnection class to send data to a servlet; see http://www.exampledepot.com/egs/java.net/pkg.html for examples, particularly e135.

Of course, to save the data, a user ID of some kind needs to be stored along with it, so that if a user returns he can be recognized. Do you have a login mechanism of some kind in the applet?

Finally, to read existing data if the applet is started again later, you could do the reverse of what you did to store the data, or you could embed the data in parameter tags inside the applet tag. That would mean that the user logs in not in the applet, but into the web app, so that the web app can dynamically create the applet page based on that user's data.

Does this help?
Sutharshan bala
Greenhorn

Joined: Jul 31, 2008
Posts: 7
i have a jsp form to login and when the user logs in the game applet should load where he left out last time.

i have design the game applet, but i dont know how to use the object persistence with the users and the applet. i dont know how to implement the persistence in applet and also how to store that object in server?

please help me in this with some small sample codes, for using persistence in applet and for the object store


thanks in advance
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42281
    
  64
A small code sample is not going to do it. There are quite a few parts to this: 1) the applet must transfer the persistent data to a servlet, 2) the servlet must store that data somewhere (in a file or database), 3) upon login into the web app, a servlet needs to read the persistent data and write it via parameter tags into the applet tag, 4) the applet needs to read the values from the parameter tags. Only the 4th step is quite simple.

Alternatively, you could try the AppletContext's getStream and setStream methods. They're supposed to let you store data locally, but I haven't had much luck getting those to work.
[ November 18, 2008: Message edited by: Ulf Dittmer ]
Sutharshan bala
Greenhorn

Joined: Jul 31, 2008
Posts: 7
How to pass the object persistence through the applet parameters and how the applet will understand that?

IF we do like that, is it safer?

Thanks for your response
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42281
    
  64
The link I posted explains about parameter tags. A more detailed explanation can be found at http://java.sun.com/docs/books/tutorial/deployment/applet/html.html

I'm not sure what you mean by safer? Safer than what?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: store applet session using servlet