使用左侧菜单时,我不会重定向到其他页面,而是使用 href 链接其他页面。但是,在这样做时,仅限于请求的会话范围不再存在。
这是我的控制器代码:
设置会话:
request.getSession(true).setAttribute("application", application);
获取其他控制器中的会话对象:
HttpSession session = request.getSession();
session.getAttribute("application"); //application null in href; redirect works fine
那么有什么方法可以在 Spring MVC 3 中使用“应用程序”会话范围。这样我就可以在我的应用程序中访问会话。
我在我的 application-servlet.xml 中尝试了这个代码片段
<!-- a HTTP Session-scoped bean exposed as a proxy -->
<bean id="applicationVO" class="com.nypd.viewobjects.ApplicationVO" scope="globalSession">
<!-- this next element effects the proxying of the surrounding bean -->
<aop:scoped-proxy/>
</bean>
我正在注入对象来设置和检索简单的 bean,如下所示:
@Autowired private ApplicationVO applicationVO;
我在这里做错了什么?
我也尝试过@SessionAttribute
在控制器上@SessionAttributes("applicationVO")
但似乎问题仍然存在。
如果有人能为我提供一个带有两个控制器的小例子,我将非常感激。