Java Servlets and JSP Fundamentals

Test your knowledge of Java Servlets, JSP, session management, and web application deployment

16 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What will be the output of the following JSP code snippet at run-time when it is accessed the third time? <% int test = 0; %> <% ++test; %> The value of test is <%= test %>

  1. The value of the 'test' variable will be 2.
  2. The value of the 'test' variable will be 0.
  3. The value of the 'test' variable will be 1.
  4. The variable 'test' must be declared at global scope, else a run-time error will occur
Question 2 Multiple Choice (Single Answer)

Given the deployment descriptor for a Web Application is

  1. The Servlet will output 'javabeat null' in the Server Console.
  2. The Servlet will fail to load as the init param property 'no-name' is not mentioned in the deployment descriptor
  3. A NullPointerException will be raised as calling getServletConfig() in the init() method will return a null reference.
  4. The Servlet will output 'javabeat ' in the Server Console.
Question 3 Multiple Choice (Single Answer)

Which of the following suits best for Java?

  1. Object Oriented
  2. Write Once, Run Anywhere
  3. Compiled Programming language
  4. None of the above
Question 4 Multiple Choice (Single Answer)

For a given ServletResponse response, which retrieves an object for writing binary data?

  1. response.getWriter()
  2. response.getOutputStream()
  3. response.getOutputWriter()
  4. response.getWriter(Writer.OUTPUT_BINARY)
Question 5 Multiple Choice (Single Answer)

Which retrieves all cookies sent in a given HttpServletRequest request?

  1. request.getCookies()
  2. request.getAttributes()
  3. request.getSession (). GetAttributes()
  4. request.getSession ().getCookies()
Question 6 Multiple Choice (Multiple Answers)

Which two prevent a servlet from handling requests.? (Choose two.)

  1. The servlet's init method returns a non-zero status
  2. The servlet's init method throws a Servlet Exception
  3. The servlet's init method sets the Servlet Response's content type to null.
  4. The servlet's init method does NOT return within a time period defined by the servlet container
Question 7 Multiple Choice (Multiple Answers)

A JSP page needs to instantiate a JavaBean to be used by only that page. Which two jsp:useBean attributes must be used to access this attribute in the JSP page?

  1. id
  2. type
  3. name
  4. class
Question 8 Multiple Choice (Single Answer)

In form-based authentication, what must be included in the HTML returned from the URL specified by the element?

  1. a base-64 encoded user name and password
  2. a form that POSTs to the j_security_check URL
  3. an applet that requests the user name and password from the user
  4. a hidden field that supplies the login-constraint used by the application
Question 9 Multiple Choice (Multiple Answers)

Which of the following statements are true about Java Servlets Technology?

  1. A Servlet is a Server-side entity that will rest only on the Server.
  2. The life-cycle management of Servlets is done by the programmer.
  3. Java Servlet Technology provides support for handling XML requests through a special Servlet called XmlServlet.
  4. A Servlet instance is created by the client during the first request to the Servlet Container.
Question 10 Multiple Choice (Multiple Answers)

Which of the following tags is used to set the timeout interval for HttpSession?

  1. session-timeout
  2. session-min-time
  3. session-inactive-time
  4. session-interval-time
Question 11 Multiple Choice (Multiple Answers)

Which of the following is used to define a Listener for HttpSessionListener class in Web Deployment Descriptor?

  1. <session-listener>
  2. <listener>
  3. <http-session-listener>
  4. A listener for HttpSession cannot be specified statically inside a Deployment Descriptor, instead it can be programmatically mentioned.
Question 12 Multiple Choice (Multiple Answers)

Which of the following listener(s) will be called when a Servlet Container initializes a Web Application?

  1. ServletContextListener
  2. ApplicationListener
  3. ApplicationContextListener
  4. None of the above.
Question 13 Multiple Choice (Multiple Answers)

Imagine that you want to set the inactive time for a particular servlet to 10 minutes. Which of the following is the preferred way to do it?

  1. HttpSession.setMinInactiveInterval(10);
  2. HttpSession.setMinInactiveInterval(10 * 60);
  3. HttpSession.setMaxInactiveInterval(10 * 60);
  4. HttpSession.setMaxInactiveInterval(10);
Question 14 Multiple Choice (Multiple Answers)

Which of the following method is used to send response in the form of character data to the client?

  1. HttpServletRequest.getWriter();
  2. HttpServlerResponse.getCharacterWriter();
  3. HttpServetRequest.getOutputStream()
  4. HttpServletResonse.getWriter();
Question 15 Multiple Choice (Multiple Answers)

Assuming that you are developing a Web Application called 'myApp'. You have a file called secret.txt which is part of the original Application, but you don't want your clients to gain access to it. What is the preferred way to do this?

  1. Place the file 'secret.txt' in a directory called 'protected' in the 'myApp' Web Application.
  2. Place the file 'secret.txt' in a directory called 'private' in the 'myApp' Web Application.
  3. Place the file 'secret.txt' in a directory called 'WEB-INF' in the 'myApp' Web Application.
  4. Any filename starting with 'secret' are usually not accessible by the Clients, so this file can be places anywhere in the Web Application.
Question 16 Multiple Choice (Multiple Answers)

Which of the following methods can be used to retrieve all the attributes names from ServletContext?

  1. getAttributeNames()
  2. getAllAttributes()
  3. It is not possible to retrieve all the attributes in one call.
  4. getAttributes()