If you want a servlet to take the same action for both GET and POST request, what should you do?

Simply have doGet call doPost, or vice versa.

Showing Answers 1 - 2 of 2 Answers

veeru

  • Sep 8th, 2005
 

Simply override both the doGet() and doPost() 
Here is the code 
public doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException 

// write a a code for dynamic content here 

 
public doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException 

doGet(req,res); 
}

  Was this answer useful?  Yes

ravi

  • Feb 15th, 2006
 

in addition to what veeru mentioned, we can override the service(HttpServletRequest , HttpServletResponse ) method as well. service method takes priority over doGet() and/or doPost().

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions