0

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?

2 Answers 2

2

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, e.g.

  • HttpServletResponse.SC_OK for success (200)
  • HttpServletResponse.SC_BAD_REQUEST for indicating a bad request (400)
Sign up to request clarification or add additional context in comments.

2 Comments

it showing HttpServletResponse can not be resolved.help me to fix this
@Sakthivel Are you even using Java Servlet? Or Javascript?
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.