JPS useBean with HashMap

会有一股神秘感。 提交于 2019-12-11 01:08:05

问题


How do I use jsp:useBean with collections like Lists and Maps correctly?

I can get Lists by using

    type="List<MyObject>"

but I cannot get the List to instantiate if nothing is passed.

    class="ArrayList<MyObject>"

And the above attribute gives an error:

The value for the useBean class attribute ArrayList<MyObject> is invalid.

And both the attributes fail for a HashMap.

Currently, I'm reading the objects using getAttribute() but it'll be cleaner to use the tags and set them up.


回答1:


Have you tried just

class="java.util.ArrayList"

Remember, the actual type name doesn't include the generic type, that's syntactic sugar used within the Java language itself, and <jsp:useBean> isn't part of the Java language.



来源:https://stackoverflow.com/questions/3263642/jps-usebean-with-hashmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!