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.
The moose likes Servlets and the fly likes How can I call doGet method? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "How can I call doGet method?" Watch "How can I call doGet method?" New topic
Author

How can I call doGet method?

Nuha Iqbal
Greenhorn

Joined: Jul 24, 2012
Posts: 2
Hi,

I am beginner to JAVA and I have the following doGet method, and I need to call to from another method



I want to know how to call this method from another method, just like the following.



the line
return doGet(request, response);
I want to know the correct way of calling?
Greg Charles
Bartender

Joined: Oct 01, 2001
Posts: 2542
    
  10

Hi Nuha, welcome to JavaRanch!

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.
vinayak jog
Ranch Hand

Joined: Apr 01, 2011
Posts: 76

Hey,
Please tell the reason why you want to call doGet from another method.
Anirudh Srivastav
Greenhorn

Joined: Jun 30, 2012
Posts: 13

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
PMP, OCJCP 6
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56221
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35253
    
    7
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.


Android appsImageJ pluginsJava web charts
Anirudh Srivastav
Greenhorn

Joined: Jun 30, 2012
Posts: 13
Bear Bibeault / Ulf Dittmer

Thanks for sharing the valuable information.

Best Regards
jaan bhavsar
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Hi,

You can try with HttpsURLConnection which will send the request to the method from Java Programme.

Regards
Jatan Bhavsar
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How can I call doGet method?
 
Similar Threads
how to use getLastModified() ?
Is it a POST or GET request?
dopost() and doget() methods
Call a servlet from another servlet
RequestDispatcher