• 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

page scope

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HFSJ page 416 (Answer 3).


I have doubt that if the attribute is set in the request scope by the servlet class and then is it possible to access that attribute in the JSP page using standard action <jsp:getProperty> having scope not mentioned explicity, which means that default scope for the standard action is Page.?
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If an attribute is not found in the page scope, then it looks on the request scope, then session scope, and finally on the application scope.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ravi,

Although i couldn't find any details about setting request scoped attributes on page 416 on book (HFS&J, 2nd Edition). But as its been mentioned on the book that:

In a Servlet there are 3 scope objects:

1. request (HttpServletRequest)
2. session (HttSession)
3. context (ServletContext)

Note: There is NO 'page' scope object (unless the servlet is generated from the JSP) &


In a JSP there are a total of 4 implicit scope objects:

1. request (HttpServletRequest)
2. session (HttSession)
3. application (ServletContext), which is basically same as context from servlet
4. page (PageContext)

Note: The JSP adds an addition scope object 'page'.

Therefore, in terms of your question if you set a request attribute inside the servlet it will be stored in
the 'request' scope and can only be accessed from a 'request'.

If you try to access the same request attribute in your jsp using the <jsp:useBean/> you must explicitly specify
the scope as 'request'



If you don't explicitly specify the scope, it will look in the default which is 'page' and will return 'nothing'.

Regards,
Siphiwe Madi
[SCJP, __, __]
Next ... scwcd, scjwsd
 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I checked the 2nd edition and i found its corrected over there......in the same question scope has been mentioned explicitly.....i was reading the older edition of HFSJ..........


thanks for explanation anyways......Siphiwe
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If an attribute is not found in the page scope, then it looks on the request scope, then session scope, and finally on the application scope.



this happens in EL. does it work for standard action as well?
 
Siphiwe Madi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vani venkat wrote:

If an attribute is not found in the page scope, then it looks on the request scope, then session scope, and finally on the application scope.



this happens in EL. does it work for standard action as well?




It doesn't seem to work with standard action. It works for EL yes. But for standard action you have to explicitly specify the attribute scope.

Ravi:
I hope your question has been answered.

Regards,
Siphiwe Madi
[SCJP, __, __]
Next ... scwcd, scjwsd
reply
    Bookmark Topic Watch Topic
  • New Topic