← New search

Other meanings of JavaServer Pages

Web Development

JavaServer Pages

JavaServer Pages (JSP) is a Java technology for building dynamic web pages by embedding Java code and special tags within HTML or XML documents. It enables developers to create platform-independent, server-side web applications that generate HTML, XML, or other document types in response to client requests. JSP pages are compiled into Java servlets, allowing for separation of presentation and business logic, and they integrate seamlessly with the Java EE ecosystem.

1999
Year introduced
JSP was introduced by Sun Microsystems in 1999 as part of Java 2 Enterprise Edition (J2EE).
JSP 3.1
Latest version
As of 2023, JSP 3.1 is part of Jakarta EE 10, maintained under the Eclipse Foundation.
JSP 2.0
Major revision
JSP 2.0 introduced the Expression Language (EL) and custom tag libraries, simplifying page development.
1

Overview and Architecture

JavaServer Pages is a server-side technology that allows developers to embed Java code directly into HTML pages using special JSP tags, such as <% ... %> for scriptlets and <%= ... %> for expressions. When a client requests a JSP page, the server compiles it into a Java servlet, which then processes the request and generates the response. This compilation happens on the first request, and subsequent requests use the compiled servlet, improving performance. JSP pages can access JavaBeans, Enterprise JavaBeans, and other Java components, enabling robust business logic integration. The technology is part of the Jakarta EE (formerly Java EE) platform, ensuring portability across compliant application servers like Apache Tomcat, GlassFish, and WildFly.

2

Key Features and Standard Tags

JSP provides a set of standard actions and the JSP Standard Tag Library (JSTL) to reduce scriptlet usage. Standard actions include jsp:useBean, jsp:getProperty, and jsp:setProperty for bean manipulation, and jsp:include for including resources. The Expression Language (EL) simplifies data access with syntax like ${user.name}, and JSTL offers tags for iteration, conditionals, and formatting. Custom tag libraries allow developers to encapsulate reusable presentation logic. JSP also supports the JavaServer Pages Standard Tag Library (JSTL) and the Unified Expression Language (UEL), which is shared with JavaServer Faces (JSF). These features promote cleaner code and easier maintenance compared to raw scriptlets.

3

Lifecycle and Execution

The JSP lifecycle involves several phases: translation, compilation, instantiation, initialization, service, and destruction. During translation, the JSP container converts the page into a servlet source file; compilation turns it into a class; instantiation creates the servlet instance; initialization calls the jspInit() method; service handles requests via _jspService(); and destruction calls jspDestroy(). Developers can override jspInit() and jspDestroy() using declaration tags. The container manages these phases, and errors during translation or compilation result in HTTP 500 responses. Understanding this lifecycle is crucial for optimizing performance and managing resources, such as database connections, within JSP pages.

4

Lesser-known aspects

Beyond its mainstream use, JSP has several niche aspects. JSP documents can be written in XML syntax, allowing validation and tooling support. The JSP 2.1 specification introduced the Unified EL, which aligns with JSF. JSP fragments, defined with jsp:fragment, enable reusable page segments. The technology also supports tag files, which are custom tags written as JSP pages, simplifying tag development. Historically, JSP was influenced by Microsoft's ASP, and it competed with PHP and ASP.NET. A lesser-known feature is the ability to use JSP in offline documentation generation, and some frameworks like Spring MVC use JSP as a view technology. Additionally, JSP pages can be precompiled to avoid runtime compilation overhead, a technique used in production deployments.

Glossary

Scriptlet
A block of Java code embedded in a JSP page using <% ... %> tags.
Expression Language (EL)
A simple language for accessing data in JSP pages, using syntax like ${...}.
JSP Standard Tag Library (JSTL)
A collection of custom tags for common tasks like iteration and conditionals.
Servlet
A Java class that handles HTTP requests and generates responses; JSP pages are compiled into servlets.
Tag file
A reusable custom tag defined as a JSP page, with a .tag extension.

JavaServer Pages remains a viable technology for server-side web development, especially in legacy systems and enterprise environments.