You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用JSTL c:out作为Struts1 html:checkbox值时遇JasperException错误

问题解决:Struts1 <html:checkbox>标签报"equal symbol expected"错误

错误原因

你在<html:checkbox>的value属性中直接嵌套了<c:out>标签,JSP解析器无法正确识别这种嵌套结构,会将<c:out>的起始标签当作属性值的一部分,导致语法解析失败,抛出"equal symbol expected"错误。

解决方案

方案1:用<c:set>提前存储变量

先将需要的TEMPLATE_ID值存入JSTL变量,再在<html:checkbox>的value属性中引用该变量:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html"%>
<c:forEach begin="0" end="${response.length() -1}" var="index">
    <%-- 提前存储TEMPLATE_ID到变量 --%>
    <c:set var="templateId" value="${response.getJSONObject(index).get('TEMPLATE_ID')}" />
    <tr onClick="myFunction('${templateId}', '${response.getJSONObject(index).getString('TEMPLATE_NAME')}')">
        <td class="break-word">
            <div class="checkbox-inline">
                <div class="chkbox icheckbox_minimal hover" id="check_${templateId}" >
                    <html:checkbox styleClass="iCheck-helper" 
                            style="position: absolute; opacity: 0;" 
                            property="orchTempList" 
                            value="${templateId}" />
                    <ins class="iCheck-helper" 
                            style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;" ></ins>
                </div>
                ${response.getJSONObject(index).getString('TEMPLATE_NAME')}
            </div>
        </td>
    </tr>
</c:forEach> 

方案2:直接使用EL表达式(无需<c:out>)

Struts1标签属性支持EL表达式(只要Web容器版本支持,或在web.xml中配置了EL启用),可以直接在value中写EL,不用嵌套<c:out>:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="html" uri="http://struts.apache.org/tags-html"%>
<c:forEach begin="0" end="${response.length() -1}" var="index">
    <tr onClick="myFunction('${response.getJSONObject(index).get('TEMPLATE_ID')}', '${response.getJSONObject(index).getString('TEMPLATE_NAME')}')">
        <td class="break-word">
            <div class="checkbox-inline">
                <div class="chkbox icheckbox_minimal hover" id="check_${response.getJSONObject(index).get('TEMPLATE_ID')}" >
                    <html:checkbox styleClass="iCheck-helper" 
                            style="position: absolute; opacity: 0;" 
                            property="orchTempList" 
                            value="${response.getJSONObject(index).get('TEMPLATE_ID')}" />
                    <ins class="iCheck-helper" 
                            style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;" ></ins>
                </div>
                ${response.getJSONObject(index).getString('TEMPLATE_NAME')}
            </div>
        </td>
    </tr>
</c:forEach> 

额外注意点

  • 原代码中onClick属性里的双引号嵌套问题,建议将内部的双引号改为单引号(如示例中那样),避免HTML解析时的引号冲突。
  • 若遇到EL表达式不生效的情况,可检查web.xml中是否配置了<el-ignored>false</el-ignored>(针对Servlet 2.4及以上版本)。

内容的提问来源于stack exchange,提问作者star lord

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 13:53:16