Spring MVC Application - How do I set a session scoped bean value

耗尽温柔 提交于 2019-12-01 08:20:24

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

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

model.addAttribute("sessionBean", sessionBean);

You can reference spring session beans with the following syntax in your EL in the jsp.

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

That calls getFlashMessages() on this bean

<bean id="messageUtil" class="mypackage.MessageUtilImpl" scope="session">
    <aop:scoped-proxy proxy-target-class="false"/>
    <property name="messageSource" ref="messageSource" />
</bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!