1

我正在尝试从我的 jsp 访问常量接口,但它显示以下错误。

Caused by: tag 'select', field 'list', name 'title': 
The requested list key 'Constants.TITLE' 
could not be resolved as a collection/array/map/enumeration/iterator type. 
Example: people or people.{name} - [unknown location]

我的界面

public interface Constants {
    public List<String> TITLE = Arrays.asList("Mr","Mrs","Ms","Miss"); 
    // public String[] TITLE = {"MR","MRs"}; << does not work as well
   //public static final String[] TITLE = {"MR","MRs"}; << does not work as well
}

我的 Jsp 代码

...
<%@page import="com.myconstants.Constants" %>
<head>
</head>
<body>
     <s:form>
     <s:select label="title" name="title" list="Constants.TITLE" value=" "/>
     </s:form>
 ....
4

1 回答 1

2

做一堂课。将列表放在一个类中。使用普通的 OGNL 静态属性访问:

<s:select key="title" list="@some.package.Constants@TITLES" />

会这样做吗?可能不是; 更难 I18Nize,更难在 JSP 中找到/重构用法(取决于 IDE)。一般来说,我建议通过操作中的服务/层将数据暴露给视图层。

于 2013-02-12T02:40:28.820 回答