Java EE 6 Web Component Developer Certified Expert Exam v6.2 (1z0-899)

Page:    1 / 8   
Total 113 questions

A servlet wishes to indicate that it is unable to initialize at the present time, but that the initialization might succeed at some future time. Which is true?

  • A. This cannot be expressed. A servlet either initializes correctly or fails.
  • B. This expression is not necessary. If a servlet fails to initialize, the container will try again later each time a request is received that attempts to invoke that servlet.
  • C. The servlet should delay until it is ready to complete initialization successfully.
  • D. The servlet should throw an UnavailableException
  • E. The servlet should throw a servletException

Answer : E

A web application for business expense reporting allows uploading expense receipts.
Multiple receipts can be uploaded single step using one HTTP request. The servlet that processes the request has been marked with the @MultipartConfig annotation.
Which method should the servlet use to access the uploaded files?

  • A. HttpServletRequest.getParts()
  • B. HttpServletRequest.getData()
  • C. servletRequest.getParts()
  • D. servletRequest.getAllParts()

Answer : A

Explanation: The request.getParts() method returns collections of all Part objects. If you have more than one input of type file, multiple Part objects are returned. Since Part objects are named, the getPart(String name) method can be used to access a particular Part.
Alternatively, the getParts() method, which returns an Iterable<Part>, can be used to get an
Iterator over all the Part objects.

When using the @WebListener annotation, the class on which the annotation is applied to must also implement at least one o the following interfaces (Choose two):

  • A. RequestListener
  • B. AttributeListener
  • C. ServletContextListener
  • D. HttpSessionListener
  • E. SessionAttributeListener
  • F. AsyncListener

Answer : C,D

Explanation: @WebListener -
The main task of the listener is to listen the particular events and process your own task on that event. For example, if you want to initialize a database connection before your application starts, ServletContextListener will be implemented to do that. Another good example is -when you want to do some task on the creation and destruction of a session.
For this purpose you need to implement HttpSessionListener.

View the Exhibit.

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>
31. <filter-mapping>
32. <filter-name>ParamAdder</filter-name>
33. <servlet-name>Destination</servlet-name>
34. </filter-mapping>
55. <servlet-mapping>
56. <servlet-name>Destination</servlet-name>
57. <url-pattern>/dest/Destination</url-pattern>
58. </servlet-mapping>
What is the result of a client request of the Source servlet with no query string?

  • A. The output “filterAdded = null” is written to the response stream.
  • B. The output “filterAdded = addedByFilter” is written to the response stream.
  • C. An exception is thrown at runtime within the service method of the Source servlet.
  • D. An exception is thrown at runtime within the service method of the Destination servlet.

Answer : A

Assume a JavaBean com.example.GradedTestBean exists and has two attributes. The attribute name of type java.lang.string and the attribute score is of type jave.lang.Integer.
An array of com.example.GradedTestBean objects is exposed to the page in a request- scoped attribute called results. Additionally, an empty java.util.HashMap called resultMap is placed in the page scope.
A JSP page needs to add the first entry in results to resultMap, storing the name attribute of the bean as the key and the score attribute of the bean as the value.
Which code snippet of JSTL code satisfies this requirement?

  • A. ${resultMap[results[0].name] = results[0].score}
  • B. <c:set var=“${resultMap}” key=“{results[0].name}” value=“${results[0].score}” />
  • C. <c:set var=resultMap property=${results[0].name}> ${results[0].value} </c:set>
  • D. <c:set var=“resultMap” property=“${results[0].name}”> value=“${results[0].score}” />
  • E. <c:set target=“${resultMap}” property=“${results[0].name}”> value=“${results[0].score}” />

Answer : E

A servlet class is injected with a JDBC data source. After injection has occurred, the servlet needs to create a cache out of some of the data in the database, so as to improve responsiveness.
Which two methods can host the cache creation code? (Choose two)

  • A. Servlet.init()
  • B. Servlet.destroy()
  • C. A method annotated with @Init
  • D. A method annotated with @PostConstruct
  • E. A method annotated with @PreDestroy
  • F. A method annotated with @Resource

Answer : A,D

