的替代方案是允许更多格式的标签,如 BBcode 或 Wiki

发布于 2024-10-14 10:53:23 字数 264 浏览 2 评论 0原文

我正在设计 JSP 应用程序,我想打印用户输入。我需要类似 标签的东西,但需要一个允许用户进行一些格式化的东西。

首先,我想将 \n 转换为
但我仍然需要所有 XML 转义 > 提供。然后我意识到允许更多的格式会很好,比如 BBcode 或 Wiki 语法。

有没有 JSP 标签库可以实现这一点?

I'm designing JSP application and I want to print user input. I'm in need of something like <c:out> tag but then one that allows user to do some formatting.

To start, I want to translate \n to <br /> but I still need all the XML escaping <c:out> provides. Then I realized that it would be nice to allow more formating, like BBcode or Wiki syntax.

Is there any JSP tag library, which allows that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

快乐很简单 2024-10-21 10:53:23

为什么不使用 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;
}

why not create your own tags, with the use of xml

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

XML file:

<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>

And then you write a little java code of what you want to achive !

e.g. corresponding to tag above simple java code example:

 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;
}
那些过往 2024-10-21 10:53:23

您是否考虑过在需要的地方嵌入像 CKEditor 这样的东西?

http://ckeditor.com/demo

这是一个很棒的工具,但请确保许可证满足您的要求:

< a href="http://ckeditor.com/license" rel="nofollow">http://ckeditor.com/license

一个轻量级的替代方案是 TinyMCE:

http://tinymce.moxiecode.com/

Have you thought about embedding something like CKEditor where you need it?

http://ckeditor.com/demo

It's a great tool, but make sure that the license meets your requirements:

http://ckeditor.com/license

A lightweight alternative to this is TinyMCE:

http://tinymce.moxiecode.com/

幸福不弃 2024-10-21 10:53:23

您还可以考虑使用类似 wiki 的编辑器,例如 stackoverflow 中使用的编辑器:

http://wmd-editor.com/

You could also consider a wiki-like editor, like the one used here in stackoverflow:

http://wmd-editor.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文