JSP Basics and Core Java EE Technologies

JSP Lecture Outline

(I) Introduction to the Thirteen Core Technologies of Java EE

Java EE is an open platform that encompasses a wide range of technologies, including thirteen core technologies. In a project, not all thirteen technologies are necessarily used; rather, they are selectively applied. In other words, a programmer does not need to master all thirteen technologies to engage in Java EE development. However, the essential technologies to master are Java, Servlet, and JSP.

(II) The Path to Becoming a Proficient Java EE Programmer

(This section content is not provided in the original article; it is listed in the outline but not expanded upon.)

(III) Demonstration of a JSP-based User Management System

During the process of learning JSP technology, we will transform the previously built Servlet-based user management system into a JSP-based one. In this system, only JSP technology will be used (Model1 development model). Later, by rewriting this JSP-based user management system, we can natural transition to the Model 2 (MVC) design pattern, and then further to the full MVC design pattern.

The development tools used will be: Eclipse + MyEclipse.

(IV) Overview of JSP

1. Why was JSP Technology Created?

Programmers found that using Servlets to build user interfaces was cumbersome and not ideal. Hence, JSP was introduced.

JSP = HTML + Java snippets + JSP tags + JavaScript/CSS.

JSP's power comes from its ability to work with JavaBeans (i.e., JSP for the front end, JavaBeans for the back end). Combining JSP + JavaBeans with Servlets forms the MVC development pattern. MVC is a widely adopted development model in software companies today.

2. Basic JSP Syntax

a) Directive Elements

Directive elements send information from the JSP to the container, such as setting global variables, character encoding, importing packages, etc.

<%-- Page directive --%>
<%@page contentType="text/html;charset=UTF-8" %>

<%-- Include directive --%>
<%@include file="filename.jsp" %>

<%-- Taglib directive -- allows custom tags in the JSP page --%>
<%@taglib prefix="myTag" uri="http://example.com/tags" %>
b) Script Elements

Script element are essentially Java code snippets (scriptlets).

<%-- Scriptlet: Java code block --%>
<%
    String name = request.getParameter("name");
    if (name != null) {
        out.println("Hello, " + name);
    }
%>

<%-- Expression: outputs a Java expression value --%>
<%= new java.util.Date() %>
<%= resultSet.getString(1) %>

<%-- Declaration: declares variables or methods --%>
<%! 
    private int counter = 10;
    
    public int calculateSum(int num) {
        int sum = 0;
        for (int i = 0; i < num; i++) {
            sum += i;
        }
        return sum;
    }
%>
c) Action Elements

Action elements use XML syntax and are standard actions predefined by JSP. When the container processes the JSP and encounters an action element, it performs a corresponding operation.

Action Element Purpose
<jsp:useBean> Creates a new JavaBean instance
<jsp:setProperty> Sets property values for a JavaBean
<jsp:param> Provides parameters, often used with <jsp:include>
<jsp:getProperty> Retrieves a property value from a JavaBean
<jsp:include> Includes another file at request time
<jsp:forward> Forwards the request to another resource
<jsp:plugin> Embeds a plugin (e.g., applet)
<jsp:fallback> Provides fallback content for plugins

Example of <jsp:include> with parameters:

<jsp:include page="info.jsp">
    <jsp:param name="param1" value="value1" />
    <jsp:param name="param2" value="value2" />
</jsp:include>
d) Nine Implicit (Built-in) Objects in JSP
Object Description Common Methods
out Outputs data to the client (character stream) out.println(), out.print()
request Represents the HTTP request from the client getParameter(String), getParameterValues(String), setAttribute(String, Object), getAttribute(String), getCookies()
response Encapsulates the responce generated by the JSP addCookie(Cookie), sendRedirect(String)
session Stores user information and tracks user behavior setAttribute(String, Object), getAttribute(String)
application Shared by all users; can be used for a hit counter Methods to set/get attributes
pageContext Represents the context of the JSP page Methods to manage page-scoped attributes
exception Represents a runtime exception (only available in error pages) getMessage()
page Refers to the current JSP instance (rarely used) (Methods of the generated Servlet class)
config Represents the configuration of the JSP's corresponding Servlet getInitParameter(String), getServletContext()

(V) How JSP Works (Runtime Principle)

(This section is mentioned in the outline but not detailed in the provided content.)

(VI) JSP-based Calculator

(Subsection content is not provided; the outline mentions using JavaScript and CSS within JSP.)

Tags: Java EE JSP servlet JavaBeans mvc

Posted on Thu, 17 Sep 2026 16:51:13 +0000 by V