如何在Spring MVC应用程序中显示JSP中属性文件中的值 [英] How to show values from property file in JSP in a spring MVC app

查看:93
本文介绍了如何在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')" />

这篇关于如何在Spring MVC应用程序中显示JSP中属性文件中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