Servlets Flashcards
What is a servlet?
- A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model.
What is J2EE?
- J2EE stands for Java Platform Enterprise Edition. It is a collection of Java APIs used to write server-side applications.
What is the Lifecycle of a Servlet?
1) Servlet class is loaded
2) Servlet instance is created
3) Init method is invoked
4) Service method is invoked
5) Destroy method is invoked
App Server vs Web Server
- A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.
What is XML?
- Stands for Extensible Markup Language
- It defines set of rules for encoding documents in a format that is both human-readable and machine readable
What is JAXB?
- Stands for Java Architecture for XML Binding
- It is used to convert Java Object to XML and XML to Java Objects.
What is Marshalling?
- The process of transforming the memory representation of an object to a data format suitable for storage or transmission.
What is Unmarshalling?
- The process of transforming a representation of an object that was used for
storage or transmission to a representation of the object that is executable.
What is MVC?
- Represents Model, View, Controller.
MVC is an architectural pattern that separates an application into three main
components:
- Model - all data related logic.
- View - all UI related logic.
- Controller - handles all business logic and incoming requests.
What is the deployment descriptor?
- In J2EE, a deployment descriptor describes how a component should be deployed.
- An example of a “deployment descriptor” is the web.xml.
What are the important tags you need to include in the web.xml?
- web-app
- servlet, servlet-name, servlet-class
- servlet-mapping, servlet-name, url-pattern
- init-param, param-name, param-value
- context-param, param-name, param-value
Eager Loading vs Lazy Loading
- Lazy loading - a servlet is not loaded when server is starting and loaded only when the servlet receives a request.
- Eager Loading - servlet loads while server is starting.
URL vs URI vs URN
- URL (Uniform Resource Locator) - identifies the location of the resource and how to access it.
- URI (Uniform Resource Identifier) - identifies a resource by name, location, or both.
- URN (Uniform Resource Name) - identifies a resource by name in a given
namespace but does not specify how to obtain it.
What are the method signatures of doGet() and doPost()?
- Protected void doGet(HttpServletRequest req, HttpServletResponse res) extends
IOException, ServletException. - Protected void doPost(HttpServletRequest req, HttpServletResponse res) extends
IOException, ServletException.
Init, Service and Destroy, how many times do they execute?
- The init and destroy method is called once.
- The service method is called for every request the servlet receives.