如何在Spring MVC中存储会话 [英] How to store session in Spring MVC

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

问题描述

在Spring MVC(2.5)Web应用程序中存储用户的会话相关数据(例如,用户已执行的最近操作的日志)的最佳方法是什么?

What's the best way of storing session related data of a user (like, for example a log of recent actions a user has done) in a Spring MVC (2.5) web application ?

使用经典的javax.servlet.http.HttpSession或在控制器bean中指定scope =session,并将数据存储在会话对象中?

Using the classic javax.servlet.http.HttpSession or by specifying scope="session" in controller beans, and storing the data in a session object ?

推荐答案

会话范围的bean(使用 scope =session)是最干净的方法。这样就无需自己与会话进行交互。

Session-scoped beans (using scope="session") is the cleanest approach. This removes the need to interact with the session yourself.

如果要将会话范围的bean自动装入控制器,则需要进行控制器会话 - 作为这里描述。这两种方法都是有效的。

If you want to autowire a session-scoped bean in to the controller, you either need to make the controller session-scoped itself, or use a scoped-proxy to wire it into a singleton controller, as described here. Either approach is valid.

这篇关于如何在Spring MVC中存储会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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