• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

character encoding

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic