【问题标题】:Adding <pre> causes table cell to BLOW UP?添加 <pre> 会导致表格单元格炸毁?
【发布时间】:2011-08-04 12:04:57
【问题描述】:

我使用“pre”标签来允许 textarea 框通过换行符,因为我在表单被替换时将 html 剥离出来。问题在于添加“pre”......我的表格单元格扩大到巨大的比例,我不知道为什么......

提前致谢

前置标记前:

前置标记后:

这是该表的代码:

<form id="commentForm" name="commentForm" action="" method="post">
<ctl:vertScroll height="300" headerStyleClass="data_table_scroll" bodyStyleClass="data_table_scroll" enabled="${user.scrollTables}">
<ctl:sortableTblHdrSetup topTotal="false" href="show.whatif_edit_entry?entryId=${entry.entryId}"/>
<table class="data_table vert_scroll_table" style="width:360px;">
    <tr>
    <ctl:sortableTblHdr styleClass="center" title="Comments" property="comment" type="top">Comments</ctl:sortableTblHdr>    
    <ctl:sortableTblHdr styleClass="center" title="Created By" property="auditable.createdBy.lastName" type="top">Entered By</ctl:sortableTblHdr>

    </tr>
    <c:forEach var="comments" items="${entry.comments}">


    //PRE HERE!!    ----->>>   <tr id="id${comments.id}">
           <td id="comments-${comments.id}"  style="width:360px;"><pre>${comments.comment}</pre></td>

        <c:choose>
        <c:when test="${comments.auditable != null}">
        <td title="${comments.auditable.createdBy.lastName},  ${comments.auditable.createdBy.firstName} on 
            <fmt:formatDate value="${comments.auditable.createdDate}" pattern="${date_time_pattern}" />"><span class="mouseover_text">${comments.auditable.createdBy.lastName}, ${comments.auditable.createdBy.firstName} on 
        <fmt:formatDate value="${comments.auditable.createdDate}" pattern="${date_time_pattern}" />
        </td>
        </c:when>
        <c:otherwise>
        <td  colspan="1">&nbsp;</td>
        </c:otherwise>
        </c:choose>
        </tr> 
    </c:forEach>

    <c:if test="${lock.locked || form.entryId < 0 }">

    <%-- This is the row for adding a new comment. --%>           

        <tr id="commentRow">              
         <td>
         You have <strong><span id="commentsCounter">${const['COMMENT_MAX_LENGTH'] - fn:length(commentForm.comment)}</span></strong> characters left.<br/>
            <textarea id="comment" name="comment" rows="2" cols="125" style="width:320px;"
                 onkeypress="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
                 onkeydown="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"
                 onkeyup="characterCounter('commentsCounter',${const['COMMENT_MAX_LENGTH']}, this)"></textarea>

                    <a href="javascript:addComment();"><img src="../images/icon_add.gif" border="0" alt="Add"/></a>
        </td>
        <td class="shaded" colspan="1">&nbsp;</td>
        </tr>

    </c:if>
</table>

pre
{
white-space: pre-wrap;                  /* css-3 */
white-space: -moz-pre-wrap !important;  /* Mozilla, since 1999 */
word-wrap: break-word;                  /* Internet Explorer 5.5+ */
width: 99%;
}

【问题讨论】:

  • 更好...你想看哪个特别的 css 函数?
  • 你是否修改了你的css中的pre元素?
  • 我添加了我在“pre”下的 css 中找到的内容......我通常只写 java 的东西......所以我的样式不太好

标签: html jsp tags


【解决方案1】:

您的问题是:width: 99%;pre。删除该行。

【讨论】:

  • 这就是我的想法......但是......代码库中还有 3 个其他页面正在使用“pre”标签......我可以在 css 中添加一些东西以供使用吗这个页面??
  • 克里斯托弗所说的。将一个类添加到您的表 small_pre 例如:&lt;table class="small_pre"> 并在您的 css 中:table.small_pre pre {width:auto;} 确保该行出现在 pre {width: 99%} 语句之后或使用 !important 覆盖它。
【解决方案2】:

不要(ab)使用&lt;pre&gt;。只需使用&lt;c:out&gt; 对用户控制的输入进行 HTML 转义即可防止 XSS。

<c:out value="${comments.comment}" />

【讨论】:

  • 我们不能再使用 ...实际上我在 2 个月前检查了整个代码库并删除了所有 15,000 次出现的情况
  • 那么你造成了一个大问题。每当您在没有&lt;c:out&gt;fn:escapeXml() 的情况下在JSP 中重新显示用户控制的普通数据时,您就创建了一个很大的XSS 漏洞。为什么要删除这些标签?是无知吗?
  • 嘿..主要开发人员做出决定..我只是按下按钮...大声笑
  • 向他们抱怨。这是一个愚蠢的决定。另一方面,您也应该更清楚这一点,并事先抱怨它只会造成 XSS 漏洞。无论如何,如果您有适当的内容版本管理,只需回滚更改。只需按一下按钮即可。
  • 您是否也为其他 15,000 次事件这样做了?它实际上是转义 HTML 的错误位置。它应该在视图侧完成,使用&lt;c:out&gt;。例如,数据库可能已被外部修改。转义 JavaScript 也可以使用 &lt;c:out&gt; 完成。然后&lt;script&gt; 将打印为&amp;gt;script&amp;lt;,绝对不会造成任何伤害。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-30
  • 1970-01-01
相关资源
最近更新 更多