aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Question ID :995549757220 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Question ID :995549757220" Watch "Question ID :995549757220" New topic
Author

Question ID :995549757220

Raj Paul
Ranch Hand

Joined: Jul 09, 2002
Posts: 77
Following is the code for LoginServlet. Assuming that it is not preloaded or preinitialized, which of the given statements about it are correct?
(Statements given below are regarding the methods defined in this class.)
//[code]
public class LoginServlet extends HttpServlet
{
public void init()
{
//initialize db.
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
{
//do something
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
{
//do something
}
}
//[code]
1) For any HTTP request, at the most 2 of its methods will be called
2) For any and every request, atleast 1 of its methods will be called
3) for any and every request init() will be called
4) init() may be called more than once for an instance of this servlet
5) it'll throw an exception at runtime if an HTTP DELETE request is sent to it.

What would be the answer ?
Nazmul Huda Sarkar
Ranch Hand

Joined: Feb 01, 2002
Posts: 317
Here service method is not overriden. So if I think only the overriden methods are considered, then only answer b is right. You see, for the first request, init, service and another method doGet/doPost... will be called. Thats why (a) is wrong.


Nazmul<br />SCJP,SCWCD,IBM OOAD with UML
Raj Paul
Ranch Hand

Joined: Jul 09, 2002
Posts: 77
is there any difference between " every request" & "HTTP request" ?? in a
Nazmul Huda Sarkar
Ranch Hand

Joined: Feb 01, 2002
Posts: 317
Good question....I guess no....
Any one on this isesue ?
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3336
    
    8
Originally posted by Raj Paul:
(Statements given below are regarding the methods defined in this class.)
1) For any HTTP request, at the most 2 of its methods will be called
2) For any and every request, atleast 1 of its methods will be called
3) for any and every request init() will be called
4) init() may be called more than once for an instance of this servlet
5) it'll throw an exception at runtime if an HTTP DELETE request is sent to it.

What would be the answer ?

Option 1 is correct, as is given in the s/w. For the very first request to this servlet (if it is a GET or POST), init() and doGet/doPost will be called.
2 is wrong because it does not implement all the doXXX methods (such as doDelete, doPut, etc), so for such requests, no method of this class will be called.
Options 3, 4, and 5 are obviously wrong.


Enthuware - Best Mock Exams and Questions for Oracle/Sun Java Certifications
Quality Guaranteed - Pass or Full Refund!
Raj Paul
Ranch Hand

Joined: Jul 09, 2002
Posts: 77
Hi Paul,
so do u mean to say that HTTP request means only GET & POST ?
Raj Paul
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
1 is the only right i belive.
Ash.
SCJP/SCWCD


Asher Tarnopolski
SCJP,SCWCD
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3336
    
    8
Originally posted by Raj Paul:
Hi Paul,
so do u mean to say that HTTP request means only GET & POST ?
Raj Paul

No, it means any HTTP request ie. GET, POST, DELETE, PUT, OPTIONS, and HEAD. In such questions, assume that request means HTTP request unless otherwise stated.
no more user
Ranch Hand

Joined: Aug 07, 2002
Posts: 39
Originally posted by Paul Anil:
2 is wrong because it does not implement all the doXXX methods (such as doDelete, doPut, etc), so for such requests, no method of this class will be called.

its clear for me, but..
(Statements given below are regarding the methods defined in this class.)
Nazmul Huda Sarkar
Ranch Hand

Joined: Feb 01, 2002
Posts: 317
Is there any chance you guys are overlooking the default service() method ? For any request first service() will be invoked. Then depending on the request it will pass the request to get..post..put...to any relevent method. So for the very first request init(), service() and a relevent method will be invoked. Ok...now if u only consider the given code...then I don't have any argument. I dislike such misguideing question.
Am I wrong?
no more user
Ranch Hand

Joined: Aug 07, 2002
Posts: 39
im with you :roll:
Vedhas Pitkar
Ranch Hand

Joined: Jan 27, 2001
Posts: 445
Well if the servlet implements SingleThreadModel then c is also correct .Right?
Nazmul Huda Sarkar
Ranch Hand

Joined: Feb 01, 2002
Posts: 317
O yes, u r right...but the given class does not implements this...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question ID :995549757220