doGet and doPost of HttpServlet are protected.
This is from "just
java 2":
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws javax.servlet.ServletException, java.io.IOException;
You call methods on the HttpServletRequest argument to find out what the browser is asking for exactly. There's a method you call to get a PrintWriter from the HttpServletResponse, and you write your resulting plain text, HTML, image file, audio file, or Javascript using it. What you write gets sent back to the browser. It's as simple as that.
Note that the two routines are labelled as "protected," meaning that they can only be called by routines in the same package or in a subclass. That makes sense. It is probably not meaningful for your
servlet to be called other than to process an HTTP request. If it is meaningful to invoke your doPost() routine otherwise, then your system design probably needs some refactoring, perhaps to split out a chunk of the common code into a Java bean.