Tuesday, January 6, 2015

SCWCD Questions And Answers Part 5

Q: 121 Which three are valid values for the body-content attribute of a tag directive in a tag file? (Choose three.) 

A. EL
B. JSP
C. empty
D. dynamic
E. scriptless
F. tagdependent
  
Answer: C, E, F


Q: 122 The Squeaky Bean company has decided to port their web application to a new J2EE 1.4 container. While reviewing the application, a developer realizes that in multiple places within the current application, nearly duplicate code exists that finds enterprise beans. Which pattern should be used to eliminate this duplicate code?

A. Transfer Object
B. Front Controller
C. Service Locator
D. Intercepting Filter
E. Business Delegate
F. Model-View-Controller
  
Answer: C


Q: 123 A developer is designing a web application that makes many fine-grained remote data requests for each client request. During testing, the developer discovers that the volume of remote requests significantly degrades performance of the application. Which design pattern provides a solution for this problem?

A. Flyweight
B. Transfer Object
C. Service Locator
D. Dispatcher View
E. Business Delegate
F. Model-View-Controller


Answer: B

Q: 124 In an n-tier application, which two invocations are typically remote, not local? (Choose two.)

A. JSP to Transfer Object
B. Service Locator to JNDI
C. Controller to request object
D. Transfer Object to Entity Bean
E. Controller to Business Delegate
F. Business Delegate to Service Locator

Answer: B, D


Q: 125 A developer has created a special servlet that is responsible for generating XML content that is sent to a data warehousing subsystem. This subsystem uses HTTP to request these large data files, which are compressed by the servlet to save internal network bandwidth. The developer has received a request from management to create several more of these data warehousing servlets. The developer is about to copy and paste the compression code into each new servlet. Which design pattern can consolidate this compression code to be used by all of the data warehousing servlets?

A. Facade
B. View Helper
C. Transfer Object
D. Intercepting Filter
E. Composite Facade

Answer: D


Q: 126 A developer is designing the presentation tier for a web application which requires a centralized request handling to complete common processing required by each request. Which design pattern provides a solution to this problem?

A. Remote Proxy
B. Front Controller
C. Service Activator
D. Intercepting Filter
E. Business Delegate
F. Data Access Object

Answer: B


Q: 127 You are designing an n-tier Java EE application. You have already decided that some of your JSPs will need to get data from a Customer entity bean. You are trying to decide whether to use a Customer stub object or a Transfer Object. Which two statements are true? (Choose two.)

A. The stub will increase network traffic.
B. The Transfer Object will decrease data staleness.
C. The stub will increase the logic necessary in the JSPs.
D. In both cases, the JSPs can use EL expressions to get data.
E. Only the Transfer Object will need to use a Business Delegate.
F. Using the stub approach allows you to design the application without using a Service Locator.

Answer: A, D


Q: 128 You have a simple web application that has a single Front Controller servlet that dispatches to JSPs to generate a variety of views. Several of these views require further database processing to retrieve the necessary order object using the orderID request parameter. To do this additional processing, you pass the request first to a servlet that is mapped to the URL pattern /WEB-INF/retreiveOrder.do in the deployment descriptor. This servlet takes two request parameters, the orderID and the jspURL. It handles the database calls to retrieve and build the complex order objects and then it dispatches to the jspURL.

Which code snippet in the Front Controller servlet dispatches the request to the order retrieval servlet?

A. request.setAttribute("orderID", orderID); request.setAttribute("jspURL", jspURL); RequestDispatcher view
= context.getRequestDispatcher("/WEB-INF/retreiveOrder.do"); view.forward(request, response);
B. request.setParameter("orderID", orderID); request.setParameter("jspURL", jspURL); Dispatcher view
= request.getDispatcher("/WEB-INF/retreiveOrder.do"); view.forwardRequest(request, response);
C. String T="/WEB-INF/retreiveOrder.do?orderID=%d&jspURL=%s"; String url = String.format(T, orderID, jspURL);
RequestDispatcher view
= context.getRequestDispatcher(url); view.forward(request, response);
D. String T="/WEB-INF/retreiveOrder.do?orderID=%d&jspURL=%s"; String url = String.format(T, orderID, jspURL);
Dispatcher view = context.getDispatcher(url); view.forwardRequest(request, response);

Answer: C


