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

j2eeCertificate Ques.

 
mallika shah
Ranch Hand
Posts: 164
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Dhruvi Manchanda
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic