U5) Servlet and JSP Flashcards

(14 cards)

1
Q

What is a Servlet?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the architecture of a web application?

A

It follows a 3-tier model: Client (Browser),
Web Server (Servlet/JSP), and Database Server.

The Servlet runs in the middle layer (server-side).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the HTTP protocol?

A

Rules for data exchange between browser and server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are common HTTP methods?

A

GET: Request data,
POST: Send data,
PUT: Update data,
DELETE: Remove data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between a Web Server and a Web Container?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the main Servlet interfaces?

A

Servlet (base interface),

GenericServlet (abstract class for protocol-independent Servlets),

HttpServlet (handles HTTP-specific requests).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the stages of the Servlet life cycle?

A
  1. Initialization (init()): Called once when servlet loads.
  2. Request (service()): Called for every request. 3. Destroy (destroy()): Called before unloading servlet.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between ServletConfig and ServletContext?

A

ServletConfig is per servlet and holds config parameters,

while ServletContext is application-wide and shared across servlets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does Servlet communicate with a Browser?

A

Using sendError(code), setHeader(name, value), and sendRedirect(“url”).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do Servlets communicate with each other?

A

Using forward() to pass requests and include() to include responses from another servlet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a Session Object?

A

Server-side storage of user data.

Example:
HttpSession session = request.getSession(); session.setAttribute
(“name”,”King”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are Cookies?

A

Small text files stored on the client side.

Example: Cookie c = new Cookie(“user”, “King”); response.addCookie(c);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is URL Rewriting?

A

Appending session data in the URL.

Example: /product.jsp?user=King

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are Hidden Form Fields?

A

Data passed in HTML <input></input> fields.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly