0% found this document useful (0 votes)
2 views6 pages

JavaEE Servlet Intro Presentation

A servlet is a Java class that processes HTTP requests on the server side and generates dynamic responses. It is distinct from JSP, which focuses on the presentation layer, with servlets handling business logic. The servlet lifecycle includes initialization, request handling, and destruction, and typically involves a request flow from JSP to servlet and back to JSP for displaying results.

Uploaded by

ေမဇင္
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

JavaEE Servlet Intro Presentation

A servlet is a Java class that processes HTTP requests on the server side and generates dynamic responses. It is distinct from JSP, which focuses on the presentation layer, with servlets handling business logic. The servlet lifecycle includes initialization, request handling, and destruction, and typically involves a request flow from JSP to servlet and back to JSP for displaying results.

Uploaded by

ေမဇင္
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Introduction to Servlets

Java EE Web Application


Development
What is a Servlet?
• - A Java class that handles HTTP requests
• - Runs on the server side (Java EE container)
• - Generates dynamic responses (HTML, JSON,
etc.)
• - Works with JSP in modern web apps
Servlet vs JSP
• - Servlet: Java code for controlling logic
• - JSP: Presentation layer (HTML with Java)
• - Servlets are better for business logic
• - JSPs are easier for UI and displaying data
Servlet Lifecycle
• 1. init() - Called once when the servlet is
created
• 2. service() - Called for each request
• 3. destroy() - Called once when the servlet is
destroyed
Basic Servlet Example
• @WebServlet("/hello")
• public class HelloServlet extends HttpServlet {
• protected void doGet(HttpServletRequest
req, HttpServletResponse res) throws
IOException {
• res.getWriter().println("Hello from Servlet");
• }
• }
Request Flow: JSP → Servlet → JSP
• - User submits form from JSP
• - Servlet receives request with parameters
• - Servlet sets attributes and forwards to result
JSP
• - JSP reads attributes and displays result

You might also like