2015-01-09 71 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" />