社区
Java EE
帖子详情
spring mvc如何去掉Content-Type中的charset
cyc123007512
2016-09-23 11:17:13
response返回的结果:
Content-Type:audio/mpeg;charset=UTF-8
后台:
response.setContentType("audio/mpeg");
response.setCharacterEncoding("utf-8"); 把这行注释掉,前端看到还有charset=UTF-8
想把charset=UTF-8这段去掉可以吗?
...全文
783
2
打赏
收藏
spring mvc如何去掉Content-Type中的charset
response返回的结果: Content-Type:audio/mpeg;charset=UTF-8 后台: response.setContentType("audio/mpeg"); response.setCharacterEncoding("utf-8"); 把这行注释掉,前端看到还有charset=UTF-8 想把charset=UTF-8这段去掉可以吗?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
cyc123007512
2016-09-23
打赏
举报
回复
web.xml <filter> <filter-name>encodingFilter</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> <init-param> <param-name>forceEncoding</param-name> <param-value>
false
</param-value> </init-param> </filter> java代码: response.setCharacterEncoding(null); 之前一直不生效是红色的地方为true,改为false,并在后台设置为null即可
花谢尊前不敢香
2016-09-23
打赏
举报
回复
手动设为null看下。
记一次Content type 'application/json;
char
set
=UTF-8' not supported解决方案
本文记录了解决
Spring
MVC
在接收到Content type 'application/json;
char
set
=UTF-8'请求时出现不支持错误的过程。问题出现在StringHttpMessageConverter无法处理JSON请求,通过添加Jackson依赖并注册JsonMessageConverter到
Spring
容器
中
,成功解决了该问题。
Spring
MVC
Content type ‘application/json;
char
set
=UTF-8’ not supported问题
博客围绕
Spring
MVC
出现Content type ‘application/json;
char
set
=UTF-8’ not supported问题展开。提出若在
Spring
MVC
配置类使用@Bean注解,可注释或删掉;要注意Web文件夹创建及配置;若问题未解决,可能是project Structure出错,需检查tomcat配置,还可借助自动配置web.xml的插件。
content-type
java_
Content-Type
详解
Content-Type
是HTTP协议
中
用于标识请求和响应
中
数据类型的字段,常见于邮件、HTTP请求和响应。它包括type/subtype和可选参数,如
char
set
。常见的类型有text/html用于HTML,application/json用于JSON数据,application/x-www-form-urlencoded用于表单提交,multipart/form-data用于文件上传。设置正确的
Content-Type
对于HTTP通信至关重要,如
Spring
MVC
中
@RequestBody需配合application/json。
【
Spring
Boot】 解决报错Content type ‘multipartform-data; boundary=...;
char
set
=UTF-8‘ not supported
本文主要解决
Spring
Boot
中
Content type ‘multipart/form-data; boundary=…;
char
set
=UTF-8’ not supported报错。指出form-data和x-www-form-urlencoded不能用@RequestBody,可用@RequestParam。介绍了@RequestParam和@RequestBody的使用场景,最后给出解决方法,将@RequestBody改为@RequestParam。
SSM之一步一坑:
Spring
MVC
配置
Content-Type
消息头 返回 application/json;
char
set
=utf-8
本文讲述使用SSM搭建Web系统时,配置返回JSON格式遇到的问题。测试结果并非理想的JSON数据,经查看发现是response的content type不符合期望。通过@RequestMapping注解
中
的produces动态设置返回数据格式,解决了该问题,并附上
spring
官方文档说明。
Java EE
67,536
社区成员
225,852
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章