【发布时间】:2011-07-01 09:47:26
【问题描述】:
使用左侧菜单时,我不会重定向到其他页面,而是使用 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 中尝试了这段代码 sn-p
<!-- 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") 但问题似乎仍然存在。
如果有人能给我提供一个带有两个控制器的小例子,我将不胜感激。
【问题讨论】:
标签: java spring spring-mvc