I want to define a jsp tag, which can accept some extra attributes which are not declared in the .tld file. Is it possible?
I want this because I want to define a <cms:img> tag, which will generate a html img tag. User can pass some attributes to it, but I don’t want to limit user, I hope they can use it just as a normal html img tag.
For example, user can use this tag and pass some required information:
<cms:img id="111" />
Which will generate a html img tag as:
<img src="/show_images?id=111" />
All I need is a id attribute.
But user may treat it as a normal html img tag, and pass some extra attributes to it, like:
<cms:img id="111" width="100px" height="100px" style="..." more attributes .. />
I don’t want to declare the other attributes in my tag, because there are too many, and user may have their custom attributes.
So I want to know: Can I just declare the id attribute in the jsp tag, but let it accept all the other undeclared attributes?
Yes, it’s possible. These are called dynamic attributes. See http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPTags5.html#wp89775: