JSF 1.1 中的字符编码

发布于 2024-11-06 23:40:43 字数 1531 浏览 1 评论 0原文

我正在使用 JSF 1.1 开发一个工具,但遇到了这个问题: 打印为:

./src.cpp: In function ‘int main()’:
./src.cpp:4: error: ‘dsdada’ was not declared in this scope

我的支持 bean 中有一个字符串,它在 txt 文件上

但是当我把它放在 ah:inputTextArea 上时,它是这样的:

./src.cpp: In function ‘int main()’:
./src.cpp:4: error: ‘dsdada’ was not declared in this scope

-

<%@ page contentType="text/html;charset=UTF-8" %>
and this
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>

但它也不起作用。 有人可以告诉我如何解决这个问题吗?感谢

/* String[0] as stdout, String[1] as stderr */
String[] results = sshBO.execCommand(cmd, timeout);

/* Done with SSH things */
sshBO.closeSession();

/* Bring the output and err to the presentation */
msg = results[1]+results[0];
FileServices.saveStringToFile("F:/myoutput.txt", msg);
msg = new String(msg.getBytes("UTF8"), "UTF8"); /* makes no difference */

JSP 页面:

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://sakaiproject.org/jsf/sakai" prefix="sakai" %>

<f:view >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
...

<h:inputTextarea disabled="true" value="#{SSH.msg}" styleClass="myTextArea" />

I'm developing a tool using JSF 1.1 and I'm having this problem :
I have a String in my backing bean which is printed as:

./src.cpp: In function ‘int main()’:
./src.cpp:4: error: ‘dsdada’ was not declared in this scope

on a txt file.

But when I put it on a h:inputTextArea, it goes like this:

./src.cpp: In function ‘int main()’:
./src.cpp:4: error: ‘dsdada’ was not declared in this scope

-

<%@ page contentType="text/html;charset=UTF-8" %>
and this
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>

But it didn't work either.
can somebody tell me how to fix this. Thanks

/* String[0] as stdout, String[1] as stderr */
String[] results = sshBO.execCommand(cmd, timeout);

/* Done with SSH things */
sshBO.closeSession();

/* Bring the output and err to the presentation */
msg = results[1]+results[0];
FileServices.saveStringToFile("F:/myoutput.txt", msg);
msg = new String(msg.getBytes("UTF8"), "UTF8"); /* makes no difference */

on the JSP pages :

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://sakaiproject.org/jsf/sakai" prefix="sakai" %>

<f:view >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
...

<h:inputTextarea disabled="true" value="#{SSH.msg}" styleClass="myTextArea" />

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

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

发布评论

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

评论(2

我早已燃尽 2024-11-13 23:40:43

字符 ' 存在于字节 0xE2 0x80 0x98 的 Unicode 中。当您使用 CP1252(Windows 默认)编码对这些字节进行编码时,您会得到

您需要将 pageEncoding 显式设置为 UTF-8。

<%@ page pageEncoding="UTF-8" %>

这样,它将使用 UTF-8 打印字符隐式设置 Content-Type 标头。

The character exist in Unicode of the bytes 0xE2 0x80 0x98. When you use the CP1252 (Windows default) encoding to encode those bytes, you get ‘.

You need to explicitly set the pageEncoding to UTF-8.

<%@ page pageEncoding="UTF-8" %>

This way it will print the characters using UTF-8 and implicitly set the Content-Type header right.

野生奥特曼 2024-11-13 23:40:43

为了确定转码错误的来源,请在每次转码操作后检查数据。使用类似这个的工具来确定值应该是。

例如,JSP 编写器正在将 Java 字符串从 UTF-16(Java 字符串的编码)转码为 UTF-8。其他转码操作看起来像是从本机系统读取程序输出。

/* String[0] as stdout, String[1] as stderr */
String[] results = sshBO.execCommand(cmd, timeout);

例如,您可以使用如下代码打印字符串的十六进制值:

for (char ch : msg.toCharArray())
  System.out.format("%04x ", (int) ch);

代码点 ' 应打印为 2018。您的文件编写代码可能与读取输入的代码有类似的错误,从而误导您了解问题的根源。


msg = new String(msg.getBytes("UTF8"), "UTF8"); /* makes no difference */

这没有什么区别,因为它获取 UTF-16 数据,将其转码为 UTF-8,然后将其转码回 UTF-16。但除此之外,如果您的字符串已损坏,那就已经太晚了。您正在错误的位置修复错误。

In order to determine the source of your transcoding bug, inspect the data after each transcoding operation. Use a tool like this one to determine what the values should be.

For example, Java strings are being transcoded from UTF-16 (the encoding of Java strings) to UTF-8 by your JSP writer. The other transcoding operation looks like reading program output from the native system.

/* String[0] as stdout, String[1] as stderr */
String[] results = sshBO.execCommand(cmd, timeout);

For example, you can print the hex values of your strings using code like this:

for (char ch : msg.toCharArray())
  System.out.format("%04x ", (int) ch);

The code point should print as 2018. Your file writing code may share a similar bug to the code that reads input, misleading you about the source of the problem.


msg = new String(msg.getBytes("UTF8"), "UTF8"); /* makes no difference */

This makes no difference because it takes UTF-16 data, transcodes it to UTF-8, then transcodes it back to UTF-16. But aside from that, if your string is corrupt, it's already too late. You're fixing the bug in the wrong place.

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