0

私はJSFで働いています。RichFaces の「RichEditor」を使用しました。このエディターからのコンテンツを Bean に格納し、JSF フォームに表示しています。しかし、JSF フォームに HTML タグが表示されます。そのために、JSoup HTML パーサーを使用しました。しかし、リッチエディタの記述内容を完全に単純なテキストに変換し、太字、使用されているボタン、改行などの書式をすべて削除します。エディタとして jSF 形式でそのまま表示する必要があります。

助けてください...

リッチ エディターのコード

            <f:param name="theme_advanced_buttons1" value="
            newdocument,separator,copy,cut,paste,pasteword,undo,redo,separator,bold,italic,underline,
            strikethrough,forecolor,backcolor,separator,
            justifyleft,justifycenter,justifyright,justifyfull,outdent,indent " />

        <f:param name="theme_advanced_buttons2" value= "bullist,numlist,separator,
        insertdate,inserttime,separator,image,emotions,styleprops,fontselect,fontsizeselect,formatselect,search,replace"/>  

        <f:param name="theme_advanced_toolbar_location" value="top"/>                               
        <f:param name="theme_advanced_toolbar_align" value="left"/>
        <f:param name="theme_advanced_font_sizes" value="10px,12px,14px,16px,18px,20px,24px,32px,36px,42px,48px,60px,72px"/>
        <f:param name="theme_advanced_fonts" value="Andale Mono=andale mono,times;
            Arial=arial,helvetica,sans-serif;
            Arial Black=arial black,avant garde;
            Book Antiqua=book antiqua,palatino;
            Calibri=calibri;
            Comic Sans MS=comic sans ms,sans-serif;
            Courier New=courier new,courier;
            Georgia=georgia,palatino;
            Helvetica=helvetica;
            Impact=impact,chicago;
            Symbol=symbol;
            Tahoma=tahoma,arial,helvetica,sans-serif;
            Terminal=terminal,monaco;
            Times New Roman=times new roman,times;
            Trebuchet MS=trebuchet ms,geneva;
            Verdana=verdana,geneva;
            Webdings=webdings;
            Wingdings=wingdings,zapf dingbats"/>

        </rich:editor>   

Javaから....

public String saveNotice() {

    System.out.println(html2text(editor));



    return "";

}


public  String html2text(String editor)
{
    String edit;


    edit=Jsoup.parse(editor).text();
    setEditor(edit);
    return edit;


}
4

2 に答える 2

1

を使用して再表示する場合<h:outputText>、JSF は XSS 攻撃を防ぐためにそれらをエスケープします。HTMLプレーンを再表示するために追加する必要がありescape="false"ます(したがって、Webブラウザーによって解釈されます)。

<h:outputText value="#{bean.html}" escape="false" />

ただし、これは依然として潜在的な XSS ホールです。すでにJsoupを使用Jsoup#clean()しているため、いくつかの基本的な HTML タグを保持し、他のすべての悪意のあるタグを削除するために使用できます。

public String sanitizeHtml(String html) {
    return Jsoup.clean(unsafe, Whitelist.basic());
}

Whitelistカスタマイズ可能です。詳細については、javadocも参照してください。

于 2011-04-01T11:24:00.707 に答える
0

ソースにリッチ エディターの開始タグがありません。編集者のホームページによると、viewModeパラメーターを追加しようとしています。その価値は「視覚的」でなければならないと思います。

于 2011-04-01T11:16:39.247 に答える