Caused by: org.attoparser.ParseException:

复制代码
报错:
   Caused by: org.attoparser.ParseException: Only variable expressions returning numbers or booleans are allowed in this context, any other datatypes are not trusted in the context of this expression, including Strings or any other object that could be rendered as a text literal. A typical case is HTML attributes for event handlers (e.g. "onload"), in which textual data from variables should better be output to "data-*" attributes and then read from the event handler. (template: "fourteenth/cfgshareimage/list" - line 241, col 65)
    at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
    at org.attoparser.MarkupParser.parse(MarkupParser.java:257)
    at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230)
    ... 83 common frames omitted



修改前代码
复制代码
th:οnclick="getCopyUrl('shareImageUrl1${language.getKey}'“
复制代码
修改后的代码:


<button type="button" class="layui-btn" style="margin-top:30px;"
        th:id="'ID-upload-copy'+${language.getKey}" th:data-url="shareImageUrl1+${language.getKey}" th:οnclick="getCopyUrl(this.dataset.url)">

解释:

1. 通过 data-* 属性传递数据

Thymeleaf 认为在 onclick 等事件处理器中直接插入字符串可能会存在 XSS(跨站脚本攻击)风险,因此不允许将非数值或布尔类型直接用于事件属性。可以考虑将字符串数据存储在 data-* 属性中,然后通过 JavaScript 读取这个 data-* 属性值来动态构建 getCopyUrl()

相关推荐
布列瑟农的星空12 分钟前
重学React——memo能防止Context的额外渲染吗
前端
FuckPatience12 分钟前
Vue 与.Net Core WebApi交互时路由初探
前端·javascript·vue.js
小小前端_我自坚强18 分钟前
前端踩坑指南 - 避免这些常见陷阱
前端·程序员·代码规范
lichenyang45319 分钟前
从零实现JSON与图片文件上传功能
前端
WebGirl22 分钟前
动态生成多层表头表格算法
前端·javascript
hywel1 小时前
一开始只是想整理下书签,结果做成了一个 AI 插件 😂
前端
Metaphor6921 小时前
Java 将 HTML 转换为 Word:告别手动复制粘贴
java·经验分享·html·word
傅里叶1 小时前
SchedulerBinding 的三个Frame回调
前端·flutter
小小前端_我自坚强1 小时前
React Hooks 使用详解
前端·react.js·redux
java水泥工1 小时前
基于Echarts+HTML5可视化数据大屏展示-车辆综合管控平台
前端·echarts·html5·大屏模版