96(7)
96(7)
1. What is a servlet?
a. A server-side program that handles client requests
b. A client-side program that handles server responses
c. A type of web browser
d. A database connection class
Answer: a
12. Which method of the HttpServlet class is used to handle PUT requests?
a. doPut()
b. doRequest()
c. handlePut()
d. put()
Answer: a
20. Which of the following is a valid way to include another servlet's response?
a. response.sendRedirect()
b. RequestDispatcher.include()
c. response.include()
d. RequestDispatcher.forward()
Answer: b
23. Which of the following methods can be used to set response headers?
a. setHeader()
b. setResponseHeader()
c. addHeader()
d. Both a and c
Answer: d
33. What is the default value for the content type of a response?
a. text/html
b. application/json
c. text/plain
d. application/xml
Answer: a
34. Which of the following methods can be overridden to handle any HTTP request?
a. doGet()
b. doPost()
c. service()
d. handleRequest()
Answer: c
35. What does the request.getSession() method return?
a. A new session every time
b. The current session associated with the request
c. Null if no session exists
d. Both b and c
Answer: d
36. Which object is used to create a PrintWriter for sending character text to the client?
a. ServletOutputStream
b. HttpServletResponse
c. PrintWriter
d. ServletResponse
Answer: b
37. What is the typical use case for the session object in a servlet?
a. To store user preferences
b. To manage database connections
c. To configure servlet parameters
d. To send HTTP requests
Answer: a
servlet-based application?
a. To store session data
b. To configure servlet mappings and initialization parameters
c. To define error pages
d. Both b and c
Answer: d
41. Which of the following methods is called to read the body of an HTTP request?
a. getReader()
b. getInputStream()
c. readRequestBody()
d. Both a and b
Answer: d
48. What type of data can be sent in the body of an HTTP request?
a. Text only
b. Binary data only
c. Both text and binary data
d. Only JSON data
Answer: c
51. Which of the following is a valid way to send binary data in a servlet response?
a. Using PrintWriter
b. Using ServletOutputStream
c. Using BufferedWriter
d. Using Writer
Answer: b
55. Which method can you use to retrieve cookies from a request?
a. getCookies()
b. retrieveCookies()
c. getAllCookies()
d. fetchCookies()
Answer: a
56. How can you set the character encoding of a request?
a. request.setCharacterEncoding()
b. setCharacterEncoding()
c. setEncoding()
d. configureEncoding()
Answer: a
58. Which of the following can be used to manage error pages in a web application?
a. web.xml
b. servlet code
c. JSP files
d. Both a and c
Answer: d
67. Which of the following is a valid way to access the servlet's initialization parameters?
a. getServletConfig().getInitParameter("paramName")
b. getContext().getInitParameter("paramName")
c. getParameter("paramName")
d. getConfigParameter("paramName")
Answer: a
70. Which attribute is used to specify the timeout for a session in web.xml?
a. session-timeout
b. timeout
c. sessionExpiry
d. sessionDuration
Answer: a
74. What type of data can be sent in the query string of a URL?
a. Only text
b. Only binary data
c. Both text and binary data
d. Only JSON data
Answer: a
75. How can you set the character encoding for a response?
a. response.setCharacterEncoding("UTF-8")
b. setEncoding("UTF-8")
c. response.setEncoding("UTF-8")
d. response.setContentType("text/html; charset=UTF-8")
Answer: a
76. Which of the following methods can be overridden to handle HTTP HEAD requests?
a. doGet()
b. doHead()
c. doOptions()
d. doPost()
Answer: b
78.
79. How can you obtain the server's context path in a servlet?
a. request.getContextPath()
b. getContextPath()
c. context.getPath()
d. request.getPath()
Answer: a
83. What happens if you call response.getWriter() after response has been committed?
a. It throws an exception
b. It returns a null PrintWriter
c. It works normally
d. It generates an empty response
Answer: a