SPRING3 MVC uses @responsebody to produce a very large response header (Accept-charset will reach 4k+) because Stringhttpmessageconverter.writeinternal () by default All available character sets are written back to the response response header:
/** * Implementation of {@link Httpmessageconverter} that can read and write strings.
* * <p>by default, this converter supports all media types (<code>*/*</code>), and writes with a {@code * Content-type} of {@code text/plain}.
This can is overridden by setting the {@link * #setSupportedMediaTypes (java.util.List) Supportedmediatypes} property. * * @author Arjen Poutsma * @since 3.0 * * public class Stringhttpmessageconverter extends abstracthttpmessageconverter& Lt
string> {public static final Charset Default_charset = Charset.forname ("iso-8859-1");
Private final list<charset> availablecharsets;
Private Boolean writeacceptcharset = true;
Public Stringhttpmessageconverter () {Super (New mediatype ("text", "plain", Default_charset), Mediatype.all);
This.availablecharsets = new Arraylist<charset> (Charset.availablecharsets (). values ());
}/** * Indicates whether the {@code accept-charset} should is written to any outgoing request. * <p>default is {@code true}.
*/public void Setwriteacceptcharset (Boolean writeacceptcharset) {this.writeacceptcharset = Writeacceptcharset;
} @Override public Boolean supports (Class<?> clazz) {return String.class.equals (clazz); } @Override protected String readinternal (Class clazz, Httpinputmessage inputmessage) throws IOException {mediatype
ContentType = Inputmessage.getheaders (). getContentType (); Charset Charset = Contenttype.getcharset ()! = null?
Contenttype.getcharset (): Default_charset;
Return filecopyutils.copytostring (New InputStreamReader (Inputmessage.getbody (), CharSet)); } @Override protected Long getcontentlength (String S, mediatype ContentType) {if (ContentType! = null && con
Tenttype.getcharset () = null) {Charset Charset = Contenttype.getcharset ();
try {return (long) s.getbytes (Charset.name ()). length; } catch (Unsupportedencodingexception ex) {//should not occur throw new Internalerror (ex.getMessage ());
}} else {return null; }} @Override protected void writeinternal (String s, Httpoutputmessage outputmessage) throws IOException {if (write
Acceptcharset) {outputmessage.getheaders (). Setacceptcharset (Getacceptedcharsets ());
} MediaType ContentType = Outputmessage.getheaders (). getContentType (); Charset Charset = Contenttype.getcharset ()! = null?
Contenttype.getcharset (): Default_charset;
Filecopyutils.copy (S, New OutputStreamWriter (Outputmessage.getbody (), CharSet));
}/** * Return the list of supported {@link Charset}. * * <p>by default, returns {@link charset#availablecharsets ()}.
Can is overridden in subclasses. * * @return The list of accepted charsets */protected list<charset> getacceptedcharsets () {return This.avai
Lablecharsets; }
}
Workaround: Spring3 MVC using @responsebody garbled problem and solution