310-083 Sun Certified Web Component Developer for J2EE 5 Set 2

Given that www.example.com/SCWCDtestApp is a validly deployed Java EE web application and

that all of the JSP files specified in the requests below exist in the locations specified. Which two

requests, issued from a browser, will return an HTTP 404 error? (Choose two.)

A. http://www.example.com/SCWCDtestApp/test.jsp

B. http://www.example.com/SCWCDtestApp/WEB-INF/test.jsp

C. http://www.example.com/SCWCDtestApp/WEB-WAR/test.jsp

D. http://www.example.com/SCWCDtestApp/Customer/test.jsp

E. http://www.example.com/SCWCDtestApp/META-INF/test.jsp

F. http://www.example.com/SCWCDtestApp/Customer/Update/test.jsp


Options are :

  • B,E
  • D,E
  • A,E
  • C,E

Answer : B,E

310-083 Sun Certified Web Component Developer for J2EE 5 Set 3

A developer is designing a web application that must verify for each request:

The originating request is from a trusted network.

The client has a valid session.

The client has been authenticated.

Which design pattern provides a solution in this situation?


Options are :

  • Intercepting Filter
  • Transfer Object
  • Session Facade
  • Model-View-Controller
  • Template Method

Answer : Intercepting Filter

Which EL expression evaluates to the request URI?


Options are :

  • ${requestScope.request.requestURI}
  • ${pageContext.request.requestURI}
  • ${request.requestURI}
  • ${request.getURI}
  • ${request.URI}
  • ${requestURI}
  • ${requestScope.requestURI}

Answer : ${pageContext.request.requestURI}

Given this fragment from a Java EE deployment descriptor:

124. <welcome-file>beta.html</welcome-file>

125. <welcome-file>alpha.html</welcome-file>

And this request from a browser:

http://www.sun.com/SCWCDtestApp/register

Which statement is correct, when the container receives this request?


Options are :

  • The container first looks in the register directory for beta.html.
  • The container first looks in the register directory for alpha.html.
  • This deployment descriptor is NOT valid.
  • The container first looks for a servlet mapping in the deployment descriptor.

Answer : The container first looks for a servlet mapping in the deployment descriptor.

310-083 Sun Certified Web Component Developer for J2EE 5 Set 4

You have built a collection of custom tags for your web application. The TLD file is located in the

file: /WEB-INF/myTags.xml. You refer to these tags in your JSPs using the symbolic name:

myTags. Which deployment descriptor element must you use to make this link between the

symbolic name and the TLD file name?


Options are :

  • myTags /WEB-INF/myTags.xml
  • myTags /WEB-INF/myTags.xml
  • myTags /WEB-INF/myTags.xml
  • myTags /WEB-INF/myTags.xml

Answer : myTags /WEB-INF/myTags.xml

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?


Options are :

Answer :

What is true about Java EE authentication mechanisms?


Options are :

  • If you want your web application to support the widest possible array of browsers, and you want to perform authentication, the best choice of Java EE authentication mechanisms is DIGEST.
  • To use Java EE FORM authentication, you must declare two HTML files in your deployment descriptor, and you must use a predefined action in the HTML file that handles your user's login
  • If your deployment descriptor correctly declares an authentication type of BASIC, the container automatically requests a user name and password whenever a user starts a new session.
  • If your deployment descriptor correctly declares an authentication type of CLIENT_CERT, your users must have a certificate from an official source before they can use your application.

Answer : To use Java EE FORM authentication, you must declare two HTML files in your deployment descriptor, and you must use a predefined action in the HTML file that handles your user's login

310-083 Sun Certified Web Component Developer for J2EE 5 Set 5

Given this fragment in a servlet:

