>> Wednesday, June 15, 2011
What is Servlets and explain the advantages of Servlet life cycle?
AnswerServlets are the programs that run under web server environment. A copy of Servlet class can handle numerous request threads. In servlets, JVM stays running and handles each request using a light weight thread.
Servlets life cycle involve three important methods, i.e. init, service and destroy.
Init()
Init method is called when Servlet first loaded in to the web server memory.
Service()
Once initialized, Servlets stays in memory to process requests. Servlets read the data provided in the request in the service() method.
Destroy()
When server unloads servlets, destroy() method is called to clean up resources the servlet is consuming.
What are different Authentication options available in Servlets.
AnswerThere are four ways of Authentication options available in servlets
HTTP basic authentication
In this, server uses the username and password provided by the client and these credentials are transmitted using simple base64 encoding.
HTTP digest authentication
This option is same the basic authentication except the password is encrypted and transmitted using SHA or MD5.
HTTPS client authentication
This options is based on HTTP over SSL.
Form-based authentication
Form-based authentication uses login page to collect username and password.
Explain why HttpServlet is declared abstract.
AnswerThe Constructor HttpServlet() does nothing because this is an abstract class. Default implementations in a few Java classes like HttpServlet don’t really do anything. Hence, they need to be overridden.
Usually one of the following methods of HttpServlet must be overridden by a subclass:
doGet, if the servlet supports HTTP GET requests
doPost, HTTP POST requests
doPut, HTTP PUT requests
doDelete, HTTP DELETE requests
init and destroy, to manage resources
getServletInfo, to provide information
However, there doesn’t seem to be any reason why the service method should be overridden because it eventually dispatches the task to one of the doXXX methods.
What is the GenericServlet class?
AnswerGenericServlet makes writing servlets easier. To write a generic servlet, all you need to do is to override the abstract service method.
What is the difference between an Applet and a Servlet?
AnswerApplets
- Applets are applications designed to be transmitted over the network and executed by Java compatible web browsers.
- An Applet is a client side java program that runs within a Web browser on the client machine.
- An applet can use the user interface classes like AWT or Swing.
- Applet Life Cycle Methods: init(), stop(), paint(), start(), destroy()
- Servlets are Java based analog to CGI programs, implemented by means of servlet container associated with an HTTP server.
- Servlet is a server side component which runs on the web server.
- The servlet does not have a user interface.
- Servlet Methods: doGet(), doPost()
0 comments:
Post a Comment