是否有任何特殊配置导致“application/json” Tomcat 6.0(Spring MVC 3.0)接受mime类型?
有什么必须做的特殊配置吗?还是应该开箱即用?
例如,我应该添加这样的东西才能使其工作吗?
<mime-mapping>
<extension>json</extension>
<mime-type>application/json</mime-type>
</mime-mapping>
Is there any special configuration one must do? or should it work out of the box?
e.g. should I add something like this to make it work?
<mime-mapping>
<extension>json</extension>
<mime-type>application/json</mime-type>
</mime-mapping>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试让 Tomcat 使用正确的 mime 类型提供 .json 文件,那么您需要将该 mime 类型声明添加到 conf/web.xml 文件中。
如果您提供动态生成的 JSON,那么这实际上并不重要:您可以使用
setContentType
函数设置任何 mime 类型。If you are trying to make Tomcat serve .json files with the right mime type then yes, you will need to add that mime type declaration to the conf/web.xml file.
If you're serving dynamically generated JSON then it really shouldn't matter: you can set any mime type using the
setContentType
function.似乎没有特殊的配置,它接受任何开箱即用的 application/json 请求,我怀疑是错误的问题。
请参阅我的另一个问题,它具有原始问题和令人惊讶的愚蠢解决方案: JQuery、Spring MVC @RequestBody 和 JSON - 使其协同工作
It seems there is no special configuration, it accepts any application/json requests out of the box, I was suspecting the wrong issue.
See this other question of mine, it has the original issue and the surprising silly solution: JQuery, Spring MVC @RequestBody and JSON - making it work together