开发者

Not Able to Read the property value in JSP

开发者 https://www.devze.com 2023-02-27 03:14 出处:网络
I am running a java web application on Java 6 and Spring 3.0. I have properties file used by the web application and is loaded by the spring framework on server start.

I am running a java web application on Java 6 and Spring 3.0.

I have properties file used by the web application and is loaded by the spring framework on server start.

config.properties

url=http://www.url.com
test.url=http://www.test.com
dev.url=http://www.dev.com

I have requirement to use the properties values in java and jsp code. I am able to access the开发者_如何转开发 value in java using annotations provided in spring 3.0 : @Value("${test.url}")

To use the properties in JSP, I am trying to load the properties into servlet context, so that the properties can be referenced in the JSP directly

servletContext.setAttribute("props", properties);

In my jsp, when i print ${props}, it results the following ...

{url=http://www.url.com,test.url=http://www.test.com,dev.url=http://www.dev.com}

But when i print ${props.test.url}, it prints nothing (the same works fine for ${props.url}).

Is this an issue or am i doing something wrong. How can i get the ${props.test.url} work in jsp?


Your EL syntax isn't quite right. Try this:

${props['test.url']}

The ${props.url} syntax works due to a convenience syntax for addressing the contents of a map as though it were a javabean property, but it doesn't work when the map key itself contains a ., in which case you should use the full map-lookup syntax shown above.

0

精彩评论

暂无评论...
验证码 换一张
取 消