【问题标题】:Exposing Spring beans in a JSP file在 JSP 文件中公开 Spring bean
【发布时间】:2012-04-07 01:33:21
【问题描述】:

我们目前有一个定义了所有 bean 的 spring 项目。我想放置一个 jsp 页面,它允许我检查 bean(如 jconsole 的 mbean),这将允许我更改列表的大小、重置列表、查看内容甚至启动线程。

<bean id="properties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">    
    <property name="ignoreResourceNotFound" value="true"/>      
    <property name="locations">
        <list>
        <value>classpath:database.properties</value> 
        <value>classpath:log4j.properties</value>        
        </list>
    </property>      
</bean>

<bean id="mylogger" class="com.logging.Logger" />

<!-- Expose ever bean to the JSP   --> 
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <property name="prefix" value="/WEB-INF/views/"/>
    <property name="suffix" value=".jsp"/> 
    <property name="exposeContextBeansAsAttributes" value="true"/> 
    <property name="exposedContextBeanNames">
        <list> 
            <value>mylogger</value>
            <value>properties</value> 
        </list>
    </property>  
</bean> 

我希望让我的 JSP 文件引用这些对象会像这样工作

${properties.LogRoot}

它显示了属性值,但是否有类似的方法来呈现 spring bean,就像你将托管 bean 一样?

谢谢

【问题讨论】:

  • 不完全是重复的 - OP 已经设置了 Expose 属性,但仍然没有得到想要的结果
  • @Bozho,谢谢。问题是我如何动态地允许在 JSP 页面上查看我的 bean

标签: spring jsp spring-mvc spring-webflow


【解决方案1】:

试试${properties['LogRoot']}。这是访问地图值的常用方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-12
    • 2016-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多