SCWCD : The JavaServer Pages (JSP) Technology Model


Q.1

For debugging purposes, you need to record how many times a given JSP is invoked before the user's session has been created. The JSP's destroy method stores this information to a database. Which JSP code snippet keeps track of this count for the lifetime of the JSP page?

A.   <%! int count = 0; %> <% if ( request.getSession(false) == null ) count++; %>
B.   <%@ int count = 0; %> <% if ( request.getSession(false) == null ) count++; %>
C.   <% int count = 0; if ( request.getSession(false) == null ) count++; %>
D.   <%@ int count = 0; if ( request.getSession(false) == null ) count++; %>
E.    <%! int count = 0; if ( request.getSession(false) == null ) count++; %>

Ans. A


Q2.
For manageability purposes, you have been told to add a "count" instance variable to a critical JSP Document so that a JMX MBean can track how frequent this JSP is being invoked. Which JSP code snippet must you use to declare this instance variable in the JSP Document?

A.   <jsp:declaration> int count = 0; <jsp:declaration>
B.   <%! int count = 0; %>
C.   <jsp:declaration.instance> int count = 0; <jsp:declaration.instance>
D.   <jsp:scriptlet.declaration> int count = 0; <jsp:scriptlet.declaration>

Ans. A


Q3.
Every page of your web site must include a common set of navigation menus at the top of the page. This menu is static HTML and changes frequently, so you have decided to use JSP's static import mechanism.
Which JSP code snippet accomplishes this goal?

A.   <%@ import file='/common/menu.html' %>
B.   <%@ page import='/common/menu.html' %>
C.   <%@ import page='/common/menu.html' %>
D.   <%@ include file='/common/menu.html' %>
E.    <%@ page include='/common/menu.html' %>
F.    <%@ include page='/common/menu.html' %>

Ans. D


Q.4 
In a JSP-centric web application, you need to create a catalog browsing JSP page. The catalog is stored as a List object in the catalog attribute of the webapp's ServletContext object.
Which scriptlet code snippet gives you access to the catalog object?

A.   <% List catalog = config.getAttribute("catalog"); %>
B.    <% List catalog = context.getAttribute("catalog"); %>
C.    <% List catalog = application.getAttribute("catalog"); %>
D.    <% List catalog = servletContext.getAttribute("catalog"); %>

Ans. C


Q.5
In a JSP-centric web application, you need to create a catalog browsing JSP page. The catalog is stored as a List object in the catalog attribute of the webapp's ServletContext object.
Which scriptlet code snippet gives you access to the catalog object?

A.   <% List catalog = config.getAttribute("catalog"); %>
B.   <% List catalog = context.getAttribute("catalog"); %>
C.    <% List catalog = application.getAttribute("catalog"); %>
D.    <% List catalog = servletContext.getAttribute("catalog"); %>

Ans. C


Q.6
The JSP developer wants a comment to be visible in the final output to the browser. Which comment style needs to be used in a JSP page?

A.   <!-- this is a comment -->
B.    <% // this is a comment %>
C.    <%-- this is a comment --%>
D.    <% /** this is a comment **/ %>
Ans. A


Q.7  
You are writing a JSP that includes scriptlet code to declare a List variable and initializes that variable to an ArrayList object. Which two JSP code snippets can you use to import these list types? (Choose two.)

A.   <%! import java.util.*; %>
B.   <%! import java.util.List; import java.util.ArrayList; %>
C.   <%@ page import='java.util.List' import='java.util.ArrayList' %>
D.    <%@ import types='java.util.List' types='java.util.ArrayList' %>
E.    <%@ page import='java.util.List,java.util.ArrayList' %>
F.     <%@ import types='java.util.List,java.util.ArrayList' %>

Ans.  C,E


Q.8 
You have created a JSP that includes instance variables and a great deal of scriptlet code. Unfortunately, after extensive load testing, you have discovered several race conditions in your JSP scriptlet code. To fix these problems would require significant recoding, but you are already behind schedule. Which JSP code snippet can you use to resolve these concurrency problems?

A.   <%@ page isThreadSafe='false' %>
B.    <%@ implements SingleThreadModel %>
C.    <%! implements SingleThreadModel %>
D.    <%@ page useSingleThreadModel='true' %>
E.     <%@ page implements='SingleThreadModel' %>

Ans. A


Q.9 
Which is a benefit of precompiling a JSP page?

A.   It avoids initialization on the first request.
B.   It provides the ability to debug runtime errors in the application.
C.   It provides better performance on the first request for the JSP page.
D.   It avoids execution of the _jspService method on the first request.

Ans. C


Q.10 
You are creating a new JSP page and you need to execute some code that acts when the page is first executed, but only once. Which three are possible mechanisms for performing this initialization code?(Choose hree.)

A.   In the init method.
B.   In the jspInit method.
C.   In the constructor of the JSP's Java code.
D.   In a JSP declaration, which includes an initializer block.
E.    In a JSP declaration, which includes a static initializer block.

Ans. B,D,E


Q.11
To take advantage of the capabilities of modern browsers that use web standards, such as XHTML and CSS, your web application is being converted from simple JSP pages to JSP Document format. However, one of your JSPs, /scripts/screenFunctions.jsp, generates a JavaScript file. This file is included in several web forms to create screen-specific validation functions and are included in these pages with the following statement:

10. <head>

11. <script src='/scripts/screenFunctions.jsp'

12. language='javascript'

13. type='application/javascript'> </script>

14. </head>

15. <!-- body of the web form -->

Which JSP code snippet declares that this JSP Document is a JavaScript file?

A.   <%@ page contentType='application/javascript' %>
B.   <jsp:page contentType='application/javascript' />
C.   <jsp:document contentType='application/javascript' />
D.   <jsp:directive.page contentType='application/javascript' />
E.    No declaration is needed because the web form XHTML page already declares the MIME type of the /scripts/screenFunctions.jsp file in the <script> tag.
Ans. D


Q.12
Given the element from the web application deployment descriptor:

<jsp-property-group>

<url-pattern>/main/page1.jsp</url-pattern>

<scripting-invalid>true</scripting-invalid>

</jsp-property-group>

and given that /main/page1.jsp contains:

<% int i = 12; %>

<b><%= i %></b>

What is the result?

A.   <b></b>
B.   <b>12</b>
C.   The JSP fails to execute.
D.   <% int i = 12 %> <b><%= i %></b>

Ans. C


Q.13 

Which ensures that a JSP response is of type "text/plain"?

A.   <%@ page mimeType="text/plain" %>
B.   <%@ page contentType="text/plain" %>
C.   <%@ page pageEncoding="text/plain" %>
D.   <%@ page contentEncoding="text/plain" %>
E.    <% response.setEncoding("text/plain"); %>
F.    <% response.setMimeType("text/plain"); %>
Ans. B


Q.14
Which implicit object is used in a JSP page to retrieve values associated with <context-param> entries in the deployment descriptor?

A.   config
B.   request
C.   session
D.   application
Ans. D





Thanks For Making This Possible! Kindly Bookmark and Share it.

Technorati Digg This Stumble Stumble Facebook Twitter

3 comments:

  1. you are making for that protection many enjoyable factors right here that I to hand your article multiple technology. Your perspectives are according inside the midst of my very own for the most proportion. this is permissible content in your readers. Guest Post

    ReplyDelete
  2. Awesome article, it was exceptionally helpful! I simply began in this and I'm becoming more acquainted with it better! Cheers, keep doing awesome! Bolt Posts

    ReplyDelete
  3. Hello I am so delighted I located your blog, I really located you by mistake, while I was watching on google for something else, Anyways I am here now and could just like to say thank for a tremendous post and a all round entertaining website. Please do keep up the great work. bulk sms api Qatar

    ReplyDelete