如何在 spring MVC 应用程序中的 JSP 中显示属性文件中的值
问题描述:
我在 app-servlet.xml
中使用这样的 bean 设置我的属性:
I'm setting my properties in app-servlet.xml
with a bean like this:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/my.properties"></property>
</bean>
大多数时候我会像这样访问控制器或其他类中的属性:
Most of the time I access the properties in my controllers or other classes like this:
@Value("${dbtype}")
public String dbType;
但是如果我想使用 JSP 文件中的属性并绕过控制器怎么办.这意味着我不希望值类型作为模型属性从控制器传递到 JSP.
But what if I want to use a property in a JSP file and bypass the controller. Meaning I don't want the value type being passed from the controller to the JSP as a model attribute.
有没有办法直接在jsp中访问属性?
Is there a way to access properties directly in a jsp?
答
Spring config
<util:properties id="propertyConfigurer"
location="classpath:yourPropertyFileClasspathHere "/>
<context:property-placeholder properties-ref="propertyConfigurer" />
jsp
<spring:eval expression="@propertyConfigurer.getProperty('propertyNameHere')" />