word からコピーすると、テキスト フィールドにジャンク文字が挿入されます。jspページからパラメータを投稿している間は問題ありません。しかし、Javaでパラメーターを取得している間、それはジャンクに変換されます。次のコードを使用して、挿入前にジャンクを排除しました。私はmysqlデータベースを使用しています。(JBOSS 5.1 GA サーバー)
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();
}
しかし、私はまだ一重引用符('')と二重引用符("")のジャンク文字を取得しています。UTF-8 の文字列が必要です。誰かが私が間違っているかもしれない場所を提案できますか?
例: 入力 -"esgh". 出力 - â??esghâ?? : 希望する出力 - "esgh".