如何在Spring MVC应用程序中显示JSP中属性文件中的值
问题描述:
我正在使用这样的bean在app-servlet.xml
中设置属性:
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配置
<util:properties id="propertyConfigurer"
location="classpath:yourPropertyFileClasspathHere "/>
<context:property-placeholder properties-ref="propertyConfigurer" />
jsp
<spring:eval expression="@propertyConfigurer.getProperty('propertyNameHere')" />