Please tell me the difference that lies between Servlet and a JSP and when to use each of these.Kindly clarify my doubt on this.
Generally speaking use Servlets to process data on the server and use JSPs to present data to the client.
For example, a jsp or html file can contain a <form> object. The action for the form would be a servlet. The servlet would manipulate the data, i.e. store it to a database, etc. The servlet could then gather any additional information, i.e. a database index for the new data, and then based upon success or failure would redirect the client to a jsp which would display the data that was posted along with the index.
JSPs and Servlets, in the long run, perform the same function. The Servlet container will compile your JSP into a servlet for you. For presentation though, JSPs are easier to write as you don't have to explicitly output information into a stream...it's handled for you.
I hope that helped.