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 but its not getting any value. what is the correct way?
properties, Spring MVC will look for view-books. jsp inside the /WEB-INF/jsp/ directory. The above example shows us how to use the JSTL <c:url> tag to link to external resources such as JavaScript and CSS. We normally place these under the ${project.
The jsp:useBean action tag is used to locate or instantiate a bean class. If bean object of the Bean class is already created, it doesn't create the bean depending on the scope. But if object of bean is not created, it instantiates the bean.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With