开发者

lowercase a string with struts?

开发者 https://www.devze.com 2023-02-23 07:15 出处:网络
I have a need to lowercase some text coming back from an external web service in all caps. I need to do this with with struts and not Javascript. Is it possible?

I have a need to lowercase some text coming back from an external web service in all caps. I need to do this with with struts and not Javascript. Is it possible?

I am pretty new to Struts and开发者_C百科 I didn't really find anything searching the tag reference.


Maybe with the toLowerCase() java.lang.String method?


I assume you mean in the jsp? Then the following OGNL in a property tag will work fine:

<s:property value="myStringValue.toLowerCase()"/>

PS: +1 to Enrique but the OP may not have known OGNL expressions of type string could use string methods.


Some beginners are surprised, that

String exVal = "SOMETEXT";
exVal.toLowerCase();

does not work. This is because Strings are immutable in Java, so you need to use

String exVal = "SOMETEXT";
exVal = exVal.toLowerCase();

or just "SOMETEXT".toLowerCase() before use.


If you're using the JSTL: ${fn:toLowerCase(myString)}

0

精彩评论

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