java - 如何在 Spring MVC 应用程序中的 JSP 中显示属性文件中的值

标签 java spring jsp spring-mvc

我在 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/

相关文章:

java - log4j - 如何以编程方式从日志记录中排除某些类

java - com.mysql.jdbc.exceptions.jdbc4.CommunicationsException : Communications link failure

java - Swing 添加图像不起作用

java - 避免从不同的服务获取文件服务器的相同文件

java - 将 JSON 发布到 Controller 返回 400 Bad Request

java - 谷歌应用引擎静态 IP

java - Spring :Inserting cookies in a REST call response

javascript - JavaScript onUnload 的替代方案

javascript - jquery - 范围在变量中丢失

javascript - 如何显示输入中选定行的信息?