I had been reading on servlets and all books deal with invoking a servlet by means of a form (POST requests).
I was wondering if there are other means to invoke a servlet by a client.
Here is my understanding: For POST requests to a servlet, we use a link thus making a GET request on that servlet and in the servlet we need to call doPost() from doGet().
You can write a client that creates
GETandPOSTHTTP messages and invoke a servlet. However you can use the Apache Commons HTTP Client to do that.Also, from your question you seem to thin that all Servlets handle
GETrequests via aPOSTrequest. That is incorrect. The reason it is done in the servlet you viewed is because the servlet does that same thing for bothGETandPOSTrequest. So to minimize the amount of duplicate code it is so written.UPDATE: It seems Apache Commons HTTP Client is now end of life, and is no longer being developed. It has been replaced by the Apache HttpComponents project in its HttpClient and HttpCore modules, which offer better performance and more flexibility.
UPDATE2: I took your original question as “How can we invoke servlets other than from the browser”. Well, a browser is just a client that efficiently and easily lets us make
GETandPOSTrequests to a server [in our case aServlet]. We can also write a Java proram to makeGETandPOSTrequest to ourServlet, but that will be tedious and cumbersome. So, we can use the libraries specified above to do that. These libraries are not limited to client Java prorams and can be used from any application that can invoke Java code [and that includes JSP].