• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Need Help!

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic