2015-01-09 38 views
0

我有DocumentVariable(含blob数据的Struts Bean变量),其中包含数据和Html标记。如何删除html标签并仅显示文本。如何从Jsp中的Blob中删除Html标记

<s:label name="documentDAO.documentAllContent" /> 

<p>/*<br /> &nbsp;* This is a JavaScript Scratchpad.<br /> &nbsp;*<br /> &nbsp;* Enter some JavaScript, then Right Click or choose from the Execute Menu:<br /> &nbsp;* 1. Run to evaluate the selected text (Ctrl+R),<br /> &nbsp;* 2. Inspect to bring up an Object Inspector on the result (Ctrl+I), or,<br /> &nbsp;* 3. Display to insert the result in a comment after the selection. (Ctrl+L)<br /> &nbsp;*/</p> <p>&nbsp;</p> 
+0

为什么你使用''标签在动作类中使用HTML解析器?使用'' - 它默认转义html。 –

+0

我正在使用CKEditor的数据,即使我正在使用我正在使用标签获取数据。

sfhsdfhsdf

sfdhsfdhsfdhsfdhsdfh

hgdf

+0

你想逃避它们吗?如果不是,则将'escapeHtml'属性设置为false。 –

回答

2

这个问题还不清楚,虽然可能值得解释涵盖所有情况。

您使用CKEditor创建HTML,然后将其保存到BLOB字段(应该用于二进制数据,这里您要的是CLOB,但这是另一回事)。

然后你找回你的内容,在这一点上可以有三种不同的期望结果:

  1. HTML(如<b>foo</b>呈现为foo):

    <s:property value="yourVar" escapeHtml="false" /> 
    
  2. 纯文本(例如,<b>foo</b>呈现为<b>foo</b>

    <s:property value="yourVar" /> 
    
  3. 纯/文本不包含HTML标签(如: <b>foo</b>呈现为foo):为此,你需要(如Jsoupdescribed in this answer

    private byte[] yourVar; 
    
    public String getYourVar() { 
        return Jsoup.parse(new String(yourVar, "UTF-8")).text(); 
    } 
    
    <s:property value="yourVar" />