Spring MVC Application - How to set bean value for a session

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

I chose to save this information in a bean with the scope defined as a session (it will be used in several other screens after the initial data collection screen)

The manager is configured as follows:

 <bean name="/springapp.htm" class="foo.bar.controller.springcontroller">
        <property name="sessionBeanManager" ref="sessionBeanManager" />
    </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>

And I output to the jsp page using

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

but whenever i load the page is the value blank?

It seems to me that the bean loads normally, but does not populate with a value, which makes me think that either the bean session does not populate, or the bean is not created as a bean session?

+3
source share
2

Spring beans (JSP ), .

SessionBean , .

model.addAttribute("sessionBean", sessionBean);
+2

spring session beans EL jsp.

${sessionScope['scopedTarget.messageUtil'].flashMessages}

getFlashMessages() bean

<bean id="messageUtil" class="mypackage.MessageUtilImpl" scope="session">
    <aop:scoped-proxy proxy-target-class="false"/>
    <property name="messageSource" ref="messageSource" />
</bean>
+8

Source: https://habr.com/ru/post/1729908/


All Articles