Q: 129 You have built a web application that you license to small businesses. The webapp uses a context parameter, called licenseExtension, which enables certain advanced features based on your client's license package. When a client pays for a specific service, you provide them with a license extension key that they insert into the <context-param> of the deployment descriptor. Not every client will have this context parameter so you need to create a context listener to set up a default value in the licenseExtension parameter. Which code snippet will accomplish this goal?

A. You cannot do this because context parameters CANNOT be altered programmatically. 
B. String ext = context.getParameter('licenseExtension');
if ( ext == null ) { context.setParameter('licenseExtension', DEFAULT);
}
C. String ext = context.getAttribute('licenseExtension'); if ( ext == null ) { context.setAttribute('licenseExtension', DEFAULT);
}
D. String ext = context.getInitParameter('licenseExtension'); if ( ext == null ) { context.resetInitParameter('licenseExtension', DEFAULT);
}
E. String ext = context.getInitParameter('licenseExtension'); if ( ext == null ) { context.setInitParameter('licenseExtension', DEFAULT);
}

Answer: A


Q: 130 You have a use case in your web application that adds several session-scoped attributes. At the end of the use case, one of these objects, the manager attribute, is removed and then it needs to decide which of the other session-scoped attributes to remove.

How can this goal be accomplished?

A. The object of the manager attribute should implement the HttpSessionBindingListener and it should call the removeAttribute method on the appropriate session attributes.
B. The object of the manager attribute should implement the HttpSessionListener and it should call the removeAttribute method on the appropriate session attributes.
C. The object of the manager attribute should implement the HttpSessionBindingListener and it should call the deleteAttribute method on the appropriate session attributes.
D. The object of the manager attribute should implement the HttpSessionListener and it should call the deleteAttribute method on the appropriate session attributes.

Answer: A


Q: 131 You want to create a filter for your web application and your filter will implement javax.servlet.Filter.

Which two statements are true? (Choose two.)

A. Your filter class must implement an init method and a destroy method.
B. Your filter class must also implement javax.servlet.FilterChain.
C. When your filter chains to the next filter, it should pass the same arguments it received in its doFilter method.
D. The method that your filter invokes on the object it received that implements javax.servlet.FilterChain can invoke either another filter or a servlet.
E. Your filter class must implement a doFilter method that takes, among other things, an HTTPServletRequest object and an HTTPServletResponse object.

Answer: A, D


Q: 132 Your web site has many user-customizable features, for example font and color preferences on web pages. Your IT department has already built a subsystem for user preferences using Java SE's lang.util.prefs package APIs and you have been ordered to reuse this subsystem in your web application. You need to create an event listener that stores the user's Preference object when an HTTP session is created. Also, note that user identification information is stored in an HTTP cookie.

Which partial listener class can accomplish this goal?

A. public class UserPrefLoader implements HttpSessionListener { public void sessionCreated(HttpSessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory) se.getServletContext().getAttribute("myPrefsFactory"); User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user); Preferences userPrefs = myFactory.userRoot(); se.getSession().setAttribute("prefs", userPrefs);
}
// more code here
}
B. public class UserPrefLoader implements SessionListener {
public void sessionCreated(SessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory) se.getContext().getAttribute("myPrefsFactory"); User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user); Preferences userPrefs = myFactory.userRoot(); se.getSession().addAttribute("prefs", userPrefs);
}
// more code here
}
C. public class UserPrefLoader implements HttpSessionListener { public void sessionInitialized(HttpSessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory) se.getServletContext().getAttribute("myPrefsFactory"); User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user); Preferences userPrefs = myFactory.userRoot();
se.getHttpSession().setAttribute("prefs", userPrefs);
}
// more code here
}
D. public class UserPrefLoader implements SessionListener { public void sessionInitialized(SessionEvent se) {
MyPrefsFactory myFactory = (MyPrefsFactory) se.getServletContext().getAttribute("myPrefsFactory"); User user = getUserFromCookie(se);
myFactory.setThreadLocalUser(user); Preferences userPrefs = myFactory.userRoot(); se.getSession().addAttribute("prefs", userPrefs);
}
// more code here
}

Answer: A


Q: 133 Given the web application deployment descriptor elements:

11.    <filter>

