Which two output the name of the product in the response?

Refer to the Exhibit.

A servlet sets a session-scoped attribute product with an instance of com.example.product an
forward to a JSP. Which two output the name of the product in the response? (Choose two)

Refer to the Exhibit.

A servlet sets a session-scoped attribute product with an instance of com.example.product an
forward to a JSP. Which two output the name of the product in the response? (Choose two)

A.
<%= product.getName() %>

B.
<jsp:useBean id=”product” class=”com.example.Product” />
<%= product.getName() %>

C.
<jsp:useBean id=”com.example.Product” scope=”page”>
<%= product.getName() %>
</jsp:useBean>

D.
<jsp:useBean id=”product” type=”com.example.Product”
scope=”page” />
<%= product.getName() %>

E.
<jsp:useBean id=”product” type=”com.example.Product”>
<%= product.getName() %>
</jsp:useBean>



Leave a Reply 13

Your email address will not be published. Required fields are marked *


Hao

Hao

I don’t understand. Question ask “session-scoped attribute”, why all options are using scope=”page”.

giuseppe

giuseppe

I agree with you. And if the exam aswers would be wrong? 🙂

giuseppe

giuseppe

…and so the questions

giuseppe

giuseppe

And if it were ‘page’ It would have been B,D. Why C?

Allan Santos

Allan Santos

B and D.
>>> BUT <<<

D should B scope=session.

B would write "Default
D would write the name of the product in the session

Nagarajan Muthukrishnan

Nagarajan Muthukrishnan

B is the only answer.

B searches in all scope. Finally B prints the session value.
D cannot be the answer. Because product is not available in page scope. so new product object needs to be auto instantiated. For auto instantiation class attribute is required. Here class attribute is missing. so the output of D would be some exception.

Zaid

Zaid

It wont’ search in all scopes because the default scope is page.

Nagarajan Muthukrishnan

Nagarajan Muthukrishnan

I have not tested it.
A and B both may be the answer.

Tiparega

Tiparega

Supposing scope=”page” is scope=”session”, answer should be C and D.
B is false as default scope value is “page” (is not like an EL).
C is true as the body can contain anything.

Adriano Palomino

Adriano Palomino

the answer is B,D.

Tiparega

Tiparega

Now I realize. It’s B,D.
But it’s as Allan Santos says:
B is a new Product, not the one in session (I was right that B is default scope: session. But as no “product” yet exists in page scope, it creates a new one).
C was completly wrong, as it doesn’t have any class or type attribute.