FAQ

[Struts-user] Struts encoding problem ?

Dakota Jack
Aug 15, 2006 at 5:47 am
Just a thought, which I hope is helpful:

package com.topiatechnology.mdci.core.framework.util.console;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;

import com.topiatechnology.mdci.core.framework.report.util.UnicodeFormatter;

/** A Java program that demonstrates console based input and output. */
public class CommandLineConsole
implements Serializable
{
/**
* Serial version UID
*/
private static final long serialVersionUID = -6501048949779510612L;

// Create a single shared BufferedReader for keyboard input
private static BufferedReader stdin =
new BufferedReader( new InputStreamReader( System.in ) );

// Program execution starts here
public static void entry ()
{
// Prompt the user
System.out.print( "Type some data for the program: " );

String input = "" ;

while (! "STOP".equals(input.toLowerCase().toUpperCase()))
{
// Read a line of text from the user.
try
{
input = stdin.readLine();
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

// Display the input back to the user.
System.out.println( input + "\n");
System.out.println( "" );

char [] chars = input.toCharArray() ;

String hex = UnicodeFormatter.charToHex(chars[0]) ;
System.out.println("HEX: " + hex) ;
}
}

public static void main(String [] params)
{
System.out.println("START") ;
int input = 0;
byte [] bytes = null ;

try
{
CommandLineConsole.entry () ;
bytes = new byte [input] ;
System.in.read(bytes) ;
} catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

for (int i = 0 ; i < bytes.length; i++)
{
System.out.println(byteToHex(bytes [i])) ;
System.out.println(charToHex(((char)bytes [i]))) ;
}


}

static public String byteToHex(byte b)
{
// Returns hex String representation of byte b
char hexDigit[] =
{
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};

char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] };

return new String(array);
}

static public String charToHex(char c)
{
// Returns hex String representation of char c
byte hi = (byte) (c >>> 8);
byte lo = (byte) (c & 0xff);
return byteToHex(hi) + byteToHex(lo);
}
}
On 8/14/06, Mark Breitner wrote:

If there is any way to escape the character (and all unicode characters) via javascript before I send it - this would be the solution. But I havent found one yet.

-------- Original-Nachricht --------
Datum: Mon, 14 Aug 2006 13:56:11 -0400
Von: Monkeyden <monkeyden@gmail.com>
An: "Struts Users Mailing List" <user@struts.apache.org>
Betreff: Re: Struts encoding problem ?
This avoids the real question. I would have to hear a pretty good case as
to why the character itself needs to be sent to begin with.
On 8/14/06, Chetan Pandey wrote:

Try sending its Unicode Equivalent. Available from www.unicode.org.

CHetan

-----Original Message-----
From: Mark Breitner
Sent: Tuesday, August 15, 2006 12:55 AM
To: user@struts.apache.org
Subject: Struts encoding problem ?

Hi,

I´ve got the problem the I want to send the "€" (Euro) character via
struts and whenever this character appears in a string, all I receive in my
action is an empty string.

Is this an encoding problem and what do I have to do to solve it ?
--


Echte DSL-Flatrate dauerhaft für 0,- Euro*. Nur noch kurze Zeit!
"Feel free" mit GMX DSL: http://www.gmx.net/de/go/dsl

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org






---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
--


Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org

--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
reply

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions