Java库将HTTP状态代码映射到描述? [英] Java library to map HTTP status code to description?

查看:140
本文介绍了Java库将HTTP状态代码映射到描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Webapp编写自定义错误页面(主要是从servlet容器的默认错误页面减少信息泄露)。由于我需要每个错误状态代码的错误页面,所以我必须对每个代码都有明智的响应。据我所知,这些错误页面不一定要特别方便用户使用,而只是将所有内容重定向到一个单一的出错错误页面将非常困难地诊断问题。

I'm in the situation where I'm writing custom error pages for a webapp (primarily to reduce information disclosure from the servlet container's default error pages). Since I need an error page for each error status code, I'm going to have to have a sensible response for each code. As far as I can tell, these error pages don't have to be particularly user-friendly, but simply redirecting everything to a single "it went wrong" error page is going to make diagnosing problems very difficult.

所以我想知道是否有一个Java库提供HTTP状态代码之间的良好映射和简要的可读描述(理想情况下是一个2-4个字摘要,用作页面标题,以及在摘要上展开的1-3句话消息)。那么我可以在JSP中使用这个来为错误类提供一些反馈。如果不是,我可以自己写一个,但是如果发明了轮子,我很乐意使用它们。

So I'm wondering if there is a Java library that provides a good mapping between HTTP status codes and a brief human-readable description of them (ideally a 2-4 word "summary", for use as a page title, as well as a 1-3 sentence message expanding on the summary). Then I could just use this in a JSP to provide some feedback on the class of the error. If not I'm sure I can write one myself, but if wheels have been invented I'm happy to use them.

推荐答案


所以我想知道是否有一个Java
库,提供了一个很好的映射
在HTTP状态代码和一个简短的
人类可读的描述之间
(理想情况下,一个2-4个词摘要,用作
作为页面标题,以及一个1-3
个句子消息,在
摘要上展开)。 p>

So I'm wondering if there is a Java library that provides a good mapping between HTTP status codes and a brief human-readable description of them (ideally a 2-4 word "summary", for use as a page title, as well as a 1-3 sentence message expanding on the summary).

是, Apache Commons HttpClient 具有此功能。 HttpStatus 类具有相同的 int 常量列表,您可以在其他地方找到它们,但它也有一个 static String getStatusText( int) 方法返回状态代码的可读描述。

Yes, Apache Commons HttpClient has this functionality. The HttpStatus class has the same list of int constants that you'll find elsewhere, but it also has a static String getStatusText(int) method that returns a human-readable description of the status code.

这篇关于Java库将HTTP状态代码映射到描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