Tag: web technology

Questions Related to web 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.


Correct Option: A

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


Correct Option: A

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

  1. A listener for HttpSession cannot be specified statically inside a Deployment Descriptor, instead it can be programmatically mentioned.


Correct Option: B

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.


Correct Option: A

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);


Correct Option: C
  1. HttpServletRequest.getWriter();

  2. HttpServlerResponse.getCharacterWriter();

  3. HttpServetRequest.getOutputStream()

  4. HttpServletResonse.getWriter();


Correct Option: D

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.


Correct Option: C

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()


Correct Option: A
  1. An IllegalStateException exception will be thrown because of the presence of

  2. A second call to setAttribute() with the same attribute name will just replace the

  3. The behavior is not defined in the Servlet Specification.

  4. None of the above.


Correct Option: B
Explanation:

To answer this question, the user needs to know about the HttpSession and its setAttribute() method.

Option A: This option is incorrect. IllegalStateException is thrown when we try to set an attribute on an already invalidated session, not when we set an attribute with the same name.

Option B: This option is correct. A second call to setAttribute() with the same attribute name will just replace the previous value associated with the attribute name with the new value.

Option C: This option is incorrect. The Servlet Specification does define the behavior of HttpSession.setAttribute() method when it is called the second time with the same attribute name.

Option D: This option is incorrect as option B is the correct answer.

Therefore, the correct answer is:

The Answer is: B. A second call to setAttribute() with the same attribute name will just replace the previous value associated with the attribute name with the new value.