Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help!

 
Rahul Shende
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I came across this Q in a mock.
why 1st answer ain't right? wont it luk through all the scopes for "foo" attribute.
1st & 2nd both should b correct. Am i right?
 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rahul, welcome to javaranch

I came across this Q in a mock.


Please Quote Your Sources when you post a question. Tell us exactly from which mock exam this question is. Also please Use A Meaningful Subject Line when you start a topic.
 
Harshana Dias
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you access properties of a request scope attribute you have to do the option 2. but to access the attribute both should be working? please someone confirm my answer right or wrong
 
Adrian Precub
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as i know you have to get the request from the pageContext implicit object and then get the requests attributes.If you say pageContext.getAttribute('attrName') it will get a page scoped attribute, not request scope.You can however say pageContext.getAttribute('attrName',scope) and get the desired attribute at the desired scope
 
Ankit Garg
Sheriff
Posts: 9578
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also there is a pageContext.findAttribute if you don't know the scope...
 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also there is a pageContext.findAttribute if you don't know the scope...


but pageContext.findAttribute("foo"); cannot guarantee you ,get attribute foo in the request scope .

findAttribute - searches for foo attribute in all scopes , starting from page , request , session and application.

so if attribute foo happens to be both in page and request scope, you will be ending up with foo attribute from page scope , not request scope .

so ,

pageContext.getAttribute("foo", scope ) is the best option for getting foo in the specified scope.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic