wood burning stoves*
The moose likes JSF and the fly likes character encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "character encoding" Watch "character encoding" New topic
Author

character encoding

Hoa Phan
Greenhorn

Joined: May 14, 2011
Posts: 3
Hi,
I develop 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



I've tried adding this to my jsp page:
<%@ 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
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18886
    
    8

Saying that the data you send is encoded as UTF-8 is a good first step. But then you have to follow up by actually encoding the data you send as UTF-8, and you haven't done that. Make sure that all of your files are UTF-8 files. That includes Java source code, JSF source code, everything. Make sure your text editor or IDE is configured to write files as UTF-8.
Hoa Phan
Greenhorn

Joined: May 14, 2011
Posts: 3
Paul Clapham wrote:Saying that the data you send is encoded as UTF-8 is a good first step. But then you have to follow up by actually encoding the data you send as UTF-8, and you haven't done that. Make sure that all of your files are UTF-8 files. That includes Java source code, JSF source code, everything. Make sure your text editor or IDE is configured to write files as UTF-8.


I'm not sure what to do. To be more precise, mywebapp run in tomcat on a Win7 x64, its request an ssh command to a Ubuntu 10.10 server then get back result from stdout into a String store in backing bean. The String is then output on a h:inputTextArea (which is disable for input cause I only use its as to the output and because JSF do not have outputTextArea -.-"). So, when I run my program I see this on the web:
./src.cpp: In function ‘int main()’:
./src.cpp:4: error: ‘dsdada’ was not declared in this scope

Then I add 1 more line in my action to print this String out to a text file before finish. I open the txt file and saw:
./src.cpp: In function ‘int main()’:
./src.cpp:4: error: ‘dsdada’ was not declared in this scope


:banghead: what should I do :banghead:
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18886
    
    8

So you are saying that data which is incorrectly encoded comes via SSH from another system? Okay, then when you receive it, if you have to convert it from bytes to chars, make sure that you use UTF-8 as the encoding.
Hoa Phan
Greenhorn

Joined: May 14, 2011
Posts: 3
Paul Clapham wrote:So you are saying that data which is incorrectly encoded comes via SSH from another system? Okay, then when you receive it, if you have to convert it from bytes to chars, make sure that you use UTF-8 as the encoding.


I've just tried adding the bold line but it produred exaclty the same result as before.
on the backingBean, in the action:
/* 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.saveStringToSrc("F:/myoutput.txt", msg);
msg = new String(msg.getBytes("UTF8"), "UTF8");


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" ></h:inputTextarea>

Thank you. Is there anything else I can try?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: character encoding