Java Servlets and JSP Quiz

Test your knowledge of Java web development including servlets, JSP, HTTP methods, session management, and MVC pattern

20 Questions Published

Questions

Question 1 True/False

Through a ServletContext object, servlets can interact with their enviornment.

  1. True
  2. False
Question 2 Multiple Choice (Single Answer)

To get an object of PrintWriter, we use getWriter() method of class _____________

  1. HttpSession
  2. HttpServletResponse
  3. HttpServletRequest
  4. None
Question 3 Multiple Choice (Single Answer)

A life-cycle method of a servlet is_________________

  1. init()
  2. service()
  3. destroy()
  4. Above All
Question 4 True/False

Servlets are multi threaded

  1. True
  2. False
Question 5 Multiple Choice (Single Answer)

In the init(ServletConfig) method of Servlet life cycle, what method can be used to access the ServletConfig object ?

  1. getServletInfo()
  2. getInitParameters()
  3. getServletConfig()
  4. None
Question 6 Multiple Choice (Single Answer)

What JSP stand for

  1. Java Server Pages
  2. Java Server Programming
  3. Java Service Pages
  4. Java Service Programming
Question 7 True/False

We must have configure and map all jsp files into web.xml

  1. True
  2. False
Question 8 Multiple Choice (Multiple Answers)

JSP can run by

  1. Apache Tomact
  2. Bea WebLogic
  3. Servlets
  4. JSP Engine
Question 9 Multiple Choice (Single Answer)

Syntax of Scriptlet Element

  1. <% code %>
  2. <@jsp code %>
  3. <jsp: scriptlet code />
  4. <%jsp code %>
Question 10 Multiple Choice (Single Answer)

Syntax of Declaration Element

  1. <%! code !%>
  2. <%! code %>
  3. <jsp: scriptlet code />
  4. <%jsp code !%>
Question 11 Multiple Choice (Single Answer)

Choose JavaBean Actions:-

  1. useBean
  2. setProperty
  3. getProperty
  4. All
Question 12 Multiple Choice (Single Answer)

Which of the following archive files can be deployed in a Web Server?

  1. jar
  2. war
  3. jar, war
  4. jar, war, ear
Question 13 Multiple Choice (Single Answer)

What are the support functions that the Container provide ____________?

  1. Communication Support
  2. Life-cycle Management
  3. Multithreading support
  4. All of the above
Question 14 Multiple Choice (Single Answer)

Which of the below statements are true considering MVC design pattern?

  1. Model – Java Class, JSP, View – HTML, Controller – Servlet
  2. Model – Java Class, View – JSP, Controller – Servlet
  3. Model – Java Class, View – JSP, Container – Servlet
  4. Model – Java Beans, View – JSP, HTML, Controller – Servlet, EJB
Question 15 Multiple Choice (Single Answer)

When you have non-idempotent request which Http method satisfy the requirement?

  1. GET
  2. POST
  3. PUT
  4. HEAD
Question 16 Multiple Choice (Single Answer)

Which of the following statements are true?

  1. HttpServletRequest getParameter(...) retrieves the parameter value from the request
  2. HttpServletResponse getAttribute(...) retrieves the attribute value from the response
  3. HttpServletResponse getParameter(...) retrieves the parameter value from the response
  4. HttpServletRequest setParameter(...) sets the parameter value to the request
Question 17 Multiple Choice (Single Answer)

Which method of HttpServletResponse is used to redirect an Http request to another URL?

  1. sendURL()
  2. redirectURL()
  3. sendRedirect()
  4. getRequestDispatcher()
Question 18 Multiple Choice (Single Answer)

What is the recommended way to deal with servlets and thread safety?

  1. Write servlet code to extend ThreadSafeServlet.
  2. Have the servlet implement SingleThreadModel
  3. Synchronize the service method of the servlet
  4. Use local variables exclusively, and if you have to use instance variables, synchronize access to them.
Question 19 Multiple Choice (Single Answer)

Which statements about HttpSession objects are true?

  1. A session whose timeout period has been set to -1 will never expire.
  2. A session will become invalid as soon as the user closes all the browser windows.
  3. A session will become invalid after a timeout period defined by the servlet container.
  4. A session may be explicitly invalidated by calling HttpSession.invalidateSession().
Question 20 Multiple Choice (Single Answer)

Which of the following statements are not true?

  1. URL rewriting may be used by a server as the basis for session tracking.
  2. SSL has a built-in mechanism that a servlet container could use to obtain data used to define a session.
  3. When using cookies for session tracking, the name of the session tacking cookie must be JSESSIONID.
  4. IF a user has cookies disabled in the browser, the container may choose to use a javax.servlet.httpCookielessHttpSession object to track the user's session.