• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I call doGet method?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 83
Netbeans IDE MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,
Please tell the reason why you want to call doGet from another method.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Anirudh Srivastav
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear Bibeault / Ulf Dittmer

Thanks for sharing the valuable information.

Best Regards
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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

Regards
Jatan Bhavsar
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic