Well, HttpServletRequest has a getMethod() method. But in most designs the programmer should already know whether the servlet is meant to handle GET or POST requests, and just code a doGet() or doPost() method.
If you are collapsing doGet() and doPost() into a single process() method, then to all appearances you don't care if it is GET or POST. If the logic is to be different based on the method, then it is usually implemented in the appropriate method handlers. as Paul has already pointed out.
But perhaps the difference in logic is so trivial that you really do want a single service() method. As Bear Bibeault reminded me in a different thread, you also have HttpServletRequest.getMethod() to tell you which HTTP verb was used. If this is the case though, you may want to re-think your design.
Lastly, a service() method traditionally takes the HttpServletResponse object as a second argument -- I think that's the way you see it in the Netbeans HttpServlet templates. [ February 07, 2007: Message edited by: Philip Shanks ]
Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Joined: Sep 20, 2001
Thanks for the reply.
I realized that what I really want to do is to distinguish if a request is from URL (in browser address or a link from a web page) or from subsequent form submission (when user clicks a button to submit the form). Since form submission can also be GET, use of Request.getMethod may not accomplish what I want to do.
I may code a hidden field in form to tell servlet what request is a form request.