Servlets Flashcards
What is a web server?
A Web server is a computer system that processes request by HTTP. This can refer to the hardware of the software that accepts the HTTP request. The web server store, process and deliver web pages to the clients.
What is an application server?
An application server is a software framework that provides both facilities to create web applications and a server environment to run them. The server behaves like an extended virtual machine for running applications, handling connections to the database on one side and often connections to the Web client on the other.
What is the difference between the application server and the web server?
Web server: serves content to the web using http protocol.
Application server: hosts and exposes business logic and processes.
What is a servlet?
A Java servlet is a Java program that extends the capabilities of a server. They are most often used to process or store a Java class in Java EE and are most often used in HTTP protocol. It is an object that receives a request and generates a response based on that request.
How do you deploy a servlet?
The servlet specification defines the element which can be specified in the deployment descriptor to make the servlet container load and initialize the servlet as soon as it starts up.
What is HTTP?
It is Hypertext Transfer Protocol, which is basically structured text.
What is a HTTP Request?
When your computer is on the browser and tries to fetch a file from a web server, it sends a request for some file.
What is a HTTP Response?
The Web Server sends back a response by sending back a file that can be used to display the web page.
What is Web.xml?
It is the configuration file of web application in Java. It instructs the servlet container which classes to load, what parameters to set in the context and how to intercept requests coming from the browsers.
What is HTTP GET
GET is used to retrieve remote data
What is HTTP Post
POST is used to insert/update remote data
Difference between HTTP GET and POST
GET is for retrieving data. It should have no side effects, you should be able to request the same URL over and over harmlessly.
POST is for writing data. It may have side effects. Making multiple identical write requests will likely result in multiple writes. Browsers typically give you warnings about this. POST is not secure. The data is in the body of the request instead of the URL but it is trivially simple to view/edit.
Servlet Class Hierarchy
Servlet Interface
Generic Servlet
HttpServlet
(User created Servlet)
What is the Servlet life cycle?
Init
Service
Destroy
What is the Servlet Init method?
The init() method simply creates or loads some data that will be used throughout the life of the servlet.
public void init() throws ServletException { // Initialization code... }
What is the Servlet Service method?
The service() method is the main method to perform the actual task. The servlet container (i.e. web server) calls the service() method to handle requests coming from the client( browsers) and to write the formatted response back to the client.
public void service(ServletRequest request,
ServletResponse response)
throws ServletException, IOException{
}
What is the servlet destroy method?
This method gives your servlet a chance to close database connections, halt background threads, write cookie lists or hit counts to disk, and perform other such cleanup activities.
public void destroy() { // Finalization code... }
What are the 4 scope in a servlet?
Page
Request
Session
Application
What is the Page scope?
Page: The page scope restricts the scpoe and lifetime of attributes to the same page where it was created.
What is the Request scope?
Request: Request scope start from the moment an HTTP request hits a servlet in our web container and end when the servlet is done with delivering the HTTP response.
What is the Session scope?
Session: A session scope starts when a client (e.g. browser window) establishes connection with our web application till the point where the browser window is closed.