Page: 7
Unit-1: The Servlet Technology Model
Q32. Which of the following servlet lifecycle method is guaranteed to run before a servlet
can process any request? [Select one correct answer]
A. doGet( ) B. service( ) C. init() D. detroy( ) E.doPut( )
Q33. Assume that you have a servlet class that extends javax.servlet.http.HttpServlet class
which of the following methods you should override to process only the POST request?
[Select one correct answer]
A. doGet( ) B. service( ) C. doPut( ) D. doPost( ) E. Both B and D
Q34. How would servlet code from a service method (e.g., dopost ( )) retrieve the value of the “User-Agent” header from request? (Choose all that apply.)
A. String userAgent = request.getparameter(“User-Agent”)
B. String userAgent = request.getHeader(“User-Agent”)
C. String userAgent = request.getRequestHeader(“Mozilla”)
D. String userAgent = getServletcontext( ).getInitparameter(“User-Agent”);
Option B show the correct method call passing in the header name as a String parameterQ35. Which HTTP methods are used to show the client what the server is receiving?
[Choose all that apply.]
A. GET B. PUT C. TRACE D. RETURN E. OPTIONS
This method is typically used for troubleshooting, not for production
Q36.Which method of HttpServletResponse is used to redirect an HTTP request to another URL?
A. sendURL ( ) B. redirectURL ( ) C. redirectHttp ( )
D. sendRedirect ( ) E. getRequestDispatcher ( )
Option D is correct and of the methods listed, it’s the only one that exists in HttpServletResponse
Q37. Which HTTP methods are NOT considered idempotent? [Choose all that apply]
A. GET B. POST C. HEAD D. PUT
By design POST is meant to convey request to update the state of the server. In general same update should not be applied multiple times.Q38 Given req is a HttpServletRequest, which gets a binary input stream? [Choose all that apply]
A. BinaryInputStream S = req.getInputStream ( ); B. ServletInputStream S = req.getInputStream ( );
C. BinaryInputStream S = req.getBinaryStream ( ); D. ServletInputStream S = req.getBinaryStream ( );
Option B specifies the correct method and the correct return type
Q39. How would you set a header named “CONTENT-LENGTH” in the HttpServletResponse object?
[Choose all that apply]
A.response.SetHeader(CONTENT-LENGTH, “1024”); B. response.Set Header(“CONTENT-LENGTH”, “1024”);
C. response.setStatus(1024); D. response.setHeader(“CONTENT-LENGTH”, “1024”);
Option B shows the correct way to set an HTTP header with two String parameters one representing the header name and other the value.
Get Answers For All Questions
Page: 7
1
2
3
4
5
6
7
8
9