Explanation: A: Because the Servlet init() method is invoked when the servlet instance is loaded, it is the perfect location to carry out expensive operations that need only be performed during initialization. By definition, the init() method is thread-safe. The results of operations in the HttpServlet.init() method can be cached safely in servlet instance variables, which become read-only in the servlet service method.
D: Example:
private void init() {
cached = (Cached) ctx.lookup(EJB_PATH + Cached.class.getSimpleName());

During initialization, a servlet finds that the database connection it requires is unavailable.
As the system designer, you know that the database start up completes several minutes after the web- container initializes the servlet. How should this be handled?

  • A. Retry the connection until it is successful, then allow the init() method to complete.
  • B. Throw a ServletException
  • C. Throw the IOException
  • D. Throw an UnavailableException

Answer : D


Given this fragment in a servlet:
23. if(reg.isUserInRole(Admin)) {
24. // do stuff
25. }
And the following fragment from the related Java EE deployment descriptor:
812. <security-role-ref>
813. <role-name>Admin</role-name>
814. <role-link>Administrator</role-link>
815. </security-role-ref>
900. <security-role>
901. <role-name>Admin</role-name>
902. <role-name>Administrator</role-name>
903. </security-role>
What is the result?

  • A. Line 24 can never be reached.
  • B. The deployment descriptor is NOT valid.
  • C. If line 24 executes, the user’s role will be Admin.
  • D. If line 24 executes, the user’s role will be Administrator.
  • E. If line 24 executes, the user’s role will NOT be predictable.

Answer : D

Given a war file with the following structure
| - WEB-INF/classes/Myservlet.class
| - WEB-INF/lib/wf.jaf
Where wf.jar contains a valid web-fragment.xml and the following two classes:
MyFilter1.class and MyFiler2.class.
The web-fragment.xml is as follows:

The following are some code snippets:

When one access / of the above web application, which filters will be executed?

  • A. No filters will be executed.
  • B. MyFilter1
  • C. MyFilter2
  • D. MyFilter1 and MyFilter2

Answer : C

* <filter-mapping>
This tag specifies a filter name, and either a URL mapping or servlet name, for a filter that has been defined with the <filter> tag.
Multiple <filter-mapping> tags can be specified for a single <filter>, providing different URL patterns. See the <url-pattern> tag for examples.
The <filter-mapping> has two required elements:
<filter-name> - the filter name, as specified in the <filter-name> element of the <filter> tag
Either a <url-pattern> or a <servlet-name>.
If a servlet name is specified, the filter will be called whenever the specific servlet is called.

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.

Answer : C

The jquery_1_3_2.jar file contains the JQuery Ajax framework in its META-INF/ resources directory. Where should the jar file be placed inside the web application to ensure the resources it contains are accessible by clients?

  • A. WEB-INF/classes
  • B. WEB-INF/jar
  • C. WEB-INF/lib
  • D. WEB INF/resources

Answer : C

Reference: ml (topic: web modules, third paragraph)

Servlet A forwarded a request to servlet B using the forward method of RequestDispatcher.
What attribute in Bs request object contains the URI of the original request received by servlet A?

  • B. javax.servlet.forward.request_uri
  • C. javax.servlet.forward.REQUEST_URI
  • D. javax.servlet.request_dispatcher.request_uri
  • E. javax.servlet.request_dispatcher.REQUEST_URI

Answer : B

A web application allows the HTML title banner to be set using a context initialization parameter called titlestr.
Which two properly set the title in the scenario? (Choose two)

  • A. <title> $ {titlestr} </title>
  • B. <title> $ {initparam.titlestr}</title>
  • C. <title> $ {param [0]. titlestr} </title>
  • D. <title> $ {paramValues.titleStr} </title>
  • E. <title> $ {initParam [‘titleStr’] } </title>
  • F. <title> $ {servletParams.titleStr} </title>
  • G. <title> $ {request.get (“titleStr”) } </title>

Answer : B,E

Given the fragment from Java EE deployment descriptor:
341. <error-page>
342. <exception-type>java.lang.Throwable</exception-type>
343. <location>/mainError.jsp</location>
344. </error-page>
345. <error-page>
346. <exception-type>java.lang.ClassCastException</exception-type>
347. <location>/castError.jsp</location>
348. </error-page>
If the web application associated with the fragment above throws a ClassCastException.
Which statement is true?

  • A. The deployment descriptor is invalid.
  • B. The container invokes mainError.jsp
  • C. The container invokes castError.jsp
  • D. Neither mainError.jsp nor castError.jsp is invoked.

Answer : C

Given that a web application consists of two HttpServlet classes, ServletA and ServletB, and the ServerletA.service method:
20. String key =;
21. session.setAttribute(key, Hello);
22. object value = session.getAttribute(key);
Assume session is an HttpSession, and is not referenced anywhere else in ServletA.
Which two changes, taken together, ensure that value is equal to Hello on line 23?
(Choose two)

  • A. ensure that the ServletB.service method is synchronized
  • B. ensure that the ServletA.service method is synchronized
  • C. ensure that ServletB synchronizes on the session object when setting session attributes
  • D. enclose lines 21-22 in synchronized block: synchronized(this) ( session.setAttribute(key, Hello); value = session.getAttribute(key); )
  • E. enclose lines 21-22 in synchronized block: synchronized(session) ( session.setAttribute(key, Hello); value = session.getAttribute(key); )

Answer : C,E

Page:    1 / 8   
Total 113 questions