ricjava
asked on
Writing codes in service() method
hi experts,
Often I seen programmer writing codes in the service method of servlet. By right, I think we should write only in doGet or doPost. Why want to write in service method? Is it a bad practise or somewhat any reason?
Thanks
Often I seen programmer writing codes in the service method of servlet. By right, I think we should write only in doGet or doPost. Why want to write in service method? Is it a bad practise or somewhat any reason?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Factorized code means code that you want to apply regardless if it is get/post/...
e.g you might want to set the response buffer size for any kind of request.
That is relevant only if the same servlet supports/overrides more then one request type [get/post/...])
After you applied to common/factorized code you want to delegate the call to the right method (doPost,doGet,...)
and that can be achived by calling super.service(...)
e.g you might want to set the response buffer size for any kind of request.
That is relevant only if the same servlet supports/overrides more then one request type [get/post/...])
After you applied to common/factorized code you want to delegate the call to the right method (doPost,doGet,...)
and that can be achived by calling super.service(...)
You can put code in service() if you want but then you need to handle lots of things yourself, which are handled by the service() method of HttpServlet (which yoiu would be overriding).
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServlet.html#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpSer vletRespon se)
Basically it does all the standard things for you, and leaves you to do the stuff specific to your servlet.
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServlet.html#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpSer
Basically it does all the standard things for you, and leaves you to do the stuff specific to your servlet.
ASKER
I don't like to put codes in service method but saw others doing it.
so objects, u don't recommend anyone to put codes in service method?
so objects, u don't recommend anyone to put codes in service method?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks everybody..
you are welcome :-)
(:
ASKER
>One case where you might consider putting code in the service method (though you can easilly >get around without it)
>is to have some factorized code there before calling super.service(...) for further dispatching.
What is factorized code?
And why do u want to call the super.service?
Can you explain a bit:)