• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

page scope

 
Ravi Bansal
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • 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.?
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4680
329
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
Siphiwe Madi
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
vani venkat
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic