Struts2从JSP访问枚举 [英] Struts2 accessing enum from JSP
问题描述
我有以下类
package com.test;
public class SomeClass {
public enum COLOR {RED,BLUE}
}
我想在我的JSP中访问 COLOR
枚举的值。我尝试了以下代码,但它不起作用。
< s:property value =@ com.test .SomeClass.COLOR @ RED/>
< s:property value =@ com.test.SomeClass@COLOR.RED/>
以前有哪些机构遇到这个问题?
[我已经在struts.xml中启用静态方法访问]
对于枚举
-s不需要启用静态方法访问
。
可以使用 @
签名获取枚举:
< s:property value =@ package.ENUM@enumvalue/>
在您的情况下,您声明枚举
c code code code code code code code code code $ c $ pre> < s:property value =@ com.test.SomeClass$COLOR@RED/>
I have the following class
package com.test;
public class SomeClass {
public enum COLOR {RED,BLUE}
}
I want to access values of COLOR
enum in my JSP. I've tried the following code but it doesn't work.
<s:property value="@com.test.SomeClass.COLOR@RED"/>
<s:property value="@com.test.SomeClass@COLOR.RED"/>
Any body came across this issue before? [I've already enabled static method access in struts.xml]
For enum
-s there is not need to enable static method access
.
Enum-s can be accessed using @
sign like that:
<s:property value="@package.ENUM@enumvalue"/>
In your case since you are declaring enum
inside class use $
sign to refer to your enum
.
<s:property value="@com.test.SomeClass$COLOR@RED"/>
这篇关于Struts2从JSP访问枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!