Skip to content
Unit 5 Syllabus Note· Web Technologies

Web Technologies

Comprehensive exam revision notes for BCA-303N Unit 5 (JavaServer Pages (JSP) & JavaBean Architecture). Includes Section A (2M), Section B (5M), and Section C (15M) questions, answers, and diagrams.

Web Technologies

JavaServer Pages (JSP) & JavaBean Architecture

Core Definitions & Key Concepts

What is JavaServer Pages (JSP) and how does it relate to Servlets

JSP is a server-side presentation technology that allows developers to write standard HTML embedded with dynamic Java tags. At runtime, the JSP engine translates the JSP file into an equivalent Java Servlet source file (`.java`), which is then compiled into bytecode (.class).

The JSP Lifecycle phases

  1. Translation: JSP page is translated into a Java Servlet source file (_jsp.java).
  2. Compilation: Servlet source is compiled into bytecode (_jsp.class).
  3. Loading & Instantiation: Servlet class is loaded into memory.
  4. Initialization: jspInit() is invoked once.
  5. Execution: _jspService(req, res) is called for each client request.
  6. Destruction: jspDestroy() cleans up resources when unloaded.

Name the three types of JSP Directives

  1. <%@ page ... %>: Defines page-dependent attributes (language, contentType, import, errorPage).
  2. <%@ include ... %>: Static include of another file at translation time.
  3. <%@ taglib ... %>: Declares custom tag libraries (such as JSTL).

What are the three core JSP Scripting Elements

  1. Scriptlet (`<% ... %>`): Arbitrary Java statements executed inside _jspService().
  2. Expression (`<%= ... %>`): Evaluates an expression and prints to output (no semicolon).
  3. Declaration (`<%! ... %>`): Declares class-level instance variables and methods outside _jspService().

List the 9 Implicit Objects in JSP

  1. request (HttpServletRequest)
  2. response (HttpServletResponse)
  3. out (JspWriter)
  4. session (HttpSession)
  5. application (ServletContext)
  6. config (ServletConfig)
  7. pageContext (PageContext)
  8. page (Object / this)
  9. exception (Throwable - only on error pages).

What constitutes a valid JavaBean class

  1. Must implement java.io.Serializable.
  2. Must have a public zero-argument constructor.
  3. All properties must be private and accessible via standard public getProp() and setProp() methods.

What are the three standard JSP Action tags for JavaBeans

  1. <jsp:useBean id="..." class="..." scope="..."/>: Locates or instantiates a bean.
  2. <jsp:setProperty name="..." property="..."/>: Sets property value.
  3. <jsp:getProperty name="..." property="..."/>: Retrieves property value and writes to output.

The four scopes in JSP

  1. `page`: Accessible only within the current JSP page.
  2. `request`: Accessible across pages handling the same request (forward).
  3. `session`: Accessible across multiple requests within the user's active session.
  4. `application`: Accessible to all users across the entire web application.

What is the JSP Expression Language (EL) syntax and purpose

EL uses the syntax ${expression} (e.g., ${student.name}) to access JavaBean properties, implicit objects, and collection elements simply and cleanly without requiring Java scriptlets.

What is JSTL (JSP Standard Tag Library)

JSTL is a standardized collection of custom JSP tags providing core functions (loops <c:forEach>, conditionals <c:if>), XML processing, formatting (dates/numbers), and SQL access.

Conceptual & Architectural Analysis

The Translation and Compilation Lifecycle of a JSP Page

System Architecture / Concept DiagramHorizontal Scroll Enabled
[ Client Request: index.jsp ]
          |
          v
[ JSP Engine / Container ]
          |
          +---> Checks: Is Translated Servlet up to date?
          |     If NO:
          |     1. [ Translation Phase ]: Translates index.jsp -> index_jsp.java
          |     2. [ Compilation Phase ]: Compiles index_jsp.java -> index_jsp.class
          |
          v
[ Load & Initialize ]
          |
          +---> jspInit() (Executed once)
          |
          v
[ Request Handling ]
          |
          +---> _jspService(request, response) (Invoked for every request)
          |
          v