12.        <filter-name>ParamAdder</filter-name>
13.        <filter-class>com.example.ParamAdder</filter-class>
14.    </filter>
...
24.    <filter-mapping>
25.        <filter-name>ParamAdder</filter-name>
26.        <servlet-name>MyServlet</servlet-name>
27.        <!-- insert element here -->
28.    </filter-mapping> 

Which element, inserted at line 27, causes the ParamAdder filter to be applied when MyServlet is invoked by another servlet using the RequestDispatcher.include method?

A. <include/> 
B. <dispatcher>INCLUDE</dispatcher>
C. <dispatcher>include</dispatcher>
D. <filter-condition>INCLUDE</filter-condition>
E. <filter-condition>include</filter-condition>

Answer: B


Q: 134 Your web application uses a simple architecture in which servlets handle requests and then forward to a JSP using a request dispatcher. You need to pass information calculated by the servlet to the JSP; furthermore, that JSP uses a custom tag and must also process this information. This information must NOT be accessible to any other servlet, JSP or session in the webapp. How can you accomplish this goal?

A. Store the data in a public instance variable in the servlet. 
B. Add an attribute to the request object before using the request dispatcher.
C. Add an attribute to the context object before using the request dispatcher.
D. This CANNOT be done as the tag handler has no means to extract this data.

Answer: B


Q: 135 A JSP page needs to set the property of a given JavaBean to a value that is calculated with the JSP page. Which three jsp:setProperty attributes must be used to perform this initialization? (Choose three.)

A. id 
B. val
C. name
D. param
E. value
F. property
G. attribute

Answer: C, E, F


Q: 136 Your web application views all have the same header, which includes the <title> tag in the <head> element of the rendered HTML. You have decided to remove this redundant HTML code from your JSPs and put it into a single JSP called /WEB-INF/jsp/header.jsp. However, the title of each page is unique, so you have decided to use a variable called pageTitle to parameterize this in the header JSP, like this:

10. <title>${param.pageTitle}<title>

Which JSP code snippet should you use in your main view JSPs to insert the header and pass the pageTitle variable?

A. <jsp:insert page='/WEB-INF/jsp/header.jsp'> ${pageTitle='Welcome Page'}
</jsp:insert>
B. <jsp:include page='/WEB-INF/jsp/header.jsp'> ${pageTitle='Welcome Page'}
</jsp:include>
C. <jsp:include file='/WEB-INF/jsp/header.jsp'> ${pageTitle='Welcome Page'}
</jsp:include>
D. <jsp:insert page='/WEB-INF/jsp/header.jsp'> <jsp:param name='pageTitle' value='Welcome Page' /> </jsp:insert>
E. <jsp:include page='/WEB-INF/jsp/header.jsp'> <jsp:param name='pageTitle' value='Welcome Page' /> </jsp:include>

Answer: E


Q: 137 A JSP page needs to instantiate a JavaBean to be used by only that page. Which two jsp:useBean attributes must be used to access this attribute in the JSP page? (Choose two.)

A. id
B. type
C. name
D. class
E. scope
F. create

Answer: A, D


Q: 138 Click the Exhibit button.

Given the HTML form:

1.  <html>

2.      <body>
3.          <form action="submit.jsp">
4.              Name: <input type="text" name="i1"><br>
5.              Price: <input type="text" name="i2"><br>
6.              <input type="submit">
7.          </form>
8.      </body>
9.  </html>

Assume the product attribute does NOT yet exist in any scope.

Which code snippet, in submit.jsp, instantiates an instance of com.example.Product that contains the results of the form submission?



A. <jsp:useBean id="com.example.Product" /> <jsp:setProperty name="product" property="*" />
B. <jsp:useBean id="product" class="com.example.Product" /> ${product.name = param.i1}
${product.price = param.i2}
C. <jsp:useBean id="product" class="com.example.Product"> <jsp:setProperty name="product" property="name" param="i1" />
<jsp:setProperty name="product" property="price" param="i2" /> </jsp:useBean>
D. <jsp:useBean id="product" type="com.example.Product"> <jsp:setProperty name="product" property="name" value="<%= request.getParameter( "i1" ) %>" /> <jsp:setProperty name="product" property="price" value="<%= request.getParameter( "i2" ) %>" /> </jsp:useBean>

Answer: C


Q: 139 Click the Task button.

Place the events in the order they occur.


Answer: Check ExamWorx eEngine, Download from Member Center


Q: 140 For an HttpServletResponse response, which two create a custom header? (Choose two.)

