Using varargs in a Tag Library Descriptor

后端 未结 4 1589
情话喂你
情话喂你 2021-01-11 17:18

Is it possible to have a TLD map to the following function:

public static  T[] toArray(T... stuff) {
    return stuff;
}

So that I

4条回答
  •  有刺的猬
    2021-01-11 17:43

    One thing I did to get around this was to create a utility function class and set it on the application context when the server starts up, rather than trying to define it as an EL function. You can then access the method in EL.

    So when my servlet starts up:

    context.setAttribute("utils", new MyJSPUtilsClass());

    and on my JSP:

    ${utils.toArray(1, 2, 3, 4)}

提交回复
热议问题