gpt4 book ai didi

java - 使用 spring ws 后端 Web 应用程序进行 session 管理

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:01:28 24 4
gpt4 key购买 nike

我正在尝试创建一个 web 应用程序,它将使用 js 前端并在后端调用 Spring WS。假设这是一个购物网站类型的网站。因此,我可以拥有 OrderService InventoryService ShippingService 等服务。唯一需要 session 的是用户的购物车。现在,就这个购物车而言,使用 servlet 容器进行 session 管理是否有意义?或者,我应该有 CartService 将 session 信息保存到数据库吗?

在使用 Web 服务进行 session 管理时,最佳实践是什么?我想,最好的做法确实是保持服务无状态,但如果我有无状态网络服务,我该如何授权用户呢?

使用一个 servlet 容器来进行 session 管理,然后让不同的 Controller 充当 web 服务的代理,这到底是不是一个好习惯?

我附上一张图片,让您更好地理解上下文。 enter image description here

最佳答案

How can I authorize users if I have stateless webservices?

  1. 如果您的应用程序使用外部 ws,则描述了相当常见的方法 here .

  2. 如果所有 ws 都是您交付的一部分,您当然可以使用 spring-security .

  3. 一种非常常见的方法也是使用 (apache) http 服务器作为代理,同时使用 ldap 之类的东西进行身份验证和授权。

Is it a good practice at all to use a servlet container just to do session management and then have different controllers acting as proxies to the webservices?

我认为不是。也讨论过here您只能从保持 Web 服务无状态中获益,如果您需要在请求之间保持状态,请使用 cookie。

如果状态(购物车)在注销后仍然存在,CartService 之类的东西对我来说是个好主意。

关于java - 使用 spring ws 后端 Web 应用程序进行 session 管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31949664/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com