How to store object (not string) in session in play framework?

前端 未结 3 1716
走了就别回头了
走了就别回头了 2021-02-14 08:17

I have a project for school and I have to use Java. Recently I found play framework and I want to try to use it. It\'s easy enough for a quick start, but I ran into a problem wi

3条回答
  •  滥情空心
    2021-02-14 09:00

    Use Java Serialization to serialize a Hashmap to a file or to the database. Name the file or id column after a unique identifier you store in the user's cookie. Then put the User object in the hashmap before you serialize the hashmap. Now you have a persistent store that you can access. When the framework forgets the User object or any other session information, you can deserialize the Hashmap. Then write some static helper methods, static Object SessionDB.get(String id, String key) and SessionDB.put(String id, String key, Object value). I use this method on my homemade framework to store session information over a small server farm. Of course I use the database, not a file system.

提交回复
热议问题