[英]Retrieveing status code from a response in java
How to retrieve a response code for an error page? 如何检索错误页面的响应代码? For successful page I am using
getresponsecode
method. 对于成功的页面,我正在使用
getresponsecode
方法。 But for an error page, which method I have to use to get a status code of a response of web application? 但是对于错误页面,我必须使用哪种方法来获取Web应用程序响应的状态码?
HttpServletResponse.getStatus()
is the one you're looking for. HttpServletResponse.getStatus()
是您要寻找的那个。 It is not just for error pages, it is for every servlet responses. 它不仅用于错误页面,还用于每个servlet响应。
The HttpServletResponse
class contains constants for the possible values, eg HttpServletResponse
类包含可能值的常量,例如
HttpServletResponse.SC_OK
for success (200) HttpServletResponse.SC_OK
成功(200) HttpServletResponse.SC_BAD_REQUEST
for indicating a bad request (400) HttpServletResponse.SC_BAD_REQUEST
用于指示错误的请求(400) httpServletResponse.getStatus()
will give you an int value which represents the status code. httpServletResponse.getStatus()
将为您提供一个表示状态代码的int值。 Open HttpServletResponse
class an you ll find the list of the possible status codes 打开
HttpServletResponse
类,您将找到可能的状态代码列表
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.