The sendError() method sends what type of information to the client?
A. Response footer.
B. Response header.
C. Content body.
D. None of the above.
Which of the following is a correct sendError() call?
A. response.sendError(HttpServletResponse.SC_FORBIDDEN, "Sorry, restricted to geeks.");
B. request.sendError(HttpServletResponse.SC_FORBIDDEN, "Sorry, restricted to geeks.");
D. response.sendError("Sorry, restricted to geeks.");
The Status-Code element is a three-digit integer code. The first digit of the Status-Code defines the class of response while the last two digits do not have categories, although they are defined in the standard. What classification is used for redirect?
The status codes have been defined by whom?
A. The DSN group.
B. Sun's expert group.
C. The Internet Society.
D. The Apache group.
You need to terminate the request due to an erroneous set of credentials. What method should your servlet respond with?
A. addHeader(String name, String value) method of the response object to add a response header with the given name and value.
B. terminate(String name, int value) to add a response header with the given name and integer value.
C. doTerminate(String location) to send a temporary redirect response to the client so they can try again.
D. response.sendError(HttpServletResponse. SC_NOT_ACCEPTABLE, "Sorry, your crentials are invalid. Please try again.");.
Which method is best for telling the client that all went well and the request was processed successfully?
A. Do nothing. This is the default.
Which method commits the response, effectively terminating it?
How can you return an exception object to the client?
A. You cannot do this.
B. Use sendError.
C. Use setStatus.
D. Use sendException.
Which of the following will throw an IllegalStateException exception?
C. Calling the destroy method before the buffer is flushed.
D. Calling sendError after the response is committed.
D. The sendError() method sends both header and content body type information. This method is overloaded to handle either header only or both.
A. This method is overloaded with two signatures. Only A is correct. B and C are wrong because this method is part of the response object not the request object. D is wrong because you must supply a status code; you can't just send a String message.
B. 3XX is used for redirection. The other codes are 2XX for continuation, 4XX for client error, and 5XX for server error.
C. The Internet Society is the group who defined these codes. The other groups were not involved.
D. This is the correct way to send a “Not Acceptable” status code of 406. The other answers are correct syntax, but don't send the proper status code to the client.
A. This is a difficult question. B, C, and D can be used to send information to the client. C is close because it is sometimes used to send an “OK” status of 200 back to the client. However, A is the correct answer. This particular task should be left to the container.
A. This is the only method that actually terminates the request. sendError() commits the response, if it has not already been committed, and terminates it. No further output to the client can be made because data written to the response after this method is called is ignored.
B. Sending an exception object is not possible without a lot of tweaking. This action is not mentioned anywhere in the specification. See “Returning an Error Code to the Client.”
D. Calling sendError will throw an IllegalStateException exception if the response was already sent (committed). None of the other choices will throw this exception.
Previous Chapter: Quick Recap - Chapters 25 to 29
Next Chapter: Chapter 30 - Servlet API
© 2013 by www.inheritingjava.blogspot.com. All rights reserved. No part of this blog or its contents may be reproduced or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission of the Author.