Question:
If you want a servlet to take the same action for both GET and POST request, what should you do?
Answer:
Simply have doGet call doPost, or vice versa. Source: CoolInterview.com
u can call doGet Method in doPost method and vice versa i.e
public void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServetException,IOException { doPost(req,resp); } public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServetException,IOException { doGet(req,resp); }
----------------------------- we can create a method say x and call that method in both i.e doGet { x(); } doPost() { x(); } Source: CoolInterview.com
Answered by: raj | Date:
| Contact raj
The first answer above will create a deadlock, so to take the same action for both Get and Post requests, call one of the doGet() or doPost() methods from the other method, not both. public void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServetException,IOException { doPost(req,resp); } public void doPost(HttpServletRequest req,HttpServletResponse resp) throws ServetException,IOException { Action to be taken } Source: CoolInterview.com
Answered by: harish h n | Date: 5/4/2009
| Contact harish h n
You can have doGet() and doPost() method and another method say handleRequest() called by both of them. and handleRequest can do the rest of the operations. Source: CoolInterview.com
Answered by: Manju | Date: 11/12/2009
| Contact Manju
override service method of Servlet interface or Generic Servlet class Source: CoolInterview.com
Answered by: Pk | Date: 11/15/2009
| Contact Pk
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|