• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed in useBean standard action

 
Salim Khatib
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the jsp code

<%

pageContext.setAttribute("product", new com.example.Product(" Pizza", 0.99));

%>

<%-- insert code here--%> --- > what should be inserted here to output thename of the product in the response ?

Given answers are

1. <jsp:useBean id = "product" class = "com.example.product"/>
<%= product.getName()%>

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

I think both the given answers are wrong

please let me know your suggestion guys , its urgent




 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually unless i am drunk i think both work correctly ;)

in addition you could use expression language such as

${product.name}

or

${product["name"]}


(peace)
 
Salim Khatib
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the quick reply

The below code will set the product attribute in the application scope right ?

<%

pageContext.setAttribute("product", new com.example.Product(" Pizza", 0.99));

%>

For the first answer I feel they should have mentioned scope as application
and for the second answer the scope is mentioned as page , which I feel should be application

please let know your suggestion


 
Omar Al Kababji
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
attention when you don't specify a scope parameter then the default scope is used which is "page" scope and not the application scope. regarding your last question no it will set in the page scope, if you want to place it in the application scope you should do

application.setAttribute(.....);

the pageContext object is an object available only in JSP's which is of type PageContext and is used to add a fourth scope wich is the "page" scope, don't mistake the pageContext with the servletContext.

pageContext ---> PageContext
application ---> ServletContext


(peace)


 
Salim Khatib
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your clarrification

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic