Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doPost() vs doService()

 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I've got a servlet that doesn't need to be passed any parameters, it just gets called from one html page and displays results in a new page. Do I use doService() or the usual doPost()? Something's not working at the moment, and I'm not quite sure how to figure it out. Is there a method that does not require any parameters but that will run automatically?
Thanks,
Annette
 
Chris Klu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it doesn't take any parameters use doGet()
 
Danny Mui
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to treat gets and posts the same, override the doService() method so that a post and get will result in the same output. On the other hand, if you need to be specific (ie ignore post methods) then override the doGet() and doPost() methods as needed.
of course all IMHO.
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all!
I got it to work. I overrided doGet().
Does anyone know how to call it from a link?
i.e. on a webpage I have something like:
<a href="http://some url/servlet/servlet_name"> click here </a>
I've tried that, but it doesn't work. The only way I can do it is to call it directly from the address bar in the browser. Can it be done with a link?
thanks,
Annette
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure - there is nothing magic about a servlet, a GET is what a browser does for any link. Anywhere you would write href="someurl" the url can point to a servlet.
The main thing is that your server must be configured correctly to interpret that URL as a request to the servlet.
Bill
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Annette,
I just give an example which I used. Please take a look at this. In servlet side, I coded doGet(..) and doPost(..) calls doGet(..) and didn't do anything with doService(..). The html page is not a form. This is a link I used in my html page. When we click on Serup Accounts link it will invoke doGet(..) of SetupServlet.
By default all href links will be linked to doGet(..) of the servet to which they are linked to. If you could give the same address fron browser and invoke means, the same url in a html also should work since both use GET method. Try to check the spelling (case sensitive) of the url in your href link.

<A HREF="http://www.webappcabaret.com/maha/servlet/SetupServlet?RequestType=Setup Accounts">Setup Accounts</A>
regds
maha anna
 
B Wiley Snyder
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Annette L'Heureux:
Thanks all!
I got it to work. I overrided doGet().

Does anyone know how to call it from a link?
i.e. on a webpage I have something like:
<a href="http://some url/servlet/servlet_name"> click here </a>

I've tried that, but it doesn't work. The only way I can do it is to call it directly from the address bar in the browser. Can it be done with a link?

thanks,
Annette


How do you over ride a doGet(), I have to post info to the page but I'm doing it from a link??? Is that possible, if you post from a link you're screwed. How can I do a post from a link if I can't over ride get?



 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<a href="http://some url/servlet/servlet_name"> click here </a>

I've tried that, but it doesn't work.

The use of "/servlet/" indicates that you have encountered the dreaded "invoker" servlet problem. Read this ranch FAQ on the invoker.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic