试一下在web.xml中配置spring的编码设置:代码如下:(注意要放在web.xml的最上方,我的是只有这样才有用)<!-- 编码配置 -->
    <filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

解决方案 »

  1.   

    web.xml文件里我是做了配置的。反复测试了下,发现普通的请求后,后台报异常返回的中文是正确的。只有在文件上传操作时后台报异常后返回的中文就是乱码。
      

  2.   

    <value>text/html;charset=UTF-8</value>加上这个
      

  3.   

    真的就是这个地方少了一种text/html 文件格式的配置。加上就好了非常感谢
      

  4.   

    我spring mvc上个月刚刚接触,我公司的一个中型项目我一个人啃了,还用我那时候不会的spring mvc,哈哈
      

  5.   

    您好!我也遇到同样的问题,我用的是Spring MVC4.0.
    但是配置了
    <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter">
    <property name="supportedMediaTypes">
    <list>
    <value>text/plain;charset=UTF-8</value>
    <value>text/html;charset=UTF-8</value>
    <value>application/json;charset=UTF-8</value> 
    </list>
    </property>
    </bean> <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
    <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
    <property name="messageConverters">
    <list>
    <ref bean="mappingJacksonHttpMessageConverter" /><!-- json转换器 -->
       </list> 
    </property>
    </bean>

    <mvc:annotation-driven />统一处理异常代码:@ExceptionHandler(MaxUploadSizeExceededException.class)
    @ResponseBody 
    public String handleException(MaxUploadSizeExceededException ex,HttpServletRequest request) {

    long size_kb = ex.getMaxUploadSize()/1024;

    return "upload file max size must less than 【"+size_kb+" KB.";
    }页面返回乱码:
    upload file max size must less than ?5 KB.
    若您有空,可直接回复评论。或把您的Spring配置发我邮箱一份([email protected])。
    感谢。
    祝工作顺利。