[ Container Shutdown ]
          |
          +---> jspDestroy() (Executed once)

Compare JSP Scripting Elements: Scriptlet vs Expression vs Declaration

ElementSyntaxGenerated Location in ServletExample
Scriptlet<% ... %>Inside _jspService() method<% int count = 10; %>
Expression<%= ... %>Inside _jspService() wrapped in out.print(...)<%= Math.sqrt(16) %>
Declaration<%! ... %>Outside _jspService() as Class Member<%! private int visits = 0; %>

JSP Directive Tags (page, include, taglib) with Attributes

1. Page Directive (<%@ page ... %>):

Configures page-wide attributes:

JSP
1<%@ page language="java" contentType="text/html; charset=UTF-8"
2 import="java.util.List, com.mjpru.Student"
3 isErrorPage="false" errorPage="error.jsp" session="true" %>

2. Include Directive (<%@ include file="header.jsp" %>):

Merges target file into current page during translation (static include).

3. Taglib Directive (<%@ taglib uri="..." prefix="c" %>):

Imports tag libraries such as JSTL core (xmlns:c).

The 4 Scopes of <jsp:useBean> with Lifespan Comparison

ScopeLifespanStored InShared With
`page`Duration of single JSP page executionPageContextCurrent page only
`request`Lifetime of the HTTP requestHttpServletRequestCurrent page and forwarded JSPs
`session`User session duration (browser session)HttpSessionAll pages visited by same user
`application`Server uptime (application lifetime)ServletContextAll users across entire web app

JSTL Core Tags (<c:if>, <c:forEach>, <c:choose>) with Examples

System Architecture / Concept DiagramHorizontal Scroll Enabled
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!-- Conditional Rendering -->
<c:if test="${score >= 50}">
  <p style="color:green;">Status: Passed</p>
</c:if>

<!-- Multi-way Branching -->
<c:choose>
  <c:when test="${marks >= 75}"><p>Distinction</p></c:when>
  <c:when test="${marks >= 60}"><p>First Class</p></c:when>
  <c:otherwise><p>Second Class / Pass</p></c:otherwise>
</c:choose>

<!-- Iteration over Collections -->
<c:forEach var="item" items="${productList}">
  <li>${item.name} - &#8377;${item.price}</li>
</c:forEach>

In-Depth Analysis & Implementation

Develop a Complete Enterprise JavaBean and JSP Application Demonstrating <jsp:useBean>, Property Population, and EL Rendering

Complete JavaBean and JSP Implementation

1. JavaBean Class: StudentBean.java

Java
1package com.mjpru.bca.beans;
2
3import java.io.Serializable;
4
5public class StudentBean implements Serializable {
6 private static final long serialVersionUID = 1L;
7 private int rollNo;
8 private String studentName;
9 private double marks;
10
11 public StudentBean() {} // Mandatory no-arg constructor
12
13 public int getRollNo() { return rollNo; }
14 public void setRollNo(int rollNo) { this.rollNo = rollNo; }
15
16 public String getStudentName() { return studentName; }
17 public void setStudentName(String studentName) { this.studentName = studentName; }
18
19 public double getMarks() { return marks; }
20 public void setMarks(double marks) { this.marks = marks; }
21
22 public String getGrade() {
23 if (marks >= 80) return "A+";
24 if (marks >= 60) return "A";
25 if (marks >= 50) return "B";
26 return "C";
27 }
28}

2. JSP Page: student_entry.jsp (Input Form)

JSP
1<!DOCTYPE html>
2<html>
3<head><title>Student Registration</title></head>
4<body>
5 <h2>Enter BCA Student Details</h2>
6 <form action="student_display.jsp" method="POST">
7 Roll Number: <input type="text" name="rollNo"><br><br>
8 Student Name: <input type="text" name="studentName"><br><br>
9 Marks (out of 100): <input type="text" name="marks"><br><br>
10 <input type="submit" value="Register Student">
11 </form>
12</body>
13</html>

3. JSP Page: student_display.jsp (Processing & Display via Bean & EL)

