QUESTION NO: 21
You need to store a Java long primitive attribute, called customerOID, into the session scope.
Which two code snippets allow you to insert this value into the session? (Choose two.)
A. long customerOID = 47L;
session.setAttribute("customerOID", new Long(customerOID));
B. long customerOID = 47L;
session.setLongAttribute("customerOID", new Long(customerOID));
C. long customerOID = 47L;
session.setAttribute("customerOID", customerOID);
D. long customerOID = 47L;
session.setNumericAttribute("customerOID", new Long(customerOID));
E. long customerOID = 47L;
session.setLongAttribute("customerOID", customerOID);
F. long customerOID = 47L;
session.setNumericAttribute("customerOID", customerOID);
Answer: A,C
QUESTION NO: 22
A developer for the company web site has been told that users may turn off cookie support in their
browsers. What must the developer do to ensure that these customers can still use the web
application?
A. The developer must ensure that every URL is properly encoded using the appropriate URL
rewriting APIs.
B. The developer must provide an alternate mechanism for managing sessions and abandon the
HttpSession mechanism entirely.
C. The developer can ignore this issue. Web containers are required to support automatic URL
rewriting when cookies are not supported.
D. The developer must add the string id=<sessionid> to the end of every URL to ensure that the
conversation with the browser can continue.
Answer: A
QUESTION NO: 23
Your web application requires the adding and deleting of many session attributes during a
complex use case. A bug report has come in that indicates that an important session attribute is
being deleted too soon and a NullPointerException is being thrown several interactions after the
fact. You have decided to create a session event listener that will log when attributes are being
deleted so you can track down when the attribute is erroneously being deleted.
Which listener class will accomplish this debugging goal?
A. Create an HttpSessionAttributeListener class and implement the attributeDeleted method and
log the attribute name using the getName method on the event object.
B. Create an HttpSessionAttributeListener class and implement the attributeRemoved method and
log the attribute name using the getName method on the event object.
C. Create an SessionAttributeListener class and implement the attributeRemoved method and log
the attribute name using the getAttributeName method on the event object.
D. Create an SessionAttributeListener class and implement the attributeDeleted method and log
the attribute name using the getAttributeName method on the event object.
Answer: B
QUESTION NO: 24
As a convenience feature, your web pages include an Ajax request every five minutes to a special
servlet that monitors the age of the user's session. The client-side JavaScript that handles the
Ajax callback displays a message on the screen as the session ages. The Ajax call does NOT
pass any cookies, but it passes the session ID in a request parameter called sessionID. In
addition, assume that your webapp keeps a hashmap of session objects by the ID. Here is a
partial implementation of this servlet:
10. public class SessionAgeServlet extends HttpServlet {
11. public void service(HttpServletRequest request, HttpServletResponse) throws IOException {
12. String sessionID = request.getParameter("sessionID");
13. HttpSession session = getSession(sessionID);
14. long age = // your code here
15. response.getWriter().print(age);
16. } ... // more code here
47. }
Which code snippet on line 14, will determine the age of the session?
A. session.getMaxInactiveInterval();
B. session.getLastAccessed().getTime() - session.getCreationTime().getTime();
C. session.getLastAccessedTime().getTime() - session.getCreationTime().getTime();
D. session.getLastAccessed() - session.getCreationTime();
E. session.getMaxInactiveInterval() - session.getCreationTime();
F. session.getLastAccessedTime() - session.getCreationTime();
Answer: F
QUESTION NO: 25
Which statement is true about web container session management?
A. Access to session-scoped attributes is guaranteed to be thread-safe by the web container.
B. To activate URL rewriting, the developer must use the HttpServletResponse.setURLRewriting
method.
C. If the web application uses HTTPS, then the web container may use the data on the HTTPS
request stream to identify the client.
D. The JSESSIONID cookie is stored permanently on the client so that a user may return to the
web application and the web container will rejoin that session.
Answer: C
QUESTION NO: 26
One of the use cases in your web application uses many session-scoped attributes. At the end of
the use case, you want to clear out this set of attributes from the session object. Assume that this
static variable holds this set of attribute names:
201. private static final Set<String> USE_CASE_ATTRS;
202. static {
203. USE_CASE_ATTRS.add("customerOID");
204. USE_CASE_ATTRS.add("custMgrBean");
205. USE_CASE_ATTRS.add("orderOID");
206. USE_CASE_ATTRS.add("orderMgrBean");
207. }
Which code snippet deletes these attributes from the session object?
A. session.removeAll(USE_CASE_ATTRS);
B. for ( String attr : USE_CASE_ATTRS ) {
session.remove(attr);
}
C. for ( String attr : USE_CASE_ATTRS ) {
session.removeAttribute(attr);
}
D. for ( String attr : USE_CASE_ATTRS ) {
session.deleteAttribute(attr);
}
E. session.deleteAllAttributes(USE_CASE_ATTRS);
Answer: C
QUESTION NO: 27
Assume that a news tag library contains the tags lookup and item:
lookup Retrieves the latest news headlines and executes the tag body once for each headline.
Exposes a NESTED page-scoped attribute called headline of type com.example.Headline
containing details for that headline.
item Outputs the HTML for a single news headline. Accepts an attribute info of type
com.example.Headline containing details for the headline to be rendered.Which snippet of JSP
code returns the latest news headlines in an HTML table, one per row?
A. <table>
<tr>
<td>
<news:lookup />
<news:item info="${headline}" />
</td>
</tr>
</table>
B. <news:lookup />
<table>
<tr>
<td><news:item info="${headline}" /></td>
</tr>
</table>
C. <table>
<news:lookup>
<tr>
<td><news:item info="${headline}" /></td>
</tr>
</news:lookup>
</table>
D. <table>
<tr>
<news:lookup>
<td><news:item info="${headline}" /></td>
</news:lookup>
</tr>
</table>
Answer: C
QUESTION NO: 28
Which JSTL code snippet can be used to perform URL rewriting?
A. <a href='<c:url url="foo.jsp"/>' />
B. <a href='<c:link url="foo.jsp"/>' />
C. <a href='<c:url value="foo.jsp"/>' />
D. <a href='<c:link value="foo.jsp"/>' />
Answer: C
QUESTION NO: 29
Assume the scoped attribute priority does NOT yet exist. Which two create and set a new requestscoped
attribute priority to the value "medium"? (Choose two.)
A. ${priority = 'medium'}
B. ${requestScope['priority'] = 'medium'}
C. <c:set var="priority" value="medium" />
D. <c:set var="priority" scope="request">medium</c:set>
E. <c:set var="priority" value="medium" scope="request" />
F. <c:set property="priority" scope="request">medium</c:set>
G. <c:set property="priority" value="medium" scope="request" />
Answer: D,E
QUESTION NO: 30
You are creating a JSP page to display a collection of data. This data can be displayed in several
different ways so the architect on your project decided to create a generic servlet that generates a
comma-delimited string so that various pages can render the data in different ways. This servlet
takes on request parameter: objectID. Assume that this servlet is mapped to the URL pattern:
/WEB-INF/data.
In the JSP you are creating, you need to split this string into its elements separated by commas
and generate an HTML <ul> list from the data.
Which JSTL code snippet will accomplish this goal?
A. <c:import varReader='dataString' url='/WEB-INF/data'>
<c:param name='objectID' value='${currentOID}' />
</c:import>
<ul>
<c:forTokens items'${dataString.split(",")}' var='item'>
<li>${item}</li>
</c:forTokens>
</ul>
B. <c:import varReader='dataString' url='/WEB-INF/data'>
<c:param name='objectID' value='${currentOID}' />
</c:import>
<ul>
<c:forTokens items'${dataString}' delims=',' var='item'>
<li>${item}</li>
</c:forTokens>
</ul>
C. <c:import var='dataString' url='/WEB-INF/data'>
<c:param name='objectID' value='${currentOID}' />
</c:import>
<ul>
<c:forTokens items'${dataString.split(",")}' var='item'>
<li>${item}</li>
</c:forTokens>
</ul>
D. <c:import var='dataString' url='/WEB-INF/data'>
<c:param name='objectID' value='${currentOID}' />
</c:import>
<ul>
<c:forTokens items'${dataString}' delims=',' var='item'>
<li>${item}</li>
</c:forTokens>
</ul>
Answer: D
No comments:
Post a Comment