使用 Spring 处理会话 ID [英] Handling Session ID with Spring

查看:39
本文介绍了使用 Spring 处理会话 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 GWT 构建一个 Spring 服务器(您可以将其视为 Javascript AJAX 客户端).但我无法决定建筑的一点.应该如何创建和使用会话?

I'm trying to build a Spring server for GWT (you can think of it as of Javascript AJAX client). But I can't decide on one point of architecture. How should session be created and used?

最简单的方法 - 是使用 HTTP 会话(cookies 和其他东西).看起来不错,但我认为将会话 ID 与标头分开发送会更好(SOAP 样式).

The obvious easiest way - is to use HTTP sessions (cookies and stuff). Looks fine, but I think that sending session ID separate from the headers would be better (SOAP style).

那么,什么更好:getMyPetsName(String sessionID, int petID)getMyPetsName(int petID) + 通过 HTTP 标头(cookies 或其他东西)的会话 ID.

So, what is better: getMyPetsName(String sessionID, int petID) or getMyPetsName(int petID) + session ID through HTTP header (cookies or something).

另一个问题是,如果我使用第一种方式(我更喜欢) - 我如何处理 Spring 中的会话?我真的是春天的新手,谷歌搜索没有帮助.我的意思是:

Another question is, if I use the first way (which I like more) - how do I handle session in Spring? I'm really newbie in Spring, and googling did not help. What I mean is:

String getMyPetsName(String sessionID, int petID) {
    Session s = someWayToGetItById(sessionID);
}

提前致谢.

推荐答案

如果您可以选择,我会选择始终发送会话 ID.

If you can choose it I would opt for always sending the session id.

当用户在同一个会话中打开多个标签时,这会让事情变得更容易.

It will make things a lot easier, also when a user opens multiple tabs in the same session.

如果您不使用 Spring MVC,我认为 Spring 不会对您处理会话的方式施加太多限制/假设.有很多缓存,比如 ehcache,可以使用 spring 设置并存储您的会话.更好的缓存还允许会话分布在机器上并持久存储,而不会影响代码库.

If you are not using Spring MVC I do not think Spring will put much constraints/assumptions on how you handle the session. There are many caches, like ehcache, which can be set up using spring and store your sessions. The better caches also allow the sessions to be distributed over machines and stored persistently without impacting on the code base.

这篇关于使用 Spring 处理会话 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