• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Mock Question - What is the answer?

 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The ServletContext interface provides direct access to the hierarchy of static content documents that are part of the web application, including HTML, GIF and JPEG files through following methods
A

getSource
B

getResource
C

getResourceStream
D

getResourceAsStream
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

->getResourceAsStream(...)


Thanks,
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Options B,D are correct.
B returns URL, where we need to handle URLConnection objects.
D returns InputStream directly, where container handles URLConnection objects.
 
Joe San
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, B and D are correct!
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure why getResource() is the correct answer; it returns
URL whereas getResourceAsStream() returns InputStream.

Would anybody please the option 'B' with regard to what is asked in the
question?


Thanks,
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can access the resource using the URL that is returned by getResource(). You open a stream on the URL. getResourceAsStream saves you a setp by doing it for you. Look up the IO tutorial and you will see these 2 methods used and it will explain the differences between them
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Michael,

I got it, using getResourceAsStream() or getResource() both solves our
purpose. Whereas getResourceAsStream() directly returns the stream.

So when we have URL, we use that URL to open a stream, so still we need to
follow one more step in getting the stream. Right?


Thanks,
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, that is correct
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jothi Shankar Kumar Sankararaj:
The ServletContext interface provides direct access to the hierarchy of static content documents that are part of the web application,



As chandra said, i also think of same when seeing the words "direct access" which gives an impression that you get the content of the resource at hand with NO additional steps!

But does the word "hierarchy of" contribute something to this context? I think its NOT. Any suggestions?
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I always try to understand the spirit of the question rather than the exact words used. For me, this prevents me from over thinking the question, which I sometimes do. Since most books or articles that deals with this subject discuss using both of the methods, I always think that both methods may be used.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Ku:
I always try to understand the spirit of the question rather than the exact words used. For me, this prevents me from over thinking the question, which I sometimes do. Since most books or articles that deals with this subject discuss using both of the methods, I always think that both methods may be used.




Yes, sometimes its helpful!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic