MCQS Servlet
MCQS Servlet
i) Server Initialization
ii) Servlet Execution
iii) Servlet Destruction
iv) Servlet Stop
2. Which of the following are the advantages of Java Servlet over the other common server extensions.
i) Java servlets are faster than other server extensions like CGI scripts.
ii) Java servlets use a standard API that is supported by many browsers.
iii) Java servlets are portable between server and operating system.
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii
3. Which of the following methods are provided to enable the servlet to process the client’s request.
i) getCookies()
ii) getRequest()
iii) getSession()
iv) getHeader()
4. … are the methods provided by HTTP servlet response to formulate the response to the client.
i) sendRedirect
ii) getWriter
iii) sendError
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii
5. …… method obtains a byte-based output stream that enables binary data to be sent to the client.
A) sendRedirect
B) getOutput()
C) getOutputStream()
D) getWirter
6. ……… method obtains a character-based output stream that enables text data to be sent to the client.
A) sendRedirect
B) getOutput()
C) getOutputStream()
D) getWirter
7. State whether the following statements about the GET method are True.
i) In the GET method entire form submission can be encapsulated in one URL.
ii) The query length is limited to 256 characters.
iii) The data is submitted as a part of the URL.
A) i and ii only
B) ii and iii only
C) i and iii only
D) All i, ii and iii
a) Servlet
b) HttpServlet
c) ServletConfig
d) ServletRequest
9. Which HTTP method is used to retrieve data from a server using a servlet?
a) GET
b) POST
c) PUT
d) DELETE
10. Which of the following is true about servlet containers?
11. What is the purpose of the web.xml file in a servlet-based web application?
a) ServletConfig
b) HttpServletRequest
c) HttpServletResponse
d) ServletContext
16. Which method is used to include the content of another resource during servlet processing?
a) include()
b) import()
c) use()
d) forward()
19. Which of the following code is used to get an attribute in a HTTP Session object in servlets?
a) session.getAttribute(String name)
b) session.alterAttribute(String name)
c) session.updateAttribute(String name)
d) session.setAttribute(String name)
20. Which object of HttpSession can be used to view and manipulate information about a
session?
a. session identifier
b. creation time
c. last accessed time
d. All mentioned above
b) ServletInterface
c) Servlet
d) ServletApp
22. Which method receives and processes client requests?
a) getRequest()
b) processRequest()
c) service()
d) handle()
b) doService()
c) service()
d) handleRequest()
b) 15
c) 20
d) 30
25. Which method is used to retrieve parameter values from the query string?
a) getParams()
b) getParameter()
c) getQuery()
d) fetchParameter()
b) ServletContextListener
c) HttpSessionListener
d) ServletRequestAttributeListener
28. Which annotation is used to define a servlet in the latest versions of the Servlet API?
a) @ServletDefinition
b) @WebServlet
c) @HttpServlet
d) @ServletConfig
29. Which method is used to get all the initialization parameters from the web.xml file?
a) getInitParameters()
b) getConfigParameters()
c) getServletParameters()
d) getInitParameterNames()
30. Which of the following code is used to set content type of a page to be serviced using servlet?
A - response.setContentType()
B - request.setContentType()
C - writer.setContentType()
D - None of the above.
A - Header.getHeaderName(headerName)
B - response.getHeader(headerName)()
C - request.getHeader(headerName)
D - None of the above.
32. Which of the following application servers do not provide built in support for servlets?
a) Tomcat server
b) Glassfish
c) JBoss
d) None of the mentioned
33. Which class can handle any type of request so that it is protocol-independent?
(a) HttpServlet
(b) Request
(c) Http
(d) GenericServlet
(d) ServletContext object can't be nullified but ServletConfig object can be.
35. Which method is used to send the same request and response objects to another servlet ?
(a) forward()
(b) next()
(c) sendForward()
(d) sendRedirect()
(c) XML document that is used by Web Container to run servlets and JSPs.
<web-app>
<servlet>
<servlet-name>DemoServlet </servlet-name>
<servlet-class>DemoServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DemoServlet </servlet-name>
<url-pattern>/Demo</url-pattern>
</servlet-mapping>
</web-app>
(a) /Demo
(b) /*
(c) /DemoServlet
(d) /Servlet
(d) only B
39. When servlet object is created? (select the correct option)
(d) only v)
(b) Program will start execution with main method without any error.
(c) No error but this method will not get executed automatically.
(b) No constructor because Servlet is web class and not java class.
(c) It will give run time error if you write constructor in servlet.
(d) It can have constructor but it is not the right way to initialize servlet.
(a) Servlet
(b) GenericServlet
(c) HttpServlet
(d) ServletConfig
44. Maximum size of data that can be sent using doGet() is?
(a) ServletException
(b) IOExecption
(d) only A
(a) ServletConfig
(b) ServletContext
(c) ServletRequest
(d) ServletResponse
47. controls the behaviour of Java Servlet.
(a) ServletConfig
(b) ServletContext
(d) web.xml
49. How many servlet context object are there per web application?
50 . As long as web application is executing, ______object will be available, and it will be destroyed once the
application is removed from the server.
(a) ServletContext
(b) ServletConfig
(c) ServletRequest
(d) ServletResponse
51. The ____interface provides the facility of dispatching the request to another resource.
(a) ServletRequest
(b) HttpSession
(c) Filter
(d) RequestDispatcher
52. The tasks of authentication, blocking of requests, data compression, Encryption and Decryption are
performed by
(a) response.sendRedirect()
(b) request.sendRedirect()
(c) request.forward()
(d) response.include()