在JSP中获取会话代理bean

时间:2014-02-14 10:16:53

标签: spring spring-mvc

我有一个像这样的会话bean:

@Component
@Scope(value="session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public class MySession  { ... }

如何在JSP中启用对此bean的访问?

我在JSP中显示了会话数据,我得到了这个:

org.springframework.web.context.request.ServletRequestAttributes.DESTRUCTION_CALLBACK.scopedTarget.mySession
scopedTarget.mySession

所以,我尝试使用${scopedTarget.mySession.qualites},但它没有用。

1 个答案:

答案 0 :(得分:0)

如果使用此视图解析程序配置将spring beans作为上下文属性公开,那么应该可以直接使用#{mySession.qualites}等值表达式访问bean:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="exposeContextBeansAsAttributes" value="true"/>
</bean>

作为替代方案,通过在@Controller中使用@ModelAttribute注释,将spring bean公开给视图模型。

相关问题