• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubts on the init() and constructors()

 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1. why do we need init() method when we can do the things in the constructors it self. I am having confusion in this?
Q2. why doGet() method should not change the data on the server and doPost() can do it?

Thanks in advance.

Nitin
 
Vassili Vladimir
Ranch Hand
Posts: 1585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

As a reply for your first question, when the constructor runs, the Servlets class just becomes a Java object, but not a Servlet yet, to get its Servlet-ness, its init() method has to run, so you can get access to the Servlet Config and Servlet Context objects.

And as a reply for your second question, all HTTP methods are idempotent except POST, and by idempotent its meant without side effects or negative consequences on the server side. Actually you can write code that makes the doGet() method not idempotent, but it's better to use the doPost() method to do so.

I hope that everything is clear now ...

Best of luck ...
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.. i got it clear.. thanks for clearing the doubts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic