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

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

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

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