<s:if> 在 JSP 中使用 JavaScript 和 Struts 2 时显示错误

<s:if> showing error while using JavaScript in JSP with Struts 2

我的JSP代码:

<script>
<s:if test="hasActionErrors()">
       if ($("input[name=radio_workitem]:checked").length > 0) {
            $("#id_div_workitem_detail").show();
        }
    </s:if>
</s:if>

on s:if, JSP 将鼠标悬停在其上时显示编译时错误(如 s:if 下的拼写错误红线),显示消息 "Syntax error on token "if", ( expected after this token"

虽然这段代码工作正常。没问题。

我的问题是:

  1. 为什么它显示错误,虽然它有效?
  2. 在 JavaScript 中编写 Struts 标记是好的编码习惯吗?

我正在使用 eclipse Luna IDE。

why it shows error, although it works ?

它有一个语法错误,尽管它可能有效,但 eclipse 无法验证其语法。

is this good coding practice to write struts tag in javascript ?

javascript 应该是 javascript,不要把 jsp 代码和 javascript.

搞混了

I m using eclipse Luna Ide.

Eclipse 是世界上最好的免费 IDE。但它可能有错误或缺少一些对您很重要的功能。

<s:if test="hasActionErrors()">
    <script>
      if ($("input[name=radio_workitem]:checked").length > 0) {
    $("#id_div_workitem_detail").show();
      }
    </script>
</s:if>

this answer 中所述,您还可以将 struts 标记包含在 <![CDATA[]]> 部分中。