[英]Spring-mvc 3.0 application session scope
使用左側菜單時,我沒有重定向到其他頁面,而是使用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;
我在這做錯了什么?
我還在控制器@SessionAttributes("applicationVO")
上嘗試了@SessionAttribute
,但似乎問題仍然存在。
如果有人能為我提供一個帶有兩個控制器的小例子,我將深表感謝。
@Session屬性不會在會話范圍中存儲數據。 它將數據存儲在會話范圍內,該范圍是大於請求但小於會話的范圍。 此范圍由spring進行內部管理,用於對話(跨越多個請求),並在對話完成后刪除
要將bean存儲在會話范圍中,您必須在spring-context.xml中聲明requestContextListner,這會將請求公開給當前線程
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.