如何使动态属性在 JSP 标记文件中工作?
因此,根据我的 JSP 参考书以及我在网上可以找到的所有其他参考资料,我应该能够执行以下操作:
<%@ tag dynamic-attributes="dynamicAttributesVar" %>
然后当有人使用我未在属性指令中定义的属性时,我应该能够从“dynamicAttributesVar”映射访问该属性:
<%= dynamicAttributesVar.get("someUnexpectedAttribute") %>
但是,这根本不起作用; 当我尝试时,我只是收到“dynamicAttributesVar 无法解析”错误。
现在,我确实发现(通过查看生成的标签的 Java 类)我可以通过以下方式“破解”工作动态属性变量:
<% Map dynamicAttributesVar = _jspx_dynamic_attrs; %>
现在,除非我也在我的应用程序上使用动态属性参数,否则该破解不起作用。 tag 指令,因此参数似乎正在执行某些操作。
但我想知道的是,我怎样才能让它像其他 JSP 用户那样做呢?
So according to my JSP reference book, as well as every other reference I can find on the web, I'm supposed to be able to do something like:
<%@ tag dynamic-attributes="dynamicAttributesVar" %>
and then when someone uses an attribute that I didn't define in an attribute directive, I should be able to access that attribute from the "dynamicAttributesVar" map:
<%= dynamicAttributesVar.get("someUnexpectedAttribute") %>
However, that doesn't work, at all; I just get a "dynamicAttributesVar cannot be resolved" error when I try.
Now, I did discover (by looking at the generated Java class for the tag) that I can "hack" a working dynamic attributes variable by doing:
<% Map dynamicAttributesVar = _jspx_dynamic_attrs; %>
Now, that hack doesn't work unless I also use the dynamic-attributes parameter on my tag directive, so it seems that the parameter is doing something.
But what I want to know is, how can I make it do what it does for every other JSP user out there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只是想通过回答四年前的问题来获得徽章。
我也遇到了这个问题,并在 O'Reilly 使用 JSTL 而不是 scriptlet。
原始发布者可以使用此代码来获取所有键/值:
这将获取特定值:
Just trying to get a badge for answering a four year old question.
I have this problem as well and came across some help at O'Reilly to use JSTL instead of scriptlets.
The original poster could have used this code to get all keys/values:
This would get a specific value:
“dynamicAttributesVar”不是动态属性放入的页面上下文中的键的名称吗? 所以你可以这样做
,或者如果你必须使用 scriptlet:(
免责声明:我还没有尝试过,我只是在带有直接 Java 实现的标签中使用了动态属性......但这似乎是合理的)
Isn't "dynamicAttributesVar" the name of the key in the page context that the dynamic attributes are put into? So you could do
or if you must use scriptlets:
(Disclaimer: I haven't tried it, I've just used dynamic attributes in tags with direct Java implementations... but it seems reasonable)