A. r esponse.setHeader("X-MyHeader", "34");
B. response.addHeader("X-MyHeader", "34");
C. response.setHeader(new HttpHeader("X-MyHeader", "34"));
D. response.addHeader(new HttpHeader("X-MyHeader", "34"));
E. response.addHeader(new ServletHeader("X-MyHeader", "34"));
F. response.setHeader(new ServletHeader("X-MyHeader", "34"));

Answer: A, B


Q: 141 You need to create a servlet filter that stores all request headers to a database for all requests to the web application's home page "/index.jsp". Which HttpServletRequest method allows you to retrieve all of the request headers?

A. String[] getHeaderNames()
B. String[] getRequestHeaders()
C. java.util.Iterator getHeaderNames()
D. java.util.Iterator getRequestHeaders()
E. java.util.Enumeration getHeaderNames()
F. java.util.Enumeration getRequestHeaders()

Answer: E


Q: 142 Given an HttpServletRequest request and HttpServletResponse response, which sets a cookie "username" with the value "joe" in a servlet?

A. request.addCookie("username", "joe")
B. request.setCookie("username", "joe")
C. response.addCookie("username", "joe")
D. request.addHeader(new Cookie("username", "joe"))
E. request.addCookie(new Cookie("username", "joe"))
F. response.addCookie(new Cookie("username", "joe"))
G. response.addHeader(new Cookie("username", "joe"))

Answer: F


Q: 143 Click the Task button.

Given a request from mybox.example.com, with an IP address of 10.0.1.11 on port 33086, place the appropriate ServletRequest methods onto their corresponding return values.


Answer: Check ExamWorx eEngine, Download from Member Center


Q: 144 Your web application requires the ability to load and remove web files dynamically to the web container's file system. Which two HTTP methods are used to perform these actions? (Choose two.)

A. PUT
B. POST
C. SEND
D. DELETE
E. REMOVE
F. DESTROY

Answer: A, D


Q: 145 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' %>

Answer: D


Q: 146 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>

Answer: A


Q: 147 You have a new IT manager that has mandated that all JSPs must be refactored to include no scritplet code. The IT manager has asked you to enforce this. Which deployment descriptor element will satisfy this constraint?

A. <jsp-property-group> <url-pattern>*.jsp</url-pattern>
<permit-scripting>false</permit-scripting> </jsp-property-group>
B. <jsp-config> <url-pattern>*.jsp</url-pattern> <permit-scripting>false</permit-scripting> </jsp-config>
C. <jsp-config> <url-pattern>*.jsp</url-pattern> <scripting-invalid>true</scripting-invalid> </jsp-config>
D. <jsp-property-group> <url-pattern>*.jsp</url-pattern> <scripting-invalid>true</scripting-invalid> </jsp-property-group>

Answer: D


Q: 148 You need to create a JSP that generates some JavaScript code to populate an array of strings used on the client-side. Which JSP code snippet will create this array?

A. MY_ARRAY = new Array();
<% for ( int i = 0; i < serverArray.length; i++ ) { MY_ARRAY[<%= i %>] = '<%= serverArray[i] %>'; } %>
B. MY_ARRAY = new Array();
<% for ( int i = 0; i < serverArray.length; i++ ) { MY_ARRAY[${i}] = '${serverArray[i]}';
} %>
C. MY_ARRAY = new Array();
<% for ( int i = 0; i < serverArray.length; i++ ) { %> MY_ARRAY[<%= i %>] = '<%= serverArray[i] %>'; <% } %>
D. MY_ARRAY = new Array();
<% for ( int i = 0; i < serverArray.length; i++ ) { %> MY_ARRAY[${i}] = '${serverArray[i]}';
<% } %>

Answer: C


Q: 149 You are building a Front Controller using a JSP page and you need to determine if the user's session has NOT been created yet and perform some special processing for this case. Which scriptlet code snippet will perform this test?

A. <% if ( request.getSession(false) == null ) { // special processing } %>
B. <% if ( request.getHttpSession(false) == null ) { // special processing } %>
C. <% if ( requestObject.getSession(false) == null ) { // special processing } %>
D. <% if ( requestObject.getHttpSession(false) == null ) { // special processing } %>

Answer: A


Q: 150 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 three.)

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.

Answer: B, D, E

No comments :

Post a Comment