This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "j2eeCertificate Ques." Watch "j2eeCertificate Ques." New topic
Author

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

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
 
 
subject: j2eeCertificate Ques.
 
Similar Threads
j2eeCertificate(attribute scope) ques
j2eeCertificate(taglib prefix restriction) ques
j2eeCertificate(custom tag ) ques
j2eecertificate mock exam question
J2eeCertificate ques