JavaRocks

SCWCD

Question 21

What will be the output of the following JSP code?
<html><body>  <%! int a = 20; %> <% int a = 10; %> <%! int b = 30; %> Now b = <%= b * a %> </body></html>  
 
     A    Now b = 300       
     B    Now b = 600       
     C    The code will not compile       
     D    Now b = 30       
     E    Now b = 0   

Answer
A
In the first declaration <%! int a = 20; %>, the variable "a" will be declared as an instance variable. In the second declaration <% int a = 10; %>, the variable "a" will be declared as a local variable inside the service method. And at the time of multiplication it will use the local variable.

Question 22

Consider the following code snippet of servlet code:
public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        String value = getValue ();
        if (value == null) response.sendError (HttpServletResponse.SC_NOT_FOUND, "Failed");            

        response.sendRedirect ("test.jsp");
}
If the getValue () method returns null , which of the following statements are true?  
 
     A    The code will work without any errors or exceptions           B    An IllegalStateException will be thrown       
     C    An IOException will be thrown       
     D    A NullPointerException will be thrown    

Answer
BSince the response is already committed by calling the sendError() , we cannot redirect it once again.

Question 23

Which of the following can be used to configure the JSP container to ignore EL expressions?   
 
     A    <%@ page isELIgnored="true" %>       
     B    <%@ page isELIgnored="false" %>       
     C    <%@ import isELIgnored="false" %>        
     D    None of the above.    

Answer
D
Configuring the <el-ignored> tag inside the DD is the only way to ignore EL expressions. There was a isELIgnored attribute for page directive in the 2.0 draft version. But it is removed from the final version.

Question 24

What is the default scope for <jsp:useBean>  
 
     A    application           
     B    session       
     C    page        
     D    request

Answer
C
The default scope attribute for useBean is page.

   

Question 25

15 Which of the following is the proper way to include java.util package in your jsp page?  
 
     A    <%@page:import package="java.util">       
     B    <%@ page import = "java.util.*" %>       
     C    <%= import java.util.*; %>        
     D    <%@ page import="java.util.*" %>       
       
Answer
D

Previous        Next

-->Your Ad Here