File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ServletContext related

 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
dolly shah
Ranch Hand
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. But my question is, it will give compile error or not?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 383
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wont compile. Thanks.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic