Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Need Help!

 
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?
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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.
 
Ranch Hand
Posts: 352
  • 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
 
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: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also there is a pageContext.findAttribute if you don't know the scope...
 
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.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic