Java Servlet Interview Questions and Answers for Experienced Pdf - 1
What are the life cycle methods of JSP?
Life cycle methods of JSP are
jspInit(): The container calls the jspInit() to initialize the servlet instance. it is called before any other method and is called only once for a servlet instance.
jspService(): The container calls the _jspservice() for each request and it passes the request and the response objects. _jspService() method can’t be overridden.
jspDestroy(): The container calls this when its instance is about to be destroyed. The jspInit() and jspDestroy() methods can be overridden within a JSP page.
What is JSP?
Java Server Pages (JSP) technology is the Java platform technology for delivering dynamic content to web clients in a portable, secure and well defined way. The Java Server Pages specification extends the Java Servlet API to provide web application developers.
What are the types of Servlet?
Java servlet are server side components that provides a powerful mechanism for developing server side of web application.
Earlier CGI was developed to provide server side capabilities to the web applications.
Although CGI played a major role in the explosion of the Internet, its performance, scalability and reusability issues make it less than optimal solutions.
Java Servlets changes all that. Built from ground up using Sun’s write once run anywhere technology java servlets provide excellent framework for server side processing.
There are two types of servlets,
HttpServlet defines the generic or protocol independent servlet. HttpServlet is a subclass of GenericServlet and provides some http specific functionality link doGet and doPost methods.
What are the differences between HttpServlet and GenericServlets?
HttpServlet provides an abstract class to be subclassed to create an HTTP servlet suitable for a website. A subclass of HttpServlet must override at least one method, usually one of these:
doGet, if the servlet supports HTTP GET requests
doPost, for HTTP POST requests
doPut, for HTTP PUT requests
doDelete, for HTTP DELETE requests
init and destroy, to manage resources that are held for the life of the servlet
getServletInfo, which the servlet uses to provide information about itself.
There’s almost no reason to override the service method. Service handles standard HTTP requests by dispatching them to the handler methods for each HTTP request type (the doXXX methods listed above). Likewise, there’s almost no reason to override the doOptions and doTrace methods.
GenericServlet: defines a generic, protocol independent servlet. To write an HTTP servlet for use on the web, extend HttpServlet instead.
GenericServlet implements the Servlet and ServletConfig interfaces. GenericServlet may be directly extended by a servlet, although it’s more common to extend a protocol specific subclass such as HttpServlet.
GenericServlet makes writing servlets easier. It provides simple versions of the lifecycle methods init and destroy and of the methods in the ServletConfig interface. GenericServlet also implements the log method, declared in the ServletContext interface.
To write a generic servlet, you need to only override the abstract service method.
What is session tracking?
HTTP is stateless protocol and it does not maintain the client state. But there exists a mechanism called “session tracking” which helps the server to maintain the state to track the series requests from the same user across period of time.
- Java Servlets and JSP Interview Questions and Answers
- Java Servlet Interview Questions for Freshers Pdf
- Java Servlet Interview Questions and Answers for Experienced Pdf
- Top 150+ Java Servlet Interview Questions and Answers
- Java Concurrency Interview Questions and Answers
- Advanced Java Interview Questions and Answers
- Tricky Servlet Interview Questions and Answers
- 150+ Advanced Java Servlet API Interview Questions 2020-2021
1000+ Hydraulic Machines Multiple Choice Questions and Answers Pdf More
1000+ Hydraulic Machines Objective Questions and Answers Pdf More
1000+ Hydraulics MCQ, Objective Questions and Answers Pdf More
Railway Interview Questions and Answers Pdf More
Top 1000+ Indian Railway MCQ Questions & Answers More
Mathematical Operations Reasoning Examples, Tips and Tricks More
Computer Science Data Representation Quiz Questions & Answers More
History and Culture GK Questions and Answers More
10+ Arithmetic Reasoning Questions for Bank Exams More
Compiler Design Multiple Choice Questions and Answers More