开发者

Spring - bean access in JSP

I have configured a bean like this and I have forum.host.url in the file properly

<bean id="forum_host_url" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="forum.host.url"/>
        <property name="resourceRef" value="true"/>
</bean>

I need to access this bean value from a JSP, I have tried

${forum_host_url}

in my jsp file b开发者_如何学运维ut its not getting any value. what is the correct way?


If you are using InternalResourceViewResolver you can do something like this:

<bean 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="exposedContextBeanNames">
        <list><value>forum_host_url</value></list>
    </property>
</bean>

If you prefer, you can use exposeContextBeansAsAttributes property and JSPs will be able to access all your beans.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