如何使用 JSP 中 PropertyPlaceholderConfigurer 中指定的属性文件中的属性
在我的应用程序上下文中,我定义了属性文件:
<context:property-placeholder location="classpath:application.properties" />
我想获取 JSP 页面上该文件中定义的属性值。有没有办法做到这一点
${something.myProperty}?
In my application context I have defined properties file:
<context:property-placeholder location="classpath:application.properties" />
I want to get value of the property defined in that file on JSP page. Is there a way to do that in the way
${something.myProperty}?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
PropertyPlaceholderConfigurer
只能解析 Spring 配置(XML 或注释)中的占位符。在 Spring 应用程序中使用Properties
bean 是很常见的。您可以通过这种方式从您的视图访问它(假设您使用的是InternalResourceViewResolver
):然后,在您的 JSP 中,您可以使用
${properties.myProperty}
或${properties['my.property']}
。PropertyPlaceholderConfigurer
can only parse placeholders in Spring configuration (XML or annotations). Is very common in Spring applications use aProperties
bean. You can access it from your view this way (assuming you are usingInternalResourceViewResolver
):Then, in your JSP, you can use
${properties.myProperty}
or${properties['my.property']}
.在 Spring 3.1 之后,您可以将
标签与 SpEL 像这样:After Spring 3.1, you can use
<spring:eval />
tag with SpEL like this:要与列表中可能不存在的多个位置一起使用,可以使用 context:property-placeholder bean 来完成:
To use with multiple locations in a list which might not be present as can be done with the context:property-placeholder bean:
要在视图中使用递归属性占位符扩展,您需要不同的解决方案,请查看以下答案:
https://stackoverflow.com/ a/10200249/770303
To use recursive property placeholder expansion in views, you need a different solution, take a look at this answer:
https://stackoverflow.com/a/10200249/770303
现在这是您的属性文件
。
这是您的 JSP
Now this is your Properties File
And.
Here goes your JSP
这将向您显示当前模式(您已登录)的表:
这将向您显示 schema 的表,您至少对其具有选择权限:
This will show you the tables of the current schema (which you are logged in):
This will show you the tables of schema , for which you have select rights at least: