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

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?


Options are :

    • ${item}
    • ${item}
    • ${item}
    • ${item}

Answer :

  • ${item}
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 Administrator.
  • 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.

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

Given:

11. <%

12. request.setAttribute("vals", new String[]{"1","2","3","4"});

13. request.setAttribute("index", "2");

14. %>

15. <%-- insert code here --%>

Which three EL expressions, inserted at line 15, are valid and evaluate to "3"? (Choose three.)

A. ${vals.2}

B. ${vals["2"]}

C. ${vals.index}

D. ${vals[index]}

E. ${vals}[index]

F. ${vals.(vals.index)}

G. ${vals[vals[index-1]]}


Options are :

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

Answer : B,D,G

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

Given:

10. public void service(ServletRequest request,

11. ServletResponse response) {

12. ServletInputStream sis =

13. // insert code here

14. }

Which retrieves the binary input stream on line 13?


Options are :

  • request.getResourceAsStream(ServletRequest.REQUEST);
  • request.getWriter();
  • request.getReader();
  • request.getInputStream();
  • request.getResourceAsStream();

Answer : request.getInputStream();

Assume the custom tag my:errorProne always throws a java.lang.RuntimeException with the

message "File not found."

An error page has been configured for this JSP page.

Which option prevents the exception thrown by my:errorProne from invoking the error page

mechanism, and outputs the message "File not found" in the response?


Options are :

  • ${ex.message}
  • ${ex.message}
  • ${ex.message}
  • ${ex.message}
  • ${ex.message}

Answer : ${ex.message}

A session-scoped attribute is stored by a servlet, and then that servlet forwards to a JSP page.

Which three jsp:useBean attributes must be used to access this attribute in the JSP page?

(Choose three.)

A. id

B. name

C. bean

D. type

E. scope

F. beanName


Options are :

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

Answer : A,D,E

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

Within the web application deployment descriptor, which defines a valid JNDI environment entry?


Options are :

  • param/MyExampleString java.lang.String This is an Example
  • java.lang.Boolean true
  • param/MyExampleString This is an Example
  • param/MyExampleString int 10

Answer : param/MyExampleString java.lang.String This is an Example

Which two are true about the JSTL core iteration custom tags? (Choose two.)

A. It may iterate over arrays, collections, maps, and strings.

B. The body of the tag may contain EL code, but not scripting code.

C. When looping over collections, a loop status object may be used in the tag body.

D. It may iterate over a map, but only the key of the mapping may be used in the tag body.

E. When looping over integers (for example begin='1' end='10'), a loop status object may not be

used in the tag body.


Options are :

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

Answer : A,C

Which mechanism requires the client to provide its public key certificate?


Options are :

  • HTTP Digest Authentication
  • HTTPS Client Authentication
  • Form Based Authentication
  • HTTP Basic Authentication

Answer : HTTPS Client Authentication

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

Given an HttpSession session, a ServletRequest request, and a ServletContext context, which

retrieves a URL to /WEB-INF/myconfig.xml within a web application?


Options are :

  • session.getResource("/WEB-INF/myconfig.xml")
  • getClass().getResource("/WEB-INF/myconfig.xml")
  • context.getResource("/WEB-INF/myconfig.xml")
  • request.getResource("/WEB-INF/myconfig.xml")

Answer : context.getResource("/WEB-INF/myconfig.xml")

Given:

5. public class MyTagHandler extends TagSupport {

6. public int doStartTag() throws JspException {

7. try {

8. // insert code here

9. } catch(Exception ex) { /* handle exception */ }

10. return super.doStartTag();

11. }

...

42. }

Which code snippet, inserted at line 8, causes the value foo to be output?


Options are :

  • JspWriter w = pageContext.getWriter(); w.print("foo");
  • JspWriter w = pageContext.getOut(); w.print("foo");
  • JspWriter w = pageContext.getWriter(); w.print("foo");
  • JspWriter w = new JspWriter(pageContext.getResponse()); w.print("foo");

Answer : JspWriter w = pageContext.getOut(); w.print("foo");

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

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?


Options are :

  • String[] getHeaderNames()
  • java.util.Enumeration getRequestHeaders()
  • java.util.Iterator getHeaderNames()
  • java.util.Iterator getRequestHeaders()
  • java.util.Enumeration getHeaderNames()
  • String[] getRequestHeaders()

Answer : java.util.Enumeration getHeaderNames()

Given:

11. <%

12. request.setAttribute("vals", new String[]{"1","2","3","4"});

13. request.setAttribute("index", "2");

14. %>

15. <%-- insert code here --%>

Which three EL expressions, inserted at line 15, are valid and evaluate to "3"? (Choose three.)

A. ${vals.2}

B. ${vals["2"]}

C. ${vals.index}

D. ${vals[index]}

E. ${vals}[index]

F. ${vals.(vals.index)}

G. ${vals[vals[index-1]]}


Options are :

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

Answer : B,D,G

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


Options are :

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

Answer : C,E,F

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

Which statement is true if the doStartTag method returns EVAL_BODY_BUFFERED ?


Options are :

  • The doAfterBody method is NOT called
  • It is never legal to return EVAL_BODY_BUFFERED from doStartTag
  • The tag handler must implement BodyTag.
  • The setBodyContent method is called once

Answer : The setBodyContent method is called once

Given an HttpServletRequest request and HttpServletResponse response, which sets a cookie

"username" with the value "joe" in a servlet?


Options are :

  • response.addHeader(new Cookie("username", "joe"))
  • request.setCookie("username", "joe")
  • request.addHeader(new Cookie("username", "joe"))
  • response.addCookie("username", "joe")
  • request.addCookie(new Cookie("username", "joe"))
  • response.addCookie(new Cookie("username", "joe"))
  • request.addCookie("username", "joe")

Answer : response.addCookie(new Cookie("username", "joe"))

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 /WEBINF/

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?


Options are :

  • 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);
  • request.setAttribute("orderID", orderID); request.setAttribute("jspURL", jspURL); RequestDispatcher view = context.getRequestDispatcher("/WEB-INF/retreiveOrder.do"); view.forward(request, response);
  • 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);
  • request.setParameter("orderID", orderID); request.setParameter("jspURL", jspURL); Dispatcher view = request.getDispatcher("/WEB-INF/retreiveOrder.do"); view.forwardRequest(request, response);

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

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

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


Options are :

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

Answer : B,D

Which security mechanism uses the concept of a realm?


Options are :

  • authorization
  • data integrity
  • authentication
  • confidentiality

Answer : authentication

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?


Options are :

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

Answer : MY_ARRAY = new Array(); <% for ( int i = 0; i < serverArray.length; i++ ) { %> MY_ARRAY[<%= i %>] = '<%= serverArray[i] %>'; <% } %>

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

Given a web application in which the cookie userName is expected to contain the name of the

user. Which EL expression evaluates to that user name?


Options are :

  • ${cookie.userName}
  • ${cookies.userName}[1]
  • ${cookies.get('userName')}
  • ${cookie.user.name}
  • ${cookies.userName[0]}
  • ${userName}

Answer : ${cookie.userName}

QUESTION NO: 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?


Options are :

  • ${pageTitle='Welcome Page'}
  • ${pageTitle='Welcome Page'}
  • ${pageTitle='Welcome Page'}

Answer :

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 :

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

Answer : Service Locator

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

Given a JSP page:

11. <n:recurse>

12. <n:recurse>

13. <n:recurse>

14. <n:recurse />

15. </n:recurse>

16. </n:recurse>

17. </n:recurse>

The tag handler for n:recurse extends SimpleTagSupport.

Assuming an n:recurse tag can either contain an empty body or another n:recurse tag, which

strategy allows the tag handler for n:recurse to output the nesting depth of the deepest n:recurse

tag?


Options are :

  • It is impossible to determine the deepest nesting depth because it is impossible for tag handlers that extend SimpleTagSupport to communicate with their parent and child tags.
  • Create a private non-static attribute in the tag handler class called count of type int initialized to 0. Increment count in the doTag method. If the tag has a body, invoke the fragment for that body. Otherwise, output the value of count.
  • Start a counter at 1. Call getChildTags(). If it returns null, output the value of the counter. Otherwise, increment counter and continue from where getChildTags() is called. Skip processing of the body.
  • If the tag has a body, invoke the fragment for that body.Otherwise, start a counter at 1. Call getParent(). If it returns null, output the value of the counter Otherwise, increment the counter and continue from where getParent() is called

