简体   繁体   English

我可以在html标签内使用struts标签来初始化其属性吗?

[英]Can i use struts tags inside the html tags to initialise their attribute?

I am using the following code but haven't tried it yet: 我正在使用以下代码,但尚未尝试过:

<input type="checkbox" id="<bean:write name="element" property="idvalue" />" />

Is it valid ? 有效吗?

And how can it be acheived more efiiciently ? 怎样才能更有效地实现呢?

You can use server tags to initialize attributes of HTML tags. 您可以使用服务器标签来初始化HTML标签的属性。 The code you posted is valid. 您发布的代码有效。

This code: 这段代码:

<input type="checkbox" id="<bean:write name="element" property="idvalue" />" />

evaluates to 评估为

<input type="checkbox" id="theID" />

assuming that "theID" is what's inside the "idvalue" property of your bean. 假设“ theID”是bean的“ idvalue”属性内的内容。

Off course this isn't very easy to read even if you use JSTL as VinAy suggested. 当然,即使您按照VinAy的建议使用JSTL,这也不是很容易阅读。 You will just ed up with something like this: 您将吃完这样的东西:

<input type="checkbox" id="<c:out value="${element.idvalue}" />" />

Again not easy to read if you have an entire JSP full of these. 如果您拥有完整的JSP,那么再次阅读也不容易。

The Struts html tags come in handy here and generate the input by using a construct like: Struts html标记在这里派上用场,并使用类似以下的结构生成输入:

<html:text name="element" property="idvalue" />

which, if you have it inside a <html:form> tag can be further simplified to: 如果您将其包含在<html:form>标记中,则可以将其进一步简化为:

<html:text property="idvalue" />

And if all fails, you can always simplify it as much as you want by writing your own JSP custom tags . 而且,如果一切都失败了,您可以随时编写自己的JSP定制标记来尽可能地简化它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM