java - Why this Spring MVC controller returns corrupted UTF-8 String? -
i have modified many places create spring mvc work utf-8, including char filter, contexttype in jsp, , fixed mysql well, project working utf-8.
however, newly added function wouldn't right
@requestmapping(value = "/uploadfile", method = requestmethod.post, produces = "text/plain;charset=utf-8") public @responsebody string uploadfilehandler( @requestparam("name") string name, @requestparam("type") string type, @requestparam("file") multipartfile file//, httpservletresponse response ) throws ioexception { // response.setcharacterencoding("utf-8"); if (file.isempty()) homecoming "Empty";
as can see, have set procudes, , setcharacterencoding. returned string used in ajax , have
var ajax = new xmlhttprequest(); ajax.overridemimetype('text/xml;charset=utf-8');
here origin of form in jsp
<form name = "myform" method="post" onsubmit="return validateform()" enctype="multipart/form-data">
but webpage still shows ????. else missing? don't have jquery, hoping solution without using unless must.
found link responsebody problem homecoming utf-8 string due spring web "bug"
summary:
setorg.springframework.web.filter.characterencodingfilter
in web.xml enforce utf-8 set <value>text/plain;charset=utf-8</value>
in spring-servlet.xml stringhttpmessageconverter
problem eliminated creating own class java ajax spring-mvc utf-8
No comments:
Post a Comment