• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reason for change of scope from request to page

 
Jacob Thomas
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This post is regarding the reason for the change of scope in one of the examples in Head First Servlets and JSP. On page 349, it gives the following code snippet for the <jsp:setProperty> standard action:



On the next page, the <jsp:setProperty> is nested in the <jsp:useBean> tag:




As you can see, the scope is changed from request to page. Is there any particular reason for this change? Thank you.
 
salil verma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just see at the end of page 349 it is mentioned that user want one more instance of same name of same bean but want to set the properly again.
So in the second senario we have changed the scope of the bean . In this case two instances of the same bean will exist one at request scope and the second at page scope.
 
Jacob Thomas
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply Salil. But I disagree with your reply:

just see at the end of page 349 it is mentioned that user want one more instance of same name of same bean but want to set the properly again.
So in the second senario we have changed the scope of the bean . In this case two instances of the same bean will exist one at request scope and the second at page scope.


When the non-nested <jsp:setProperty> tag is used, it resets the bean's property value had the bean already existed. But when <jsp:setProperty> is nested inside the body of <jsp:useBean>, the property setting is conditional and the values will be set only if a new bean is created. ie., there is only one instance of the bean and it exists at page scope.

But I am quite confused by the change of scope in the examples. I checked the errata section of the book given online but didn't find anything regarding this. I know it is not an error per se, but I am puzzled and was wondering if there is any requirement in the specification that demands for a change of scope to a more restrictive one as given in the cited problem. Thank you.
 
salil verma
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to mention that the user wanted to have two instances of the bean with the same attribte name .That is why, the user created one at request scope and other a page scope.
kindly refer to the followin code for to get what exactly i want to mention. I am refering to the attribute name "bean_name".


 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I want to get the value of the attribute with a specified request or page scope, can I get the corresponding value? If I'm specifying another scope rather than those two, will it return request scope value? Or what will it be?

Thanks.
 
dennis du
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For <jsp:useBean> tag , there is a default scope ="page" ,if you miss it.

But for the EL, it will search from page->request->session->application

That's it.

And at last, I don't think there are some reasons for the HF to change the scope from request->page.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic