私は1つの入力フィールドを持っています。ユーザーは国際ラング文字を含めたいものを書くことができます。問題1つのサーブレットから別のサーブレットにintr文字を転送する
最初のサーブレットがあります。
protected void doWork(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), "UTF8"), true);
out.println("<HTML><HEAD><TITLE>");
...
out.println("<input type=text name=someText style='width:10em;'>");
サーブレットは、次のキーラインを持つ2番目のサーブレットに送信ボタンを進めます。
if(httpRequest.getCharacterEncoding() == null)
httpRequest.setCharacterEncoding("UTF-8");
String someText= httpRequest.getParameter("someText");
私のような奇妙な何かを得る:AAA°iÃüÃöÃçIıたときに、私は、デバッグを進めます。
私は間違っていますか?助けのための
おかげで、直接
httpRequest.setCharacterEncoding("UTF-8");
ヌルをチェックする必要はありませんとUTFへ
あなたの 'PrintWriter'アプローチは不器用です。単にresponse.setCharacterEncoding( "UTF-8") '*を実行してから' response.getWriter() 'を取得するだけです。 'InputStreamReader'でラップする必要はありません。さらに、サーブレットでHTMLを出力することは非常に貧弱です。これはJSPで行う必要があります。 http://stackoverflow.com/tags/servlets/infoとhttp://balusc.blogspot.com/2009/05/unicode-how-to-get-characters-right.htmlも参照してください。 – BalusC