Struts 自定义标签中属性中的变量 [英] Variable in an attribute in Struts custom tag

查看:23
本文介绍了Struts 自定义标签中属性中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在自定义 Struts 标签中使用一个变量,如下所示 -

I am trying to use a variable inside a custom Struts tag something like follows -

for(String currentMacro : (List<String>)(request.getAttribute("individualMacros"))) {
    name = currentMacro.<some-operation>

<html:mce name = "hmtl_<%= name %>" />

类似的东西.但是 <%=name%> 没有被变量值替换.当我使用带有纯 HTML 标签的变量时,它会起作用.

Something like this. But <%=name%> is not replaced with the variable value. It works when I am using the variable with a pure HTML tags.

在这种情况下有什么办法可以做到这一点吗?

Is there any any way to accomplish this in this case?

谢谢.

推荐答案

使用 JSP EL(假设 JSP 2.0,并且您将名称"放入范围).您还可以检查 TLD 是否允许 rtexprs.

Use JSP EL (assuming JSP 2.0, and you put "name" into scope). You could also check to the if the TLD allows rtexprs.

<代码><html:mce name="html_${name}"/>

但是为什么要使用scriptlets呢?很少(曾经?)有充分的理由.

But why use scriptlets? There's rarely (ever?) a good reason.

这篇关于Struts 自定义标签中属性中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