2

JSPアプリケーションを設計していて、ユーザー入力を印刷したいと思います。タグのようなものが必要ですが、<c:out>ユーザーが何らかのフォーマットを行えるようにするものが必要です。

\nまず、翻訳したいのです<br />が、XMLエスケープ<c:out>が提供するすべてのものが必要です。それから私は、BBcodeやWiki構文のようなより多くのフォーマットを許可するのがいいだろうと気づきました。

それを可能にするJSPタグライブラリはありますか?

4

3 に答える 3

1

xmlを使用して独自のタグを作成してみませんか

http://www.java2s.com/Code/Java/JSP/Createyourowntagacustomtagbody.htm

XMLファイル:

<tag>
    <description>
        Escapes a String to HTML, either writing it to the response
        or exporting it to a scoped variable. 
        The string may be the value attribute or the tag body.
    </description>
    <name>escapeHTML</name>
    <tag-class>nl.strohalm.cyclos.taglibs.EscapeHTMLTag</tag-class>
    <body-content>JSP</body-content>

    <attribute>
        <description>
            The string value to be escaped. If not set, the tag body will be used instead.
        </description>
        <name>value</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
        <type>java.lang.Object</type>
    </attribute>
    <attribute>
        <description>If set to true, will only replace line breaks for br tags, ignoring other processing. Defaults to false</description>
        <name>brOnly</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
        <type>boolean</type>
    </attribute>
    <attribute>
        <description>
            A context variable name. If provided, instead of writing the escaped value to the response
            output, it will be set on the scope determined by the scope attribute, under this variable name
        </description>
        <name>var</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
        <type>java.lang.String</type>
    </attribute>
    <attribute>
        <description>
            The scope name for the variable to be exported. 
            May be one of: page, request, session or application.
            Defaults to page.
        </description>
        <name>scope</name>
        <required>false</required>
        <rtexprvalue>true</rtexprvalue>
        <type>java.lang.String</type>
    </attribute>
</tag>

そして、達成したいことの小さなjavaコードを書きます!

たとえば、上記の単純なJavaコード例のタグに対応します。

 public static String escape(final String string, boolean brOnly) {
    String out = string;
    if (!brOnly) {
        out = StringEscapeUtils.escapeHtml(out);
    }
    out = StringUtils.replace(out, "\n", "<br />");
    out = StringUtils.replace(out, "\\n", "<br />");
    return out;
}
于 2011-01-27T09:11:28.137 に答える
0

CKEditorのようなものを必要な場所に埋め込むことを考えたことはありますか?

http://ckeditor.com/demo

これは優れたツールですが、ライセンスが要件を満たしていることを確認してください。

http://ckeditor.com/license

これに代わる軽量の方法はTinyMCEです。

http://tinymce.moxiecode.com/

于 2011-01-24T15:52:24.467 に答える
0

ここでstackoverflowで使用されているようなwikiのようなエディターを検討することもできます。

http://wmd-editor.com/

于 2011-01-24T16:32:25.507 に答える