This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
While it's possible to make a direct call to a servlet's doGet() method, it's probably not going to be useful to do that. Servlets are meant to be deployed into a servlet container, like Tomcat, JBoss, or WebLogic. The doGet() method is called automatically by the framework to handle an incoming GET request, usually from a web browser. The method either writes directly to the response's output, which then renders back on the browser, or it forwards the request to another URL to be handled there.
Hey,
Please tell the reason why you want to call doGet from another method.
Anirudh Srivastav
Greenhorn
Joined: Jun 30, 2012
Posts: 13
posted
0
The Service method would invoke doGet() or doPost() depending on the equivalent (GET/POST) HTTP methods. If your servlet should handle both POST and GET HTTP method you ll call doGet from the doPost method.
Anirudh Srivastav wrote:
The Service method would invoke doGet() or doPost() depending on the equivalent (GET/POST) HTTP methods. If your servlet should handle both POST and GET HTTP method you ll call doGet from the doPost method.
Though it should be mentioned that handling GET and POST in the same way is considered a poor practice those days.
Bear Bibeault wrote:Though it should be mentioned that handling GET and POST in the same way is considered a poor practice those days.
I'd go further than that - the HTTP specification is clear on the fact that GET and POST have different characteristics, and should be used in different circumstances. Any design that uses them interchangeably may cause suboptimal (or downright broken) behavior in the presence of HTTP intermediaries like caches, proxies and the like.