my dog learned polymorphism*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes ServletContext related Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "ServletContext related" Watch "ServletContext related" New topic
Author

ServletContext related

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Given a valid deployment descriptor (WEB.XML) containing the following code

<context-param>
<param-name>bestwebsite</param-name>
<param-value>www.examulator.com</param-value>
</context-param>
<servlet>
<servlet-name>GetInitParameter</servlet-name>
<servlet-class>com.examulator.GetInitParameter</servlet-class>
<init-param>
<param-name>bestwebsite</param-name>
<param-value>www.javaranch.com</param-value>
</init-param>
</servlet>

And given that cfg is a valid ServletConfig object and ctx is a valid ServletContext object which of the following statements are true?

Choose at least one answer.
a. cfg.getInitParameter("bestwebsite") will return www.examulator.com Incorrect
b. ctx.getInitParameter("bestwebsite") will return www.javaranch.com Incorrect
c. ctx.getInitParameter("bestwebsite") will return www.examulator.com Correct
d. cfg.getServletContext().getInitParameter("bestwebsite"); will cause a compile time error Incorrect
e. ctx.getServletConfig().getInitParameter("bestwebsite"); will cause a compile time error

explaination

You need to know the difference between ServletConfig and ServletContext for the purpose of the exam. ServletContext might well have been called ApplicationContext to make its purpose clearer, but it wasn't. You can get a context from a config, but you cannot directly get a config from a context.

-My question is will "e" be the right answer or not?


SCJP-1.5<br />SCWCD-1.4
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

My question is will "e" be the right answer or not?

There's a getServletContext() in ServletConfig. But do you see any getServletConfig() method in ServletContext ?


[My Blog]
All roads lead to JavaRanch
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Thanks. But my question is, it will give compile error or not?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

But my question is, it will give compile error or not?

Do you remember what you've learned in SCJP ? What happens when you call a method which does not exist ?
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
I wont compile. Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ServletContext related
 
Similar Threads
ServletConfig & ServletContext
marcus green: Mock test
Unable to fetch config parameter in jsp
answers to questions in Macus Green tests
Which statement is true regarding initialization parameter