sau*_*abh 5 java spring spring-mvc
使用左侧菜单时,我没有重定向到其他页面,而是使用href链接其他页面.但在执行此操作时,我的会话范围仅限于请求不再存在.所以这是我的控制器代码:
设置会话:
request.getSession(true).setAttribute("application", application);
Run Code Online (Sandbox Code Playgroud)
在其他控制器中获取会话对象:
HttpSession session = request.getSession();
session.getAttribute("application"); //application null in href; redirect works fine
Run Code Online (Sandbox Code Playgroud)
那么有什么方法可以在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>
Run Code Online (Sandbox Code Playgroud)
我正在注入对象来设置和检索简单的bean,如下所示:
@Autowired private ApplicationVO applicationVO;
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
我也试过@SessionAttribute控制器,
@SessionAttributes("applicationVO")但似乎问题仍然存在.
如果有人能为我提供一个带有两个控制器的小例子,我将深表感谢.
| 归档时间: |
|
| 查看次数: |
14773 次 |
| 最近记录: |