10.What happens if the programmer calls destroy () method explicitly from the service () method of servlet program?
Servlet container will not destroy our servlet class but logic of destroy () method executes along with service () method.
When life cycle method is raised .the servlet container calls lifecycle methods. Since the programmer has called lifecycle method manually or explicitly the servlet container never raises the life cycle event.
11.What happens if init () method is called explicitly from the service () method of servlet program?
Servlet container never creates new object for our servlet class for the above call but logic of init () method execute along with service () method.
12.Can we call destroy () method inside the init () method is yes what will happen?
Yes we can call like this but if we have not override this method container will call the default method and nothing will happen. After calling this if any we have override the method then the code written inside is executed.
13.What is the possible case/situation when a Servlet's destroy() method is called,other than the server restart ?
The Servlet engine may call the destroy() method of Servlet when the container encounters the Servlet is changed, a typical case of hot deployment. In that case the container calls the destroy method and then reloads the Servlet's class, reconstructs and then initializes it.
The Servlet engine may call the destroy() method of Servlet when the container encounters the Servlet is changed, a typical case of hot deployment. In that case the container calls the destroy method and then reloads the Servlet's class, reconstructs and then initializes it.
14.What is difference between GET and POST?
GET POST
1. Design to gather data from server by generating 1.Design to send data to the server along Request. With the request.
2. Get sends limited amount of data along with 2.It can send unlimited amount of
data
The request (max of 256 kb) . along with the request.
3. The form page generated query string will appear 3.the form page generated query string will
In browser address bar so no data secrecy. Not appear in browser address bar.
4. Not suitable for file uploading operations. 4. Suitable.
5. Can not send data in encrypted format 5.can send.
6. Use doGet () method or service () method 6.use doPost () method or service () method
To process the request. To process the request.
7. Get is not idempotent. 7. Post is not idempotent.
8. Default request method of httpRequest. 8. Is not default and should be applied
Explicitly.
9.It allows bookmarks. 9.It is not allows bookmarks.
GET
|
POST
|
1. Design to gather data from server by generating
By the request
|
1.Design to send data to the server along With the request.
|
2. Get sends limited amount of data along with
The request (max of 256 kb) .along with the request.
|
2.It can send unlimited amount of data
|
3. The form page generated query string will appear In browser address bar so no data secrecy.
|
3.the form page generated query string will Not appear in browser address bar.
|
4. Not suitable for file uploading operations.
|
4. Suitable.
|
5. Can not send data in encrypted format
|
5.can send.
|
6. Use doGet () method or service () method To process the request
|
6.use doPost () method or service () method To process the request.
|
7. Get is not idempotent.
|
7. Post is not idempotent.
|
8. Default request method of httpRequest.
|
8. Is not default and should be applied Explicitly.
|
9.It allows bookmarks.
|
9.It is not allows bookmarks.
|
When request is submitted from form before completion of the request processing , if another request comes from same form and same browser window logic placed in doGet() method executes two times this behavior is called Idempotent Behavior. Idempotent Behavior means allowing double submission and this is a bad behavior and it has to be prevented. So better not to keep sensitive business logic like Credit Cards processing and other database operations in doGet () method. DoPost () method is not idempotent so it does not allows double submit ions. So it is recommended to place sensitive business logic in doPost () method.
14.When should you prefer to use doGet() over doPost()?
GET is preferred over POST in most of the situations except for the following:
When the data is sensitive.
When the data is greater than 1024 characters
When the data is greater than 1024 characters
15.How can we create deadlock condition on our servlet?
One simple way to call doPost() method inside doGet() and doGet()method inside doPost() it will create deadlock situation for a servlet.
17.What happens when you have no doGet or doPost method in your Servlet class ?
All Servelts must extends the HttpServletclass.When a request comes the service method of the HttpServlet class is invoked by the container,the service method in turn calls the doGet or doPost method of the user specified Servlet class,If we don't override the doGet or doPostmethod,the default implementation doGet() and doPost() method is executed defined in the HttpServletclass.Which tells "HTTP Status 405 - HTTP method GET/POSt is not supported by this URL". A typical example of dynamic method dispatch.
All Servelts must extends the HttpServletclass.When a request comes the service method of the HttpServlet class is invoked by the container,the service method in turn calls the doGet or doPost method of the user specified Servlet class,If we don't override the doGet or doPostmethod,the default implementation doGet() and doPost() method is executed defined in the HttpServletclass.Which tells "HTTP Status 405 - HTTP method GET/POSt is not supported by this URL". A typical example of dynamic method dispatch.
No comments:
Post a Comment