• 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

doGet() and doPost()!!!

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi folks,
i have the following code:

when i execute this servlet, why the doGet()method is always invoked even though this method is not explicitly called? I know when a form is submitted, a method attribute value is set either GET or POST that makes either doGet() or doPost() being called accordingly. but when GET or POST is not explicitly called like i execute a above servlet, what makes the doGet() method of the servlet invoked and why not doPost()?
please clarify me this mechanism.
And Also, why does setContentType("text/html") have to be present? can't we do without it? I tried running above servlet without it, bud didn't see any problem?When does it cause a problem without it?
thanks.
[ September 09, 2003: Message edited by: Namaste Sathi ]
[ September 13, 2003: Message edited by: Jim Yingst ]
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
doGet is the default method called when either a method is not specified within a form tag, the servlet is accesed by a link, or by typing the url in the address bar.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the default contentType for a response is text/html.
This is not necessary and does not affect your code if you do not have it but it will be helpful while reviewing your code if you set different response contentTypes through out your application e.g. text/xml, etc.
Thank you,
Maneesh
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by maneesh subherwal:
the default contentType for a response is text/html.
This is not necessary and does not affect your code if you do not have it but it will be helpful while reviewing your code if you set different response contentTypes through out your application e.g. text/xml, etc.
Thank you,
Maneesh


i am not sure how setContentType will be helpful while reviewing code if it does not matter setContentType is set or not. can you please clarify this in a bit detail?
thanks.
 
maneesh subherwal
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that setting the content-type is only unnecessary in the case where html is expected to be displayed since the default is text/html. it is necessary in other cases, such as image/gif, etc.
The setContentType method sets the MIME type (Multipurpose Internet Mail Extensions) of the response. Many MIME types currently exist other than the ones mentioned here.
While reviewing code and for developers who are unsure of what the default content type is, it is good to explicitly set it in the code even if the response is in text/html.
I hope this helps...
Thank you,
Maneesh
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic