【问题标题】:HTML content rendering in JSFJSF 中的 HTML 内容呈现
【发布时间】:2013-11-29 07:26:16
【问题描述】:

我有两个字段:输入和输出。在输入中,我正在编写 html 代码,按下按钮并在输出字段中查看呈现的代码。

   <h:form id="displayForm">
        <p:commandButton value="Execute" actionListener="#{screenController.executeCode}" update="displayForm:output"/>
        <h:inputTextarea value="#{screenModel.input}" rows="20" cols="165"/>
        <br/>
        <h:outputText id="output" value="#{screenModel.output}" escape="false"/>
    </h:form>

但是,当我写的时候

<script>
document.write("1")
</script>

所有页面都已呈现。我完全不了解 java-script,但我有想法。我可以在某些代码上替换文档,而不是仅在“输出”字段上进行渲染。我该怎么做?

【问题讨论】:

    标签: javascript jquery html jsf


    【解决方案1】:

    将其打印在您通过&lt;iframe&gt; 显示的独立页面中。

    无论采用何种方法,将用户控制的输入重新显示为未转义的 HTML 都会在您的服务器上打开一个巨大的 XSS attack 漏洞。您不希望最终用户能够在您的服务器上完全失控地运行 JavaScript。使用诸如Jsoup 之类的 HTML 清理工具清除所有潜在的恶意 HTML 标签和属性。

    【讨论】:

    • 是的,但是如何为iframe的html页面设置值?
    • 您可以为此使用 flash 范围或将标识符作为请求参数传递。
    猜你喜欢
    • 1970-01-01
    • 2020-07-26
    • 2013-09-08
    • 2015-03-27
    • 2019-11-07
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多