aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes page scope Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "page scope" Watch "page scope" New topic
Author

page scope

Ravi Bansal
Ranch Hand

Joined: Aug 18, 2008
Posts: 86
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.?


SCJP 5.0 94%
OCE-EJBD 90%
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3164
    
  47

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.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Siphiwe Madi
Ranch Hand

Joined: Aug 16, 2007
Posts: 70
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


Regards, Siphiwe Madi
[SCJP, SCWCD, __] Next ... scjwsd
Ravi Bansal
Ranch Hand

Joined: Aug 18, 2008
Posts: 86
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
vani venkat
Ranch Hand

Joined: Nov 21, 2006
Posts: 142
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?


SCJP 1.4, SCWCD 1.5
Siphiwe Madi
Ranch Hand

Joined: Aug 16, 2007
Posts: 70
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: page scope