Skip to content

Topic 4: Web Component ‐ JSP

Zhamri Che Ani edited this page May 10, 2026 · 2 revisions

Goal

To enable students to develop dynamic web pages using JSP and integrate them with Servlets in an MVC-based web application.

🎯 Learning Objectives

Students should be able to:

  1. Explain the role of JSP in Java web applications
  2. Describe how JSP is processed by the server
  3. Use JSP elements (directives, expressions, scriptlets)
  4. Handle input data using JSP
  5. Forward requests between JSP and Servlet
  6. Integrate JSP as the View component in MVC

📌 Topics to Cover

  1. Introduction to JSP
    • What is JSP
    • JSP lifecycle
  2. JSP Processing
    • Translation to Servlet
    • Compilation and execution
  3. JSP Elements
    • Directives (<%@ %>)
    • Expressions (<%= %>)
    • Scriptlets (<% %>)
  4. Predefined Variables (Implicit Objects)
    • request, response, session, out
  5. Associating Properties with Input Parameters
    • Using form data in JSP
  6. Forwarding Requests
    • RequestDispatcher
    • Forward vs Redirect

🛠️ Hands-on Activity

Activity: Student Registration System (Servlet + JSP Integration)

Students are required to:

  1. Create JSP Page (View)
    • Create result.jsp
    • Display student data using:
Name: ${name}
Email: ${email}
Program: ${program}
  1. Modify Servlet (Controller). In RegisterServlet:
    • Retrieve form data
    • Store data using request attributes:
request.setAttribute("name", name);

Forward to JSP:

RequestDispatcher rd = request.getRequestDispatcher("result.jsp");
rd.forward(request, response);
  1. Display Data in JSP Use JSP expressions or EL:

    • <%= request.getAttribute("name") %>
    • or ${name} (preferred)
  2. Add Navigation Flow

    • Form → Servlet → JSP
    • Show confirmation message:
Registration Successful!
Welcome, Ali!
  1. (Optional Enhancement)
    • Create login.jsp and dashboard.jsp
    • Use session to maintain user login

Expected Output

Students should produce:

  1. JSP page (result.jsp)
  2. Updated Servlet
  3. Working MVC flow:
HTML Form → Servlet → JSP

📚 Suggested Readings

  1. Oracle JSP Documentation https://jakarta.ee/specifications/pages/
  2. JSP Tutorial (W3Schools) https://www.w3schools.in/jsp/tutorials/
  3. JSP Tutorial (tutorialspoint) https://www.tutorialspoint.com/jsp/index.htm
  4. MVC Architecture in Java Web
  5. JSP Expression Language (EL) Guide

Clone this wiki locally