Which of the following HTTP methods are not idempotent?
A POST
B GET
C HEAD
D PUT
Answer
A
HTTP 1.1 declares POST as non idempotent
If the web application is distributed across multiple JVMs, how many instances of the servlet will be created ?
A 1
B we cannot distribute a web-application in multiple JVMs.
C One instance per JVM
D None
Answer
C
There will be one instance per JVM in distributed web-apps. But there will be only one instance in a single JVM
What is the argument for init() method ? Select all that apply.
A ServletContext
B ServletConfig
C HttpServletConfig
D HttpServlet
E No arguments
Answer
B and E
The init() method is having two overloaded versions in GenericServlet class. The init() that takes a ServletConfig object and init without any parameter. The no-argument init method is simply calling the init with ServletConfig object.
public class MyServlet extends HttpServlet {
private int x = 0;
public MyServlet (int x) {
this.x = x;
}
public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
x++;
PrintWriter out = response.getWriter();
out.println(x);
}
}
What will be the output (assume all imports are done correctly), when invoking MyServlet ?
A
Compiler error
B
Runtime Exception
C
Prints 1 in browser window.
D
Prints the value of x in browser window , depending up on the value used to create the servlet.
Which method is used to retrieve a form value in a JSP or Servlet?
A request.getAttribute(String)
B response.getAttribute(String)
C request.getParameter(String)
D response.getParameter(String)
Answer
C
Option B and D are incorrect because , no such method exist. Option A is incorrect because we cannot use that method for receiving request parameters.
Which is the default HTTP form method?
A POST
B HEAD
C PUT
D GET
Answer
D
The default HTTP form method is GET
HTTP HEAD method is used for ?
A To get the header part of the URL
B To delete a resource from server
C To place a resource on the server
D To connect to the server
Answer
A
HEAD method is used to get only the header part of the requested URL. It will return only header, no body
If a single client makes two requests, how many threads will be created by the container ?
A 0
B 1
C 2
D 3
Answer
C
For each and every request , the container will create a separate thread.
All Servlets implement which interface ?
A HttpServlet
B Servlet
C ServletRequest
D GenericServlet
Answer
B
All Servlets must implement javax.servlet.Servlet interface either directly or indirectly
True or False ? A new servlet is created each time a client request a servlet ?
A True
B false
Answer
B
There will be only one servlet in a JVM (if your servlet is not SingleThreadModel). Each time a client makes the request, the container will create a new thread for handling that request