Assume the product attribute does NOT yet exist in any scope.
Which two create an instance of com.example.Product and initialize the name and price properties
to the name and price request parameters? (Choose two)
A.
<jsp:useBean id=”product” class=”com.example.Product” />
<jsp:setProperty name=”product” property=”*” />
B.
<jsp:useBean id=”product” class=”com.example.Product” />
<% product.setName( request.getParameter( “name” ) ); %>
<% product.setPrice( request.getParameter( “price” ) ); %>
C.
<jsp:useBean id=”product” class=”com.example.Product” />
<jsp:setProperty name=”product” property=”name”
value=”${param.name}” />
<jsp:setProperty name=”product” property=”price”
value=”${param.price}” />
D.
<jsp:useBean id=”product” class=”com.example.Product”>
<jsp:setProperty name=”product” property=”name”
value=”${name}” />
<jsp:setProperty name=”product” property=”price”
value=”${price}” />
</jsp:useBean>
A, C ok BUT why not B?
Maybe because scritping is not best practice
because setPrice method require a double parameter?
You are right, The conversion from string to double is not supported when using scripting.
Ref : “Head First Servlets & JSP” page 362