Jetty を使用して Web サービスをテストしていますが、content-type ヘッダーの下に文字セットなしで応答するようにしようとしています。
誰もこれを行う方法を知っていますか?
Response をインターセプトし、CharacterEncoding を null または "" に設定しようとしましたが、例外が発生します。
Jetty 6.1.6 を使用しています。
Jetty を使用して Web サービスをテストしていますが、content-type ヘッダーの下に文字セットなしで応答するようにしようとしています。
誰もこれを行う方法を知っていますか?
Response をインターセプトし、CharacterEncoding を null または "" に設定しようとしましたが、例外が発生します。
Jetty 6.1.6 を使用しています。
I think that this not a matter of which servlet container you use, but what you do with the response inside your servlet. If you set your character encoding by calling ServletResponse's setContentType (2.3) or setCharacterEncoding (2.4, 2.5) with parameter null
or ""
it should work (didn't try myself). But be sure to call the methods named above before calling getWriter, otherwise setting the encoding will have no effect!
私は今それを自分で試しましたが、認めなければなりませんが、私の桟橋は非常に古いものです(4.2。しかし、必要な方法ですべてを行います)。それをTomcat(4.1.29、古いものも)と比較しました。次のコードでコンテンツ タイプを確認しました。
URL tomcatUrl = new URL("http://localhost:18080/ppi/jobperform/headertest")//tomcat;
URLConnection tconnect = tomcatUrl.openConnection();
System.out.println("tomcat: " + tconnect.getContentType());
URL jettyUrl = new URL("http://localhost:13818/ppi/jobperform/headertest")//jetty;
URLConnection jconnect = jettyUrl.openConnection();
System.out.println("jetty: " + jconnect.getContentType());
そして結果は次のようになりました。
サーブレット コード:
response.setContentType("");
response.getWriter().write("Return");
=>
tomcat: ;charset=ISO-8859-1
突堤:
サーブレット コード:
response.setContentType("text/plain");
response.getWriter().write("Return");
=>
tomcat: テキスト/プレーン;charset=ISO-8859-1
桟橋: テキスト/プレーン
サーブレット コード:
response.setContentType("text/plain;charset=UTF-8");
response.getWriter().write("Return");
=>
tomcat: text/plain;charset=UTF-8
桟橋: text/plain;charset=UTF-8
したがって、古い桟橋はまさにあなたが望んでいることを行うように見えますが、Tomcat は新しい桟橋から得たものを行います。