Java Servlets and JSP

This test covers advanced Java web programming topics including Servlets, JSP, HTTP protocol, session management, and web application lifecycle components. Useful for GATE and other competitive exams.

16 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

Which of the following is/are the correct statements about the setHeader method of the HttpServletResponse interface?

  1. This method allows us to add a name/value field to the response header.
  2. By using this method, the web server sends a special method to the browser to request another page.
  3. This method allows us to get the parameter names and values.
  4. This method can be used in HttpServletRequest interface.
  5. Both (1) and (2)
Question 2 Multiple Choice (Single Answer)

Which of the following is/are correct about the getAttribute method and the getAttributeNames method in the Servlet?

  1. The getAttributeNames method returns the enumeration of Strings representing the names of the attributes and getAttribute method returns the objects bound to that name.
  2. The getAttribute method returns an integer representing the minor version of the Servlet API.
  3. The getAttribute method stores an object in the servlet context and binds the object to a given name.
  4. The getAttribute method returns the Servlet API.
  5. Both (1) and (2)
Question 3 Multiple Choice (Single Answer)

Which of the following statements is/are correct regarding the getParameterValues method?

  1. This method accepts only a single argument.
  2. This method can accepts multiple arguments.
  3. This method returns an array of Strings containing all the values for that parameter.
  4. Both options 1 and 3
  5. Both options 2 and 3
Question 4 Multiple Choice (Single Answer)

Which of the following methods is used to clear the buffer content and the status code and headers?

  1. public void resetBuffer()
  2. public void rest()
  3. public void getBuffer()
  4. public void setBufferSize()
  5. None of the above
Question 5 Multiple Choice (Single Answer)

Which of the following statements is/are not applicable for the GenericServlet class in the Servlet applications?

  1. This is an abstract class which extends the Servlet interface.
  2. It provides protocol independent servlet.
  3. This class has getServletInfo(), getServletName() and getInitParameterNames() methods.
  4. This class has getServletInfo(), getServletName() and getValue() methods.
  5. None of the above
Question 6 Multiple Choice (Single Answer)

Which of the following statements is not applicable for the SingleThreadModel in the Servlet applications?

  1. This is an interface implemented by the servlet.
  2. This is an abstract class which extends the Servlet interface.
  3. The SingleThreadModel ensures that the Servlet will handle one request at a time.
  4. The SingleThreadModel does not have any method.
  5. None of the above
Question 7 Multiple Choice (Single Answer)

Which of the following is true about Buffering the response in the Servlet Application?

  1. Buffering is used to enhance the performance of the servlet.
  2. We can change the default Buffer size.
  3. The default Buffer size is 8.192 characters.
  4. The output of the browser can not be sent until the servlet process is finished or the Buffer is full.
  5. All of the these
Question 8 Multiple Choice (Single Answer)

Which of the following methods is used to return the preferred Locale for the content that the client will accept?

  1. public java.util.Enumeration getLocales()
  2. public java.util.Locale getLocale()
  3. Both 1 and 2.
  4. public java.util.Locales getLocale()
  5. None of the above
Question 9 Multiple Choice (Single Answer)

Which of the following statements is/are not applicable for the exceptions in the Servlet applications?

  1. The javax.Servlet package defines the various exceptions.
  2. A ServletException is known as the generic exception.
  3. The getRootCause method returns the cause of ServletException.
  4. The UnavaiableException determines that the servlet or filter is not available.
  5. None of the above
Question 10 Multiple Choice (Single Answer)

Which of the following is/are correct about JspFactory method in the javax.servlet.jsp package?

  1. It is an abstract class which provides the number of methods to obtain the various runtime objects of the JSP page.
  2. The instance of JspFactory container class is created by the JSP container.
  3. It is an implicit object.
  4. All of the above.
  5. Option 1 and 2.
Question 11 Multiple Choice (Single Answer)

Which of the following informations does the ServletContextListener class provide in the Servlet application?

  1. This class provides notifications in the ServletContext object.
  2. The contextDestroyed() method determines that the Servlet container is shut down.
  3. The contextInitialized() method determines that the web application is ready to service the request.
  4. Option 1 and 3
  5. It is incorrect. Option 5 is correct answer.
Question 12 Multiple Choice (Single Answer)

What is the role of HTTP (Hyper Text Transfer Protocol) for web servers?

  1. HTTP protocol exchanges the data over the web.
  2. Always the connection is established by the client in HTTP.
  3. It manages a stateless connection in the web.
  4. All of the above
  5. Only (1) and (2)
Question 13 Multiple Choice (Single Answer)

What is the significance of HttpSessionActivateListener interface in Servlet application package?

  1. The class implementing this interface determines the notification about the sessions.
  2. The class implementing this interface determines the notification of changes to the HttpSession object's attribute.
  3. This interface defines a session specific to the user requesting the servlet.
  4. Options 1 and 2
  5. None of the above
Question 14 Multiple Choice (Single Answer)

What is the significance of HttpSessionAttributeListener interface?

  1. The class implementing this interface determines the notification about the sessions.
  2. The class implementing this interface determines the notification of changes to the HttpSession object's attribute.
  3. This interface defines a session specific to the user requesting the servlet.
  4. Option 1 and 2
  5. None of the above
Question 15 Multiple Choice (Single Answer)

Which of the following is/are correct statements about Servlet Context object?

  1. ServletContext object can be obtained by the ServletConfig object.
  2. Servlet container creates a ServletContext object.
  3. The removeAttribute method accepts one argument.
  4. The ServletContext object can be serialised.
  5. All of the these
Question 16 Multiple Choice (Single Answer)

Which of the following statements is/are not applicable for the ServletConfig and ServletContext objects?

  1. ServletConfig interface is used to pass the information from the servlet container to the servlet during the servlet initialization.
  2. The getInitParameter() method returns null if the parameter does not exist.
  3. ServletContext object is an interface between the servlet container and a servlet.
  4. The only ServletContext object should be in a web application.
  5. None of the above