bir*_*rdy 18 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>
Run Code Online (Sandbox Code Playgroud)
大多数时候我访问控制器或其他类中的属性,如下所示:
@Value("${dbtype}")
public String dbType;
Run Code Online (Sandbox Code Playgroud)
但是,如果我想在JSP文件中使用属性并绕过控制器,该怎么办?含义我不希望值类型作为模型属性从控制器传递到JSP.
有没有办法直接在jsp中访问属性?
nav*_*611 35
Spring配置
<util:properties id="propertyConfigurer"
location="classpath:yourPropertyFileClasspathHere "/>
<context:property-placeholder properties-ref="propertyConfigurer" />
Run Code Online (Sandbox Code Playgroud)
JSP
<spring:eval expression="@propertyConfigurer.getProperty('propertyNameHere')" />
Run Code Online (Sandbox Code Playgroud)
Kie*_*ran 19
您还可以做的不是将您绑定到单个属性占位符中的属性,或者如果您使用的是java配置并且只是实例化PropertySourcesPlaceholderConfigurer,则使用环境对象:
<spring:eval expression="@environment.getProperty('application_builtBy')" />
Run Code Online (Sandbox Code Playgroud)
小智 9
<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
id="messageSource"
p:basenames="WEB-INF/i18n/site"
p:fallbackToSystemLocale="false"/>
Run Code Online (Sandbox Code Playgroud)
现在这是你的属性文件
site.name=Cool Bananas
Run Code Online (Sandbox Code Playgroud)
这就是你的JSP
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
<head>
<title><spring:message code="site.name"/></title>
</head>
<body>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
60858 次 |
| 最近记录: |