Documente Academic
Documente Profesional
Documente Cultură
Q4.What is the better approach to set some application scoped value stetted from a servlet
1. getServletContext().setAttribute("foo",barObj);
2. application.setAttribute("foo",barObj);
3. Both are good approach
4. None of these
Q5. Which is the right sequence of lifecycle method calls for a HttpServlet?
Q6. Which method of HttpServletResponse is used to redirect an HTTP request to another URL?
1. redirectURL()
2. redirectHttp()
3. sendRedirect()
4. getRequestDispatcher()
Q8. Which of the following is the right placement for servlet class in a web archive file?
A. /WEB-INF/MyServlet.class
B. /WEB-INF/lib/MyServlet.class
C. /WEB-INF/class/MyServlet.class
D. /WEB-INF/classes/MyServlet.class
Q9. How should servlet developers handle the HttpServlet’s service() method when extending HttpServlet?
A. They should override the service() method in most cases.
B. They should call the service() method from doGet() or doPost()
C. They should call the service() method from the init() method.
D. They should override at least one doXXX() method (such as doPost()).
Q12.<context-param>
<param-name>email</param-name>
<param-value>raj@123</param-value>
</context-param>
1. Can be assessed in any servlet/jsp
2. Can be assessed in any servlet but not in jsp
3. Can be assessed in an servlet in which it is defined
4. None of these
Q13.
//assume imports
public class Test extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws Exception{
PrintWriter out = response.getWriter();
out.println("hello"); out.flush();
request.getRequestDispatcher("/More").forward(request, response);}}
Assuming that Servlet in the path /More gets the PrintStream object and prints “hello there”, what will happen when the Test servlet is
requested?
A. Page displays hello
B. Page displays hello there
C. Page throws IllegalStateException
D. Page prints hello and hello there in 2 lines
Q16. The sendError() and sendRedirect() sends the status code equivalent to the static constant
A. SC_NOT_FOUND and SC_MOVED_TEMPORARILY
B. SC_FOUND and SC_MOVED_TEMPORARILY
C. SC_MOVED_TEMPORARILY and SC_NOT_FOUND
D. SC_NOT_FOUND and SC_OK
Q18. What is the recommended way to deal with servlets and thread safety?
A. Write the servlet code to extend ThreadSafeServlet.
B. Have the servlet implement SingleThreadModel.
C. Use local variables exclusively, and if you have to use instance variables, synchronize access to them.
C. Log all servlet method calls.
Q19.
public class Test extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{ response.setContentType("text/html");
HttpSession session = request.getSession();
session.setAttribute("name", "Test");
session.invalidate(); }}
public class SessList implements HttpSessionListener {
public void sessionCreated(HttpSessionEvent arg0) {
System.out.print("Session Created") ;
}
public void sessionDestroyed(HttpSessionEvent arg0) {
System.out.print("Session Destroyed") ;
}}
Test servlet will cause following to be printed in server console
A. Session Created
B. Session Destroyed
C. Session Created Session Destroyed
D. Nothing
Q20. Assuming that session does not exist, the following line
HttpSession session = request.getSession(false);
will result in
A. Returning a null value for the session
B. Throwing an NullPointerException at runtime
C. Returning a blank value
D. Causing compilation error