没有Charset的Jetty响应 [英] Jetty Response with no Charset
问题描述
我使用Jetty来测试我们有的web服务,我想让它在内容类型头下没有字符集响应。
I'm using Jetty to test a webservice we have and I am trying to get it to respond with no charset under the content-type header.
知道如何做到这一点?
我已经尝试拦截响应并将CharacterEncoding设置为null或但是给出了异常。
I've tried intercepting the Response and setting the CharacterEncoding to null or "" but that gives Exceptions.
我正在使用Jetty 6.1.6。
I am using Jetty 6.1.6.
推荐答案
承认,我的码头是一个很老的(4.2,但做一切我需要的方式)。我把它比作tomcat(4.1.29,老太)。我使用以下代码检查了内容类型:
I tried it my self now, but I must admit, my jetty is a very old one (4.2., but does everything the way I need it). I compared it to tomcat (4.1.29, old too). I checked the content type with the following code:
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());
结果如下:
Servlet代码:
Servlet code:
response.setContentType("");
response.getWriter().write("Return");
=>
tomcat:; charset = ISO-8859-1
jetty:
=>
tomcat: ;charset=ISO-8859-1
jetty:
Servlet代码:
Servlet code:
response.setContentType("text/plain");
response.getWriter().write("Return");
=>
tomcat:text / plain; charset = ISO-8859- 1
jetty:text / plain
=>
tomcat: text/plain;charset=ISO-8859-1
jetty: text/plain
Servlet代码:
Servlet code:
response.setContentType("text/plain;charset=UTF-8");
response.getWriter().write("Return");
=>
tomcat:text / plain; charset = UTF-8 < br>
jetty:text / plain; charset = UTF-8
=>
tomcat: text/plain;charset=UTF-8
jetty: text/plain;charset=UTF-8
所以看起来好像老的jetty确实是你想要的,你从更新的码头。
So it looks as if the older jetty does exactly what you want, while tomcat does what you got from the newer jetty.
这篇关于没有Charset的Jetty响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!