如何制作Tomcat 6服务器JSON内容
当我尝试使用 GET 请求请求不存在的资源时 -
http://localhost:8080/jackrabbit/server/default/jcr:root/user/abc/article/article-1.0.json
我期待 404 响应,但在JSON 格式。但我得到的是 html 响应 -
<html><head><title>Apache Tomcat/6.0.32 - Error report</title>...</body></html>
如何确保此内容以 JSON 格式而不是 HTML 格式返回。我在 web.xml 中指定了以下内容,但这没有帮助 -
<mime-mapping>
<extension>json</extension>
<mime-type>application/json</mime-type>
</mime-mapping>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该配置一个 404 错误页面来设置正确的内容类型并输出 JSON。
其中
/notFoundJSON
映射到使用response.setContentType(..)
的 servlet,并将 JSON 写入response.getWriter()
You should configure a 404 error page that sets the proper content type and outputs JSON.
Where
/notFoundJSON
is mapped to a servlet that usesresponse.setContentType(..)
and writes JSON to theresponse.getWriter()