Question:What will happen when you attempt to compile and run the following code (assuming menu.jsp is available)?
package com.examulator;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ReqD extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletContext sc = this.getServletContext();
RequestDispatcher dis = sc.getRequestDispatcher("menu.jsp");
if (dis != null){
dis.include(request, response);
}
PrintWriter out = response.getWriter();
out.print("Output after menu.jsp");
}
}
Choose at least one answer.
a. Compilation error, the this object is not available within doGet
b. Compilation and output of the contents of menu.jsp followed by "output after menu.jsp"
c. Compilation and output of the contents of menu.jsp only
d. Compilation but error at runtime.
RequestDispatcher dis = sc.getRequestDispatcher("menu.jsp");
I think here dis has value null.so it does not satisfy the if condition so it execute the further code and get a object of PrintWriter and output the message "Output after menu.jsp".
Source : Marcus 2 exam