This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes j2eeCertificate Ques. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "j2eeCertificate Ques." Watch "j2eeCertificate Ques." New topic

j2eeCertificate Ques.

mallika shah
Ranch Hand

Joined: May 11, 2006
Posts: 164
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

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..
Dhruvi Manchanda

Joined: Mar 20, 2007
Posts: 15
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.

Dhruvi<br /> <br />SCJP 1.4,SCWCD
I agree. Here's the link:
subject: j2eeCertificate Ques.
It's not a secret anymore!