System Architecture / Concept DiagramHorizontal Scroll Enabled
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!-- 1. Instantiate or Locate JavaBean in Request Scope -->
<jsp:useBean id="student" class="com.mjpru.bca.beans.StudentBean" scope="request"/>

<!-- 2. Automatically populate all bean properties matching HTTP POST parameter names -->
<jsp:setProperty name="student" property="*"/>

<!DOCTYPE html>
<html>
<head>
  <title>Student Profile Display</title>
  <style>
    .profile-card { border: 1px solid #0284c7; padding: 20px; border-radius: 8px; max-width: 400px; }
  </style>
</head>
<body>
  <div class="profile-card">
    <h2>Student Examination Record</h2>
    <!-- Render properties using modern Expression Language (EL) -->
    <p><strong>Roll Number:</strong> ${student.rollNo}</p>
    <p><strong>Student Name:</strong> ${student.studentName}</p>
    <p><strong>Marks:</strong> ${student.marks} / 100</p>
    <p><strong>Assigned Grade:</strong> <span style="color:blue;">${student.grade}</span></p>
  </div>
</body>
</html>

Error Handling in JSP: errorPage and isErrorPage Directives with Custom Error Handler Architecture

Declarative Error Handling in JSP

System Architecture / Concept DiagramHorizontal Scroll Enabled
[ Business JSP (calculate.jsp) ] -- Throws Runtime Exception --> [ Container ]
                                                                       |
                                                                       v
[ Client Browser ] <--- Renders User-Friendly Message <--- [ error_handler.jsp ]

1. Business Page (calculate.jsp):

Specifies the error handling page via the page directive:

JSP
1<%@ page errorPage="error_handler.jsp" %>
2<%
3 int a = 100;
4 int b = 0;
5 int c = a / b; // Causes java.lang.ArithmeticException: / by zero
6%>

2. Custom Error Handler Page (error_handler.jsp):

Must declare isErrorPage="true", which enables access to the implicit exception object:

JSP
1<%@ page isErrorPage="true" contentType="text/html; charset=UTF-8" %>
2<!DOCTYPE html>
3<html>
4<head><title>System Error Occurred</title></head>
5<body style="font-family:sans-serif; background:#fff1f2;">
6 <h2 style="color:#e11d48;">Application Error</h2>
7 <p>We apologize for the inconvenience. Our engineering team has been notified.</p>
8 <div style="background:#fff; border:1px solid #fecdd3; padding:15px; border-radius:6px;">
9 <p><strong>Exception Type:</strong> <%= exception.getClass().getName() %></p>
10 <p><strong>Error Message:</strong> <%= exception.getMessage() %></p>
11 </div>
12</body>
13</html>

Compare Static Include (<%@ include %>) vs Dynamic Include (<jsp:include>) with Architectural Trade-offs

Static Include vs Dynamic Include

CriteriaStatic Include (<%@ include file="..." %>)Dynamic Include (<jsp:include page="..." />)
Execution PhaseTranslation Phase (Source file level)Runtime / Request Phase (Invocation level)
MechanismCopies raw source code text of child into parent file before compilationIntercepts at runtime via RequestDispatcher.include()
Output ServletsProduces a single translated Servlet classProduces two separate independent Servlet classes
Dynamic ParametersCannot pass parameters (<jsp:param> invalid)Can pass runtime parameters via <jsp:param>
File ChangesModification in included file may not recompile parent automaticallyChanges in child page reflect immediately on next request
Best Used ForStatic copyright banners, common HTML headersDynamic user profile widgets, navigation bars with active state

Important Exam Points & Quick Revision

Examiner high-yield focus: JSP Lifecycle (guaranteed 10 marks), 9 Implicit objects table, and Static vs Dynamic include comparison.

Your reading progress
0%

100% left on this page — finishing it closes the gap for JavaServer Pages (JSP) & JavaBean Architecture.

Weak topic hint

JavaServer Pages (JSP) & JavaBean Architecture still counts as a weak topic until you finish this note and answer its questions.

Practise this unit
What Should You Do Next?

Test Your Understanding

Now that you've read through these notes, practice unit MCQs to identify weak points and solidify your learning before exams.