Lecture 32: Revision & Practical (Servlets + JSP)

BMC201 - Web Technology

Mr. Prashant Kumar Nag

2026-03-24

Lecture 32

Revision & Practical (Servlets + JSP)

Week 10 | Unit III: Servlets + JSP
BMC201 - Web Technology
Mr. Prashant Kumar Nag, Assistant Professor

Today: Revision + Practical


We will do a complete flow revision:

  1. Servlet receives request
  2. Business logic + validation
  3. Data sent to JSP via attributes
  4. JSP renders view using EL/JSTL
  5. Session controls login and protected routes

Servlet + JSP Quick Revision


Topic Key Point
Servlet life cycle init, service/doGet/doPost, destroy
Request dispatcher forward keeps same request
Redirect new request from browser
JSP role presentation/view layer
Session user state across requests

MVC Flow for Unit III


flowchart LR
  A[Browser Form Submit] --> B[Servlet Controller]
  B --> C[Validate Inputs]
  C --> D[Set request attributes]
  D --> E[Forward to JSP]
  E --> F[Render HTML Response]

Practical Task Statement


Build a mini Student Portal module:

  • Login servlet validates mock credentials
  • Store logged-in user in session
  • Dashboard JSP greets user and shows enrollment number
  • Logout servlet invalidates session

Servlet Controller Skeleton


String user = request.getParameter("user");
String pass = request.getParameter("pass");

if ("student".equals(user) && "bmc201".equals(pass)) {
  HttpSession session = request.getSession();
  session.setAttribute("loggedInUser", user);
  request.setAttribute("message", "Login successful");
  request.getRequestDispatcher("dashboard.jsp").forward(request, response);
} else {
  response.sendRedirect("login.jsp?error=1");
}

Dashboard JSP Skeleton


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:if test="${empty sessionScope.loggedInUser}">
  <jsp:forward page="login.jsp" />
</c:if>

<h2>Welcome, ${sessionScope.loggedInUser}</h2>

Practical Evaluation Checklist


  • Form submits to correct servlet mapping
  • Input validation handled in servlet
  • Correct use of forward vs redirect
  • Session set on login and removed on logout
  • JSP uses EL/JSTL for display logic
  • No sensitive values printed in response

Debugging Common Errors


Frequent issues in labs:

  • HTTP 404 due to wrong URL mapping
  • NullPointerException from missing request parameter checks
  • Session not found because of direct JSP access
  • JSTL tags not working due to missing taglib declaration/JAR

Exam-Oriented Revision Questions


Prepare short and long answers for:

  1. Servlet life cycle with diagram
  2. Forward vs redirect differences
  3. JSP implicit objects and directives
  4. Session tracking in servlet/JSP applications
  5. MVC approach using servlet controller and JSP view

Summary


  • Unit III is strongest when servlet and JSP responsibilities are separated
  • Session + request attributes are central to app flow
  • Clean JSP with EL/JSTL improves readability and marks
  • Practical implementation confidence comes from full-flow practice

Questions

Thank You

Ready for Week 11: Spring Core.