dcsimg
can I write service() ,doGet() and doPost() method in single Servlet?
7 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   pravin_kumar
Posted On:   Monday, May 9, 2005 06:14 AM

			
can I write service() ,doGet() and doPost() method in single Servlet?If in Servlet We have service() and doGet()Method and we have got request as a POST then what will happened?

Re: can I write service() ,doGet() and doPost() method in single Servlet?

Posted By:   Anonymous  
Posted On:   Friday, May 27, 2005 01:52 AM

You can override all the 3 methods. But good design practice is..ONE SHOULD NEVER OVERRIDE SERVICE() METHOD BECAUSE THERE IS NO NEED FOR IT.

PALLAV

Re: can I write service() ,doGet() and doPost() method in single Servlet?

Posted By:   Anonymous  
Posted On:   Tuesday, May 17, 2005 05:32 AM

yes why not.it's possible to write service(),doGet(),doPost()methods in single servlet.
Incase of service() method,doGet()Method if we have got request as a POST then the service()method will be executed.

Re: can I write service() ,doGet() and doPost() method in single Servlet?

Posted By:   Anonymous  
Posted On:   Tuesday, May 17, 2005 05:25 AM

yes why not.it's possible to write service(),doGet(),doPost()methods in single servlet.
Incase of doGet()Method if we have got request as a POST then the service()method will be executed.

Re: can I write service() ,doGet() and doPost() method in single Servlet?

Posted By:   Anonymous  
Posted On:   Tuesday, May 17, 2005 05:10 AM

yes why not.it's possible to write service(),doGet(),doPost()methods in single servlet.but, 
where as doGet()Method if we have got request as a POST it's not accepted & give Exceptions.

Re: can I write service() ,doGet() and doPost() method in single Servlet?

Posted By:   Anonymous  
Posted On:   Tuesday, May 10, 2005 08:28 AM


Yeah. You can write all the methods in a single servlet.

As for doGet/doPost, just define any one of them and call this function from the other one.

For e.g

void doGet(HttpServletRequest rq, HttpServletResponse rs) throws ...
{
doPost(rq,rs);
}

void doPost(HttpServletRequest rq, HttpServletResponse rs) throws ...
{
//Get the work done here
}

Regards
Vishal

Re: can I write service() ,doGet() and doPost() method in single Servlet?

Posted By:   D_Rajasekhar  
Posted On:   Tuesday, May 10, 2005 06:27 AM

It is possible legally, to write all these three methods in a single HttpServlet. But by default, service() method will be run first, irrespective of the form method in the calling html or jsp page. From there, we can divert it into the required doPost() or doGet () methods.

Re: can I write service() ,doGet() and doPost() method in single Servlet?

Posted By:   Milan_Boruvka  
Posted On:   Monday, May 9, 2005 06:29 AM

You should not override service() method.
If your request is POST, then you need only to override doPost() method.



service() method must is already implemented in the HTTP servlet. It contains the logic which dispatches the HTTP request to appropriate method - either doPost() or doGet() for HTTP POST resp. HTTP GET.



Good practice is to call doPost() method from the doGet() body or print that doGet() is not supported.



More on this topic:


http://www.unix.org.ua/orelly/java-ent/servlet/ch02_02.htm


Cheers,
Milan

About | Sitemap | Contact