Java EE 5 Web Component Developer Certified Professional Exam #2

Java EE 5 Web Component Developer Certified Professional Exam #2

Q: 1
The sl:shoppingList and sl:item tags output a shopping list to the response and are used as follows:

11. <sl:shoppingList>
12. <sl:item name="Bread" />
13. <sl:item name="Milk" />
14. <sl:item name="Eggs" />
15. </sl:shoppingList>

The tag handler for sl:shoppingList is ShoppingListTag and the tag handler for sl:item is ItemSimpleTag. ShoppingListTag extends BodyTagSupport and ItemSimpleTag extends SimpleTagSupport. Which is true?

A. ItemSimpleTag can find the enclosing instance of ShoppingListTag by calling getParent() and casting the result to ShoppingListTag.

B. ShoppingListTag can find the child instances of ItemSimpleTag by calling super.getChildren() and casting each to an ItemSimpleTag.

C. It is impossible for ItemSimpleTag and ShoppingListTag to find each other in a tag hierarchy because one is a Simple tag and the other is a Classic tag.

D. ShoppingListTag can find the child instances of ItemSimpleTag by calling getChildren() on the PageContext and casting each to an ItemSimpleTag.

E. ItemSimpleTag can find the enclosing instance of ShoppingListTag by calling findAncestorWithClass() on the PageContext and casting the result to ShoppingListTag.

Q: 2
Servlet A receives a request that it forwards to servlet B within another web application in the same web container. Servlet A needs to share data with servlet B and that data must not be visible to other servlets in A's web application. In which object can the data that A shares with B be stored?

A. HttpSession

B. ServletConfig

C. ServletContext

D. HttpServletRequest

E. HttpServletResponse

Q: 3
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 the Java SE platform'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 constructs the preferences factory and stores it in the application scope for later use.Furthermore, this factory requires that the URL to a database must be declared in the deployment descriptor like this:

42. <context-param>
43. <param-name>prefsDbURL</param-name>
44. <param-value>
45. jdbc:pointbase:server://dbhost:4747/prefsDB
46. </param-value>
47. </context-param>

Which partial listener class will accomplish this goal?

A. public class PrefsFactoryInitializer implements ContextListener {
public void contextInitialized(ServletContextEvent e) { ServletContext ctx = e.getContext();
String prefsURL = ctx.getParameter("prefsDbURL"); PreferencesFactory myFactory =
makeFactory(prefsURL); ctx.putAttribute("myPrefsFactory", myFactory);
}
// more code here
}

B. public class PrefsFactoryInitializer implements ServletContextListener {
public void contextCreated(ServletContext ctx) {
String prefsURL = ctx.getInitParameter("prefsDbURL"); PreferencesFactory myFactory =
makeFactory(prefsURL); ctx.setAttribute("myPrefsFactory", myFactory);
}
// more code here
}

C. public class PrefsFactoryInitializer implements ServletContextListener {
public void contextInitialized(ServletContextEvent e) { ServletContext ctx =
e.getServletContext();
String prefsURL = ctx.getInitParameter("prefsDbURL"); PreferencesFactory myFactory =
makeFactory(prefsURL); ctx.setAttribute("myPrefsFactory", myFactory);
}
// more code here
}

D. public class PrefsFactoryInitializer implements ContextListener {
public void contextCreated(ServletContext ctx) { String prefsURL =
ctx.getParameter("prefsDbURL");
PreferencesFactory myFactory = makeFactory(prefsURL);
ctx.putAttribute("myPrefsFactory", myFactory);
}
// more code here
}

Q: 4
A developer wants a web application to be notified when the application is about to be shut down. Which two actions are necessary to accomplish this goal? (Choose two.)

A. include a listener directive in a JSP page

B. configure a listener in the TLD file using the <listener> element

C. include a <servlet-destroy> element in the web application deployment descriptor

D. configure a listener in the application deployment descriptor, using the <listener> element

E. include a class implementing ServletContextListener as part of the web application deployment

F. include a class implementing ContextDestroyedListener as part of the web application deployment

G. include a class implementing HttpSessionAttributeListener as part of the web application deployment

Q: 5
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.

Q: 6
Which three are true about the HttpServletRequestWrapper class? (Choose three.)

A. The HttpServletRequestWrapper is an example of the Decorator pattern.

B. The HttpServletRequestWrapper can be used to extend the functionality of a servlet request.

C. A subclass of HttpServletRequestWrapper CANNOT modify the behavior of the getReader method.

D. An HttpServletRequestWrapper may be used only by a class implementing the javax.servlet.Filter interface.

E. AnHttpServletRequestWrapper CANNOT be used on the request passed to the RequestDispatcher.include method.

F. An HttpServletRequestWrapper may modify the header of a request within an object implementing the javax.servlet.Filter interface.

Q: 7
A developer wants to make a name attribute available to all servlets associated with a particular user, across multiple requests from that user, from the same browser instance.
Which two provide this capability from within a tag handler? (Choose two.)

A. pageContext.setAttribute("name", theValue);

B. pageContext.setAttribute("name", getSession());

C. pageContext.getRequest().setAttribute("name", theValue);

D. pageContext.getSession().setAttribute("name", theValue);

E. pageContext.setAttribute("name", theValue, PageContext.PAGE_SCOPE);

F. pageContext.setAttribute("name", theValue, PageContext.SESSION_SCOPE);

Q: 8)
Given the definition of MyServlet:
11. public class MyServlet extends HttpServlet {
12. public void service(HttpServletRequest request,
13. HttpServletResponse response)
14. throws ServletException, IOException {
15. HttpSession session = request.getSession();
16 session.setAttribute("myAttribute","myAttributeValue");
17. session.invalidate();
18. response.getWriter().println("value=" +
19. session.getAttribute("myAttribute"));
20. }
21. }
What is the result when a request is sent to MyServlet?

A. An IllegalStateException is thrown at runtime.

B. An InvalidSessionException is thrown at runtime.

C. The string "value=null" appears in the response stream.

D. The string "value=myAttributeValue" appears in the response stream.

Q: 9
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);

---
 
Answers:

1) A

2) D
 
3) C

4) D, E

5) A, D

6) A, B, F

7) D, F

8) A

9) A, C

Java Tips

Do you have a Java Problem?
Ask It in The Java Forum

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.