• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

service argument doubt

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

My confusion is regarding service argument. In one book it is written like
container passes ServletRequest to the service() and inside service two
objects HttpServletRequest and HttpServletResponse are created that are
further passed to the doGet() and doPost() method.


And somewhere it is written like, container only passes these two objects
to the service method.

Please clarify.


Thanks,
[ May 28, 2007: Message edited by: Chandra Bhatt ]
 
Pravin Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever a server receives a request from the client, it would first
create instances of ServletRequest and ServletResponse and invoke
doFilter method on the FilterChain, which is created for each request
received. It is the FilterChain's doFilter method which in turn
invokes the service method on the Servlet, and in case the
Servlet happens to be a subclass of HttpServlet request whose
service method has not been overridden, then the inherited service
method invokes the doGet or the doPost depending on the result of
getMethod invoked on the instance of HttpServletRequest.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chandra, can you please clarify about "session()". What is this method ? Where does it come from ?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satou,

I am newbie to "Servlet & JSP" world.

Service method comes from Servlet Interface that is implemented by the
GenericServlet class that is extended by HttpServlet. Our servlets extend
from HttpServlet (abstract) class.

GenericServlet class (an abstract class) gives definition to the service()
method. service() method is the method of the servlet life cycle that is
called each time user makes request. Container creates two objects
ServletRequest and ServletResponse ans passes them to the service method.
service(ServletRequest req, ServletResponse res) method decides which method
doGet() or doPost() to call on behalf of the user request GET and POST
method. It is recommended to not override the service() method;


Please correct me, if I missed, or got wrong.

Thanks for asking ,
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I still don't understand where you've taken that session() from. You were talking about session(), not service().
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooops!!!

It was service() not session.

I am very sorry for consuming your valuable time due to my silly typo.


"MAIN POST EDITED"


Thanks,
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Chandra,

In that case, the second statement is correct. The container passes both request and response object to the service method.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satou!





With Regards,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic