0

我有一个带有 NanoHTTPD-Server 的应用程序,它允许通过浏览器编辑笔记。它显示一个 HTML 表单,允许编辑便笺并将其发送到设备。但是如果我输入äöü,它会显示在android“?” 在我的浏览器中“�”。

HTML代码:

<html>
<head><title>Notes</title></head>
<body><h1>Notes</h1><form method=POST>
<textarea name=noe cols='50' rows='10'></textarea>
<br>
<input type=submit value=save></form></body>
</html>

如何显示äöü?

编辑:

Java代码:

    @Override
    public Response serve(String uri, Method method,
            Map<String, String> headers, Map<String, String> parms,
            Map<String, String> files) {
        Response ret = null;
        if (method == Method.GET) ret = new Response(Status.OK, MIME_HTML, getHTML());
        else if (method == Method.POST) ret = saveNote(parms);
        return ret;
    }

    private Response saveNote(Map<String, String> parms) {
        Notizen.notes = parms.get("notiz");
        osl.refresh();
        return new Response(Status.OK, MIME_HTML, getHTML());
    }

    private String getHTML()
    {
        HtmlGenerator hg = new HtmlGenerator();
        String header = hg.start+hg.getSitetitle("Notes")+hg.zwischen+hg.getTitle("Notes");
        String form = hg.getForm("POST")+hg.getInputMultiline("note", Notizen.notes)+hg.brk+hg.getSubmit("save")+hg.endform;
        String end = hg.stop;
        String site = header+form+end;
        return site;
    }

使用者:

public String formatTextUml (String text)
    {
        text = text.replaceAll("ä", "&auml;");
        text = text.replaceAll("Ä", "&Auml;");
        text = text.replaceAll("ö", "&ouml;");
        text = text.replaceAll("Ö", "&Ouml;");
        text = text.replaceAll("ü", "&uuml;");
        text = text.replaceAll("Ü", "&Uuml;");
        return text;
    }
4

2 回答 2

0

“元音变音”必须更改为 HTML 实体,这些实体对这些字符进行编码。在这些情况下,它可以是:&Auml;&Ouml;或者&Uuml; 要获得更具体的帮助,请发布相关代码。

于 2013-06-30T19:38:01.963 回答
0

有一个 unescapeHtml 库:Apache commons lang

(dependencies) compile 'commons-lang:commons-lang:2.3'

import org.apache.commons.lang.StringEscapeUtils;
.
.
String withUmlaut = StringEscapeUtils.unescapeHtml(yourString);
于 2016-02-28T19:56:29.030 回答