当我们使用下面的代码创建 Struts2 复选框时
<s:checkbox name="checkMe" fieldValue="true" label="Check Me for testing"/>
它给出了以下 HTML 表示(我指的是 https://www.mkyong.com/struts2/struts-2-scheckbox-checkbox-example/ )
<input type="checkbox" name="checkMe" value="true" id="xx_checkMe"/>
<input type="hidden" id="__checkbox_xx_checkMe" name="__checkbox_checkMe" value="true"/>
<label for="resultAction_checkMe" class="checkboxLabel">Check Me for testing</label>
是否有办法消除创建隐藏参数,因为它会导致我的应用程序出现安全漏洞
最佳答案
它使用 freemarker 模板 checkbox.ftl
来生成 html 输出。您可以从源存档中复制并修改此模板,然后使用 template
和 templateDir
属性指向自定义模板。
或者使用存档模板,但需要添加 velocity
和 velocity-tools
依赖项。
<s:checkbox name="checkme" template="checkbox.vm" templateDir="template/archive"/>
关于java - 如何在 Struts 2 中渲染没有隐藏字段的复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42701388/