Struts 标签和表达式语言

发布于 2024-07-26 21:51:34 字数 534 浏览 2 评论 0原文

我在 struts2 项目中一起使用表达式语言和 struts 标签时遇到问题。 jsp 文件中的以下代码片段说明了我的问题。 水果对象由 servlet 传递。 我知道错误不是来自 servlet,因为当我注释掉表单代码时,它会正确打印出每个水果。

<c:forEach var="fruit" items="${fruits}">
    <c:out value="${fruit}"/>
    <s:form>
        <s:checkbox label="${fruit}"></s:checkbox>
    </s:form>
</c:forEach>

这不起作用,并返回以下错误:“根据标记文件中的 TLD 或属性指令,属性标签不接受任何表达式”。

我想知道的是,有没有一种方法可以以类似优雅的方式做到这一点,而不需要表达语言? 我真的很想在我的 jsp 页面中使用 struts 标签。 我也尝试过 %{fruit} 但没有成功。

I am having a problem using expression language and struts tags together in a struts2 project. The following code snippet from a jsp file illustrates my problem. The fruits object is passed by a servlet. I know that the error is not from the servlet because when I comment out the form code, it correctly prints out each fruit.

<c:forEach var="fruit" items="${fruits}">
    <c:out value="${fruit}"/>
    <s:form>
        <s:checkbox label="${fruit}"></s:checkbox>
    </s:form>
</c:forEach>

This doesn't work, and the following error is returned: "According to TLD or attribute directive in tag file, attribute label does not accept any expressions".

What I'm wondering is, is there a way to do this in a similar elegant fashion that doesn't require expression language? I really want to use the struts tags for my jsp page. I've also tried with %{fruit} with no luck.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昵称有卵用 2024-08-02 21:51:34

我建议更仔细地阅读 Struts 标签的文档。

您的代码失败,因为 s:checkbox 标签不接受表达式。 它应该只是一个简单的标签,如下所示

<s:checkbox label="Male" name="male" value="true" />
<s:checkbox label="Female" name="male" />

对于上面的示例,s:checkboxlist 可能效果更好。 请参阅 http://struts.apache.org/2.0.6/docs/checkboxlist .html 了解更多信息。

I suggest reading the docs for the Struts tags more carefully.

Your code is failing because the s:checkbox label doesn't accept expressions. It should be just a plain label something like the following

<s:checkbox label="Male" name="male" value="true" />
<s:checkbox label="Female" name="male" />

For your example above the s:checkboxlist may work better. See http://struts.apache.org/2.0.6/docs/checkboxlist.html for more information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文