2014-02-14 39 views
0

會話代理豆,我有我的會話bean這樣的:獲取JSP

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

的問題是我怎麼可以訪問這個bean在我的jsp?

我已經顯示會話數據在我的JSP和我得到這個:

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

所以我儘量${scopedTarget.mySession.qualites},但沒有奏效。

回答

0

如果暴露彈簧豆類如使用這個視圖解析器配置上下文屬性,那麼它應該是可能直接與值表達式如#{mySession.qualites}訪問豆:

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

作爲另外,通過在@Controller中使用@ModelAttribute註釋,將spring bean展示給視圖模型。

+0

謝謝@jhadesdev不,我不想公開每一個我擁有的豆。 – Youssef

+0

在這種情況下,@ModelAttribute允許揭露beans selectivelly –

+0

不,但我想用'@Component @Scope(value =「session」,proxyMode = ScopedProxyMode.TARGET_CLASS)'我認爲只是somthing丟失,因爲我讀這是一些在會話中存儲數據的方式? – Youssef