|
SCWCD : Building JSP Pages Using the Expression Language (EL) Mock Exam Practice Questions
Questions no -1
If the servlet code
public class testServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
request.setAttribute("attribute1", "attribute1");
HttpSession session = request.getSession();
session.setAttribute("attribute2", "attribute2");
ServletContext application = getServletContext();
application.setAttribute("attribute3","attribute3");
RequestDispatcher dispatcher =
request.getRequestDispatcher("/test.jsp");
dispatcher.forward(request, response);
}
}
and in the test.jsp
attribute1:
attribute2:
attribute3:
What is the value of attribute1, attribute2, attribute3 ?
options
A)attribute1: attribute1 attribute2: attribute2 attribute3: attribute3
B)attribute1: attribute1 attribute2: null attribute3: null
C)attribute1: null attribute2: null attribute3: attribute3
D)attribute1: attribute1 attribute2: null attribute3: attribute3
Correct answer is : A
Explanations : is same as pageContext.findAttribute("attribute1").
pageContext.findAttribute() find in request then session then application scope.
Questions no -2
If in test.jsp
${3+2-1} : 4
What is the output?
options
A)${3+2-1} : 4
B)$4 : 4
C)4 : 4
D)\4 : 4
Correct answer is : A
Explanations :
adding \ before EL , does not execute the EL.
${3+2-1} : 4 value is ${3+2-1} : 4
| |