U5) Servlet and JSP Flashcards
(14 cards)
What is a Servlet?
A Java class that handles HTTP requests in a web app and runs on a web server (e.g., Tomcat).
It is used to create dynamic web content.
What is the architecture of a web application?
It follows a 3-tier model: Client (Browser),
Web Server (Servlet/JSP), and Database Server.
The Servlet runs in the middle layer (server-side).
What is the HTTP protocol?
Rules for data exchange between browser and server.
What are common HTTP methods?
GET: Request data,
POST: Send data,
PUT: Update data,
DELETE: Remove data.
What is the difference between a Web Server and a Web Container?
A Web Server handles static content (HTML, CSS),
while a Web Container executes Servlets and JSP (e.g., Tomcat) and provides Servlet life cycle management.
What are the main Servlet interfaces?
Servlet (base interface),
GenericServlet (abstract class for protocol-independent Servlets),
HttpServlet (handles HTTP-specific requests).
What are the stages of the Servlet life cycle?
- Initialization (init()): Called once when servlet loads.
- Request (service()): Called for every request. 3. Destroy (destroy()): Called before unloading servlet.
What is the difference between ServletConfig and ServletContext?
ServletConfig is per servlet and holds config parameters,
while ServletContext is application-wide and shared across servlets.
How does Servlet communicate with a Browser?
Using sendError(code), setHeader(name, value), and sendRedirect(“url”).
How do Servlets communicate with each other?
Using forward() to pass requests and include() to include responses from another servlet.
What is a Session Object?
Server-side storage of user data.
Example:
HttpSession session = request.getSession(); session.setAttribute
(“name”,”King”);
What are Cookies?
Small text files stored on the client side.
Example: Cookie c = new Cookie(“user”, “King”); response.addCookie(c);
What is URL Rewriting?
Appending session data in the URL.
Example: /product.jsp?user=King
What are Hidden Form Fields?
Data passed in HTML <input></input> fields.