gpt4 book ai didi

java - 如何从jsp访问java接口(interface)

转载 作者:行者123 更新时间:2023-11-30 04:30:11 25 4
gpt4 key购买 nike

我试图从我的 jsp 访问常量接口(interface),但它显示以下错误。

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>
....

最佳答案

开设一个类。将列表放在一个类中。使用正常的 OGNL 静态属性访问:

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

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

关于java - 如何从jsp访问java接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14824472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com