Answer : If the tag has a body, invoke the fragment for that body.Otherwise, start a counter at 1. Call getParent(). If it returns null, output the value of the counter Otherwise, increment the counter and continue from where getParent() is called

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?


Options are :

  • Front Controller
  • Intercepting Filter
  • Remote Proxy
  • Service Activator
  • Data Access Object
  • Business Delegate

Answer : Front Controller

Given:

http://com.example/myServlet.jsp?num=one&num=two&num=three

Which two produce the output "one, two and three"? (Choose two.)

A. ${param.num[0],[1] and [2]}

B. ${paramValues[0],[1] and [2]}

C. ${param.num[0]}, ${param.num[1]} and ${param.num[2]}

D. ${paramValues.num[0]}, ${paramValues.num[1]} and ${paramValues.num[2]}

E. ${paramValues["num"][0]}, ${paramValues["num"][1]} and ${paramValues["num"][2]}

F. ${parameterValues.num[0]}, ${parameterValues.num[1]} and ${parameterValues.num[2]}

G. ${parameterValues["num"]["0"]}, ${parameterValues["num"]["1"]} and

${parameterValues["num"]["2"]}


Options are :

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

Answer : D,E

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

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?


Options are :

  • <% if ( request.getSession(false) == null ) { // special processing } %>
  • <% if ( requestObject.getSession(false) == null ) { // special processing } %>
  • <% if ( requestObject.getHttpSession(false) == null ) { // special processing } %>
  • <% if ( request.getHttpSession(false) == null ) { // special processing } %>

Answer : <% if ( request.getSession(false) == null ) { // special processing } %>

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?


Options are :

  • 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 }
  • 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 }
  • 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 }
  • 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 : 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 }

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 :

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

Answer : Intercepting Filter

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

You are creating a library of custom tags that mimic the HTML form tags. When the user submits a

form that fails validation, the JSP form is forwarded back to the user. The <t:textField> tag must

support the ability to re-populate the form field with the request parameters from the user's last

request. For example, if the user entered "Samantha" in the text field called firstName, then the

form is re-populated like this:

<input type='text' name='firstName' value='Samantha' />

Which tag handler method will accomplish this goal?


Options are :

  • public int doStartTag() throws JspException { JspContext ctx = getJspContext(); String value = ctx.getParameter(this.name); if ( value == null ) value = ""; JspWriter out = pageContext.getOut(); try { out.write(String.format(INPUT, this.name, value)); } (Exception e) { throw new JspException(e); } return SKIP_BODY; } private static String INPUT = "";
  • public void doTag() throws JspException { JspContext ctx = getJspContext(); String value = ctx.getParameter(this.name); if ( value == null ) value = ""; JspWriter out = pageContext.getOut(); try { out.write(String.format(INPUT, this.name, value)); } (Exception e) { throw new JspException(e); } } private static String INPUT = "";
  • public int doStartTag() throws JspException { ServletRequet request = pageContext.getRequest(); String value = request.getParameter(this.name); if ( value == null ) value = ""; JspWriter out = pageContext.getOut(); try { out.write(String.format(INPUT, this.name, value)); } (Exception e) { throw new JspException(e); } return SKIP_BODY; } private static String INPUT = "";
  • public void doTag() throws JspException { ServletRequet request = pageContext.getRequest(); String value = request.getParameter(this.name); if ( value == null ) value = ""; JspWriter out = pageContext.getOut(); try { out.write(String.format(INPUT, this.name, value)); } (Exception e) { throw new JspException(e); } } private static String INPUT = "";

Answer : public int doStartTag() throws JspException { ServletRequet request = pageContext.getRequest(); String value = request.getParameter(this.name); if ( value == null ) value = ""; JspWriter out = pageContext.getOut(); try { out.write(String.format(INPUT, this.name, value)); } (Exception e) { throw new JspException(e); } return SKIP_BODY; } private static String INPUT = "";

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions