lift 无法处理变音符号

发布于 2024-10-09 07:58:57 字数 548 浏览 5 评论 0原文

我正在使用 Lift FrameworkGlassfishV3 开发一个 Web 应用程序,但我的应用程序中的变音符号存在问题。我只是将值绑定到模型,当我记录输入文本字段中的值时,变音符号字母已经损坏。问题可能出在哪里?

     bind("entry",content,
              "place" -> SHtml.text(lib.place, lib.place=_),
              "submit" -> SHtml.submit("Kaboom", () => {
                    Logger.getAnonymousLogger.severe(lib.place)
                    Service.library.save(lib)})
        )

这可能是一个常见的 java 问题,不限于 Lift
我输入 š 并看到 Å¡ 作为记录器的输出。

I'm developing a web app with Lift Framework, GlassfishV3 and there is a problem with diacritics in my app. I do just value binding to model and when I log the value from input text field, the diacritics letters are already broken. Where could possibly be the problem?

     bind("entry",content,
              "place" -> SHtml.text(lib.place, lib.place=_),
              "submit" -> SHtml.submit("Kaboom", () => {
                    Logger.getAnonymousLogger.severe(lib.place)
                    Service.library.save(lib)})
        )

It's probably a general java problem, not limited to Lift.
I enter š and I see Å¡ as the output from logger.

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

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

发布评论

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

评论(4

故人的歌 2024-10-16 07:58:57

如果知道整个问题的根源位于键盘和椅背之间,您会感觉好一点还是坏一点?

发生的事情是这样的:

您想要打印 š,一个 小写 s-with-caron,在 Unicode 中用数字 0x161 表示。您将其打印到文件中,并且您的 I/O 系统尽职地(且正确地)将其编码为 UTF -8 为 0xC5、0xA1。然后您要求查看该文件,没有向您的查看程序解释它是一个 UTF-8 文件。您的查看程序,无论它是什么,都会将该文件解释为 ISO 8859-1,常见但有些陈旧的格式。 0xC5 显示为 Å、A-with-a-ring 和 0xA1作为 ¡,倒置感叹号

总而言之,输出没有任何问题,只是您查看它的方式有问题。在编辑器中打开日志并将编码设置为 UTF-8 或在 Web 浏览器中打开日志并选择 View / Character Encoding / UTF-8 。

Would it make you feel better or worse to know that the source of your entire problem is located between the keyboard and the back of your chair?

Here's what happened:

You wanted to print out š, a lower-case s-with-caron, which is represented in Unicode by the number 0x161. You printed it out to a file, and your I/O system dutifully (and correctly) encoded it in UTF-8 as 0xC5, 0xA1. Then you asked view to that file without explaining to your viewing program that it was a UTF-8 file. Your viewing program, whatever it was, interpreted the file as ISO 8859-1, a very common, if somewhat elderly, format. The 0xC5 was displayed as Å, A-with-a-ring, and the 0xA1 as ¡, an inverted exclamation mark.

To summarize, there's nothing wrong with the output, there's just something wrong with the way you are looking at it. Bring the log up in an editor and set the encoding to UTF-8 or bring it up in a web browser and select View / Character Encoding / UTF-8 .

绻影浮沉 2024-10-16 07:58:57

我的猜测是,线索可能是浏览器。浏览器对页面采用什么编码?你的头部有编码元标签吗?像这样:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

My guess would be that the clue to this might be the browser. What encoding does the browser assume for the page? Do you have an encoding meta-tag in the head; like this:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
忆依然 2024-10-16 07:58:57

这很可能是记录器或控制台的问题。尝试记录到一个文件并在您知道可以处理 UTF8 的编辑器中打开该文件

This could well be a problem in the logger or your console. Try logging to a file and opening that in an editor you know can handle UTF8

云巢 2024-10-16 07:58:57

因此,获取 UTF-8 编码的一个选项是在 sun-web.xml 文件中指定编码,如下所示:

<sun-web-app error-url="">
    <parameter-encoding default-charset="UTF-8"/>
</sun-web-app>

另一个选项是在 lift bootstrapping 类中设置编码:
<代码>

def boot {
    LiftRules.early.append(makeUtf8)
}
private def makeUtf8(req: HTTPRequest) {
    req.setCharacterEncoding("UTF-8")
}

so one option to get UTF-8 encoding is to specify encoding in sun-web.xml file like this:

<sun-web-app error-url="">
    <parameter-encoding default-charset="UTF-8"/>
</sun-web-app>

the other option is to set encoding in lift bootstrapping class:

def boot {
    LiftRules.early.append(makeUtf8)
}
private def makeUtf8(req: HTTPRequest) {
    req.setCharacterEncoding("UTF-8")
}

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