In text field if i copy from word , junk character get inserted. While posting parameters from jsp page it remains fine. But while getting the parameter in java it converts into junk. I have used the following code to eliminate junk before insertion. I am using mysql database. (JBOSS 5.1 GA server)
String outputEncoding = "UTF-8";
Charset charsetOutput = Charset.forName(outputEncoding);
CharsetEncoder encoder = charsetOutput.newEncoder();
byte[] bufferToConvert = userText.getBytes();
CharsetDecoder decoder = (CharsetDecoder) charsetOutput.newDecoder();
try {
CharBuffer cbuf = decoder.decode(ByteBuffer.wrap(bufferToConvert));
ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(cbuf));
userText = decoder.decode(bbuf).toString();
} catch (CharacterCodingException e) {
e.printStackTrace();
}
but I am still getting junk character for single quote('') and double quotes(""). I need the string in UTF-8. Can anyone suggest where i may be wrong?
Example: Input -"esgh”. output - â??esghâ?? : Wanted Output - "esgh”.