• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt in <useBean > Standard action

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The below is a Product bean class

package com.certkiller

public class Product {

private String name;
private double price;

public Product(){
this(“Default”,0.0)
}
//Setter and Getter methods
}

A session-scoped attribute, product, is stored by a servlet. That servlet then forwards to a JSP page. This attribute holds an instance of com.Certkiller.Product class with a name property of “The Matrix” and price property of 39.95.
Given the JSP page code snippet:

<jsp: useBean id = ‘product’ class = ‘com.Certikiller.Product’>
<jsp: setProperty name = ‘product’ property = ‘price’ value = ’49.95’/>
</jsp: Bean>

<%=product.getName()%>
Costs <%= product.getPrice() %>

What is the response output of this JSP page code snippet?

Ans. Given answer is : Default costs 49.95

But I think the answer should be: The Matrix costs 49.95

can anyone correct me
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the default useBean scope is page not a session right? aslo you did not paste javabean class argument constructor
 
Salim Khatib
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply

is that not true that useBean standard action first searches the "product" in all the scopes, and if it does not find it
then will create the the instance of product if the scope is not specified ?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Salim Khatib wrote:
is that not true that useBean standard action first searches the "product" in all the scopes, and if it does not find it
then will create the the instance of product if the scope is not specified



No, if scope is not specified , by default scope is page .
 
Salim Khatib
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given that

A servlet context listener load a list of com.example.Product objects from a database and stores that list into the catalog attribute of the ServletContext object.

Construct a jsp:useBean standard action to access this catalog.

The given answer is answer <jsp:useBean name = ‘catalog’ id = ‘catalog’ type = ‘com.example.Product’>

But I feel its wrong .. as there is no name attribute for jsp:useBean

Please correct if I am worng
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Salim Khatib wrote:
But I feel its wrong .. as there is no name attribute for jsp:useBean


yes you are correct. you will get compile time error
 
Don't MAKE me come back there with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic