Spring MVC应用程序-如何设置会话范围的Bean值 [英] Spring MVC Application - How do I set a session scoped bean value

查看:102
本文介绍了Spring MVC应用程序-如何设置会话范围的Bean值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我需要在一个屏幕上收集信息,然后在下一个屏幕上显示.

In my application I need to gather information on one screen and then display it on the next.

我选择将此信息存储在一个范围设置为会话的bean中(它将在初始数据收集屏幕之后的其他几个屏幕中使用)

I have selected to store this information in a bean with a scope set as session ( it will be used in several other screens after the initial data gathering screen)

管理器的配置如下:

 <bean name="/springapp.htm" class="foo.bar.controller.springcontroller">
        <property name="sessionBeanManager" ref="sessionBeanManager" />
    </bean>

bean的配置如下:

The bean is configured as follows :

<bean id="sessionBean" class="foo.bar.sessionBean" scope="session">
    <aop:scoped-proxy/>
   <property name="beanValue" value="defaultValue" />
</bean>

<bean id="sessionBeanManager" class="foo.bar.sessionBeanManagerImpl">
    <property name="sessionBean" ref="sessionBean"/>
</bean>

我在

<c:out value="${sessionBean.beanValue}"></c:out>

但是每当我加载页面时,值是否为空?

but whenever I load the page the value is empty?

在我看来,该bean正在加载OK,但未填充该值,这使我认为不是正在填充会话bean还是未将其创建为会话bean?

It seems to me that the bean is loading OK but is not populated with the value, which leads me to think that either the session bean is not being populated or the bean is not being created as a session bean?

推荐答案

除非在模型中首先添加Spring Bean(在您的情况下为JSP),否则它们在视图中不可见.

Spring beans are not visible in the views (JSPs in your case) unless you add them first to the model.

您必须将sessionBean添加到控制器中的模型中,以使其可用于视图.

You have to add your sessionBean to the model in the controller to make it available to the view.

model.addAttribute("sessionBean", sessionBean);

这篇关于Spring MVC应用程序-如何设置会话范围的Bean值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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