23. if(req.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?


Options are :

  • If line 24 executes, the user's role will be Admin.
  • If line 24 executes the user's role will NOT be predictable.
  • Line 24 can never be reached.
  • The deployment descriptor is NOT valid.
  • If line 24 executes, the user's role will be Administrator.

Answer : If line 24 executes, the user's role will be Administrator.

Which JSTL code snippet can be used to perform URL rewriting?


Options are :

Answer :

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?


Options are :

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

310-083 Sun Certified Web Component Developer for J2EE 5 Set 6

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


Options are :

  • D,E
  • C,E
  • B,E
  • A,E

Answer : D,E

Squeaky Beans Inc. hired an outside consultant to develop their web application. To finish the job

quickly, the consultant created several dozen JSP pages that directly communicate with the

database. The Squeaky business team has since purchased a set of business objects to model

their system, and the Squeaky developer charged with maintaining the web application must now

refactor all the JSPs to work with the new system. Which pattern can the developer use to solve

this problem?


Options are :

  • Service Locator
  • Intercepting Filter
  • Transfer Object
  • Intercepting Filter

Answer : Intercepting Filter

Which three are valid URL mappings to a servlet in a web deployment descriptor? (Choose three.)

A. */*

B. *.do

C. MyServlet

D. /MyServlet

E. /MyServlet/*

F. MyServlet/*.jsp


Options are :

  • B,D,F
  • A,B,C
  • B,D,E
  • A,C,D

Answer : B,D,E

310-083 Sun Certified Web Component Developer for J2EE 5 Set 7

Given:

3. class MyServlet extends HttpServlet {

4. public void doPut(HttpServletRequest req, HttpServletResponse resp) throws

ServletException, IOException {

5. // servlet code here ...

26. }

27. }

If the DD contains a single security constraint associated with MyServlet and its only <httpmethod>

tags and <auth-constraint> tags are:

<http-method>GET</http-method>

<http-method>PUT</http-method>

<auth-constraint>Admin</auth-constraint>

Which four requests would be allowed by the container? (Choose four.)

A. A user whose role is Admin can perform a PUT.

B. A user whose role is Admin can perform a GET.

C. A user whose role is Admin can perform a POST.

D. A user whose role is Member can perform a PUT.

E. A user whose role is Member can perform a POST.

F. A user whose role is Member can perform a GET.


Options are :

  • A,B,C,D
  • A,B,C,F
  • B,C,D,E
  • A,B,C,E

Answer : A,B,C,E

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?


Options are :

  • Create an SessionAttributeListener class and implement the attributeDeleted method and log the attribute name using the getAttributeName method on the event object
  • Create an HttpSessionAttributeListener class and implement the attributeRemoved method and log the attribute name using the getName method on the event object.
  • Create an SessionAttributeListener class and implement the attributeRemoved method and log the attribute name using the getAttributeName method on the event object
  • Create an HttpSessionAttributeListener class and implement the attributeDeleted method and log the attribute name using the getName method on the event object

Answer : Create an HttpSessionAttributeListener class and implement the attributeRemoved method and log the attribute name using the getName method on the event object.

Your management has required that all JSPs be created to generate XHTML-compliant content

and to facilitate that decision, you are required to create all JSPs using the JSP Document format.

In the reviewOrder.jspx page, you need to use several core JSTL tags to process the collection of

order items in the customer's shopping cart. Which JSP code snippets must you use in the

reviewOrder.jspx page?


Options are :

Answer :

310-083 Sun Certified Web Component Developer for J2EE 5 Set 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?


Options are :

  • <%@ page useSingleThreadModel='true' %>
  • <%! implements SingleThreadModel %>
  • <%@ page useSingleThreadModel='true' %>
  • <%@ implements SingleThreadModel %>
  • <%@ page isThreadSafe='false' %>

Answer : <%@ page isThreadSafe='false' %>

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?


Options are :

  • Model-View-Controller
  • Intercepting Filter
  • Front Controller
  • Transfer Object
  • Service Locator
  • Business Delegate

Answer : Service Locator

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?


Options are :

  • session.getMaxInactiveInterval();
  • session.getLastAccessed() - session.getCreationTime();
  • session.getLastAccessedTime().getTime() - session.getCreationTime().getTime();
  • session.getMaxInactiveInterval() - session.getCreationTime();
  • session.getLastAccessed().getTime() - session.getCreationTime().getTime();
  • session.getLastAccessedTime() - session.getCreationTime();

Answer : session.getLastAccessedTime() - session.getCreationTime();

310-019 Sun Certified Associate.Java Platform Se Exam Set 1

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);


Options are :

  • A,C
  • A,B
  • A,D
  • A,E

Answer : A,C

You want to create a valid directory structure for your Java EE web application, and your

application uses tag files and a JAR file. Which three must be located directly in your WEB-INF

directory (NOT in a subdirectory of WEB-INF)? (Choose three.)

A. The JAR file

B. A directory called lib

C. A directory called tags

D. A directory called TLDs

E. A directory called classes

F. A directory called META-INF


Options are :

  • A,B,C
  • B,C,E
  • A,C,D
  • B,C,D

Answer : B,C,E

310-019 Sun Certified Associate.Java Platform Se Exam Set 2

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?


Options are :

  • View Helper
  • Composite Facade
  • Intercepting Filter
  • Transfer Object
  • Facade

Answer : Intercepting Filter

Your web page includes a Java SE v1.5 applet with the following declaration:

11. <object classid='clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA'

12. width='200' height='200'>

13. <param name='code' value='Applet.class' />

14. </object>

Which HTTP method is used to retrieve the applet code?


Options are :

  • PUT
  • RETRIEVE
  • GET
  • POST

Answer : GET

Which element of the web application deployment descriptor defines the servlet class associated

with a servlet instance?


Options are :

Answer :

310-019 Sun Certified Associate.Java Platform Se Exam Set 3

The Squeaky Beans Inc. shopping application was initially developed for a non-distributed

environment. The company recently purchased the Acme Application Server, which supports

distributed HttpSession objects. When deploying the application to the server, the deployer marks

it as distributable in the web application deployment descriptor to take advantage of this feature.

Given this scenario, which two must be true? (Choose two.)

A. The J2EE web container must support migration of objects that implement Serializable.

B. The J2EE web container must use the native JVM Serialization mechanism for distributing

HttpSession objects.

C. As per the specification, the J2EE web container ensures that distributed HttpSession objects

will be stored in a database.

D. Storing references to Enterprise JavaBeans components in the HttpSession object might NOT

be supported by J2EE web containers.


Options are :

  • A,C
  • A,D
  • A,B
  • B,D

Answer : A,D

Which three are described in the standard web application deployment descriptor? (Choose

three.)

A. session configuration

B. MIME type mappings

C. context root for the application

D. servlet instance pool configuration

E. web container default port bindings

F. ServletContext initialization parameters


Options are :

  • A,B,D
  • A,B,F
  • A,B,C
  • A,B,E

Answer : A,B,F

A JSP page contains a taglib directive whose uri attribute has the value dbtags. Which XML

element within the web application deployment descriptor defines the associated TLD?


Options are :

  • dbtags /WEB-INF/tlds/dbtags.tld
  • dbtags /WEB-INF/tlds/dbtags.tld
  • dbtags /WEB-INF/tlds/dbtags.tld
  • dbtags /WEB-INF/tlds/dbtags.tld

Answer : dbtags /WEB-INF/tlds/dbtags.tld

310-019 Sun Certified Associate.Java Platform Se Exam Set 4

In your web application, you need to execute a block of code whenever the session object is first

created. Which design will accomplish this goal?


Options are :

  • Create an HttpSessionListener class and implement the sessionCreated method with that block of code.
  • Create a Filter class, call the getSession(true) method, and if the result was NOT null, then execute that block of code.
  • Create a Filter class, call the getSession(false) method, and if the result was null, then execute that block of code
  • Create an HttpSessionActivationListener class and implement the sessionCreated method with that block of code
  • Create an HttpSessionListener class and implement the sessionInitialized method with that block of code

Answer : Create an HttpSessionListener class and implement the sessionCreated method with that block of code.

Given a header in an HTTP request:

X-Retries: 4

Which two retrieve the value of the header from a given HttpServletRequest request? (Choose

two.)

A. request.getHeader("X-Retries")

B. request.getIntHeader("X-Retries")

C. request.getRequestHeader("X-Retries")

D. request.getHeaders("X-Retries").get(0)

E. request.getRequestHeaders("X-Retries").get(0)


Options are :

  • A,E
  • A,B
  • A,C
  • A,D

Answer : A,B

You need to retrieve the username cookie from an HTTP request. If this cookie does NOT exist,

then the c variable will be null. Which code snippet must be used to retrieve this cookie object?


Options are :

  • 10. Cookie c = null; 11. for ( Enumeration e = request.getCookies(); 12. e.hasMoreElements(); ) { 13. Cookie o = (Cookie) e.nextElement(); 14. if ( o.getName().equals("username") ) { 15. c = o; 16. break; 17. } 18. }
  • 10. Cookie c = null; 11. Cookie[] cookies = request.getCookies(); 12. for ( int i = 0; i < cookies.length; i++ ) { 13. if ( cookies[i].getName().equals("username") ) { 14. c = cookies[i]; 15. break; 16. } 17. }
  • 10. Cookie c = null; 11. for ( Iterator i = request.getCookies(); 12. i.hasNext(); ) { 13. Cookie o = (Cookie) i.next(); 14. if ( o.getName().equals("username") ) { 15. c = o; 16. break; 17. } 18. }
  • 10. Cookie c = request.getCookie("username");

Answer : 10. Cookie c = null; 11. Cookie[] cookies = request.getCookies(); 12. for ( int i = 0; i < cookies.length; i++ ) { 13. if ( cookies[i].getName().equals("username") ) { 14. c = cookies[i]; 15. break; 16. } 17. }

310-019 Sun Certified Associate.Java Platform Se Exam Set 5

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions