Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

j2eeCertificate Ques.

 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
a ques from j2eecertificate:-

1.public class ParamServlet extends HttpServlet {
2.protected void doGet(HttpServletRequest req, HttpServletResponse resp)
3.throws ServletException, IOException {
4.// insert code here
5.}
6.

Consider the following servlet code. Which code can be used at line 4 to obtain a JavaBean called "account" that is stored in the application scope?

1. application.getAttribute("account");

2. getServletContext().getAttribute("account");

3. req.getSession().getServletContext().getAttribute("account");

4. servletContext.getAttribute("account");

5. request.getAttribute("account");


The ans is 2,3
How can 3 be the ans??how can we get a ServletContext from session??ther is no method defined in HttpSession to get a servlet Context from it??

My answers were 1 and 2.
Where am i wrong?Please help..
thanks,
mallika
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mallika,

Option 1 is not correct since there is no object named application in servlet, application is a jsp implicit object.

As for option 3 : Please look Servlet API. HttpSession has a method getServletContext which returns a servlet context to which this session belongs. Hence option 3 is also correct.

So the correct answer are 2 and 3.
reply
    Bookmark Topic Watch Topic
  • New Topic