Win a copy of Learning Java by Building Android Games this week in the Android 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Mock exam question about Context and environment entry  RSS feed

 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I've got the following question:

Given a bean named 'Customer', and an environment entry named 'lastName', which code fragment(s) inside of the bean class would return the value of the environment entry?

Answers (here for brevity I put only 2 of the five)


1)


2)


I said one, but correct was 2. Why?
 
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, all environment entries are stored directly in the "java:comp/env" context or a subcontext thereof. If you see something like

initCtx.lookup("java:comp/env/ctx1/ctx2/entry");

it means that the deployment descriptor has to look like

<env-entry>
<env-entry-name>ctx1/ctx2/entry</env-entry-name>
<env-entry-type>SomeType</env-entry-type>
<env-entry-value>SomeValue</env-entry-value>
</env-entry>

Bottom line: The bean name must no be included in the context name because each bean has its own private context anyway. This means that two different beans each have their own "java:comp/env" context. Moreover, if there are subcontexts, they are specified in the deployment descriptor by means of a /-separated sequence of characters.
[ July 27, 2004: Message edited by: Valentin Crettaz ]
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Valentin Crettaz:



Thank you. That was clear!

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!