doumisha5081 2010-12-06 02:56
浏览 75

JSP / Servlets会话+ PHP:跟踪会话 - JSON /数据库或HttpSessionListener?

I have implemented a Servlet, and a PHP site is accessing that Servlet to retrieve data. I'm wondering what is the best method to store a session variable, or whether I should store it at all.

Variables which need to be stored include an ArrayList, and other objects.

I've thought through about 3 possibilities:

(1) Implement the HttpSessionListener, and store each session (when it's created) into a static SessionMap. Then delete the session once it is destroyed.

(2) Store everything in JSON. So I'll have to serialize/deserialize each Object and pass it back and forth. (I have a list of items in each ArrayList/Object I want to keep track of between user clicks.)

(3) Store the information in MongoDB (just to pick one), using the SessionID as the primary key.

What do you guys think?

  • 写回答

2条回答 默认 最新

  • duanhangjian8149 2010-12-06 03:01
    关注

    I rather like a combination of all three.

    1. Has the advantage of simplicity - no need to go to a database if there's a session available.
    2. JSON is lightweight, and it's the language of the browser.
    3. Storing items in a database and retrieving them using session ID allows the possibility of users starting a session, leaving it in an incomplete state, and coming back later to pick up where they left off. The database might be a nice way to store information if the memory requirements become large and cumbersome.

    I don't believe it has to be an exclusive choice.

    评论

报告相同问题?

悬赏问题

  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率