简体   繁体   中英

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. But for an error page, which method I have to use to get a status code of a response of web application?

HttpServletResponse.getStatus() is the one you're looking for. It is not just for error pages, it is for every servlet responses.

The HttpServletResponse class contains constants for the possible values, eg

  • HttpServletResponse.SC_OK for success (200)
  • HttpServletResponse.SC_BAD_REQUEST for indicating a bad request (400)

httpServletResponse.getStatus() will give you an int value which represents the status code. Open HttpServletResponse class an you ll find the list of the possible status codes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM