我在 app-servlet.xml
中使用这样的 bean 设置我的属性:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="/WEB-INF/my.properties"></property>
</bean>
大多数时候我访问 Controller 或其他类中的属性,如下所示:
@Value("${dbtype}")
public String dbType;
但是如果我想使用 JSP 文件中的属性并绕过 Controller 怎么办。这意味着我不希望将值类型作为模型属性从 Controller 传递到 JSP。
有没有办法直接在 jsp 中访问属性?
最佳答案
Spring 配置
<util:properties id="propertyConfigurer"
location="classpath:yourPropertyFileClasspathHere "/>
<context:property-placeholder properties-ref="propertyConfigurer" />
jsp
<spring:eval expression="@propertyConfigurer.getProperty('propertyNameHere')" />
关于java - 如何在 Spring MVC 应用程序中的 JSP 中显示属性文件中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15111260/