Deactivate EL on JSP with example

Deactivate EL on JSP with example

JSP (JavaServer Pages), Expression Language (EL) is enabled by default to allow for easy access to data stored in JavaBeans components, various objects in the request, session, and application scopes. However, there might be situations where you want to deactivate EL, such as when you need to display content that includes EL syntax without it being evaluated.

To deactivate EL in a JSP page, you can use the isELIgnored attribute of the <%@ page %> directive. Setting this attribute to true will disable EL evaluation for that particular JSP page.

 JSP with example

Example in JSP

Here’s a simple example demonstrating how to deactivate EL in a JSP page:

Example

jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="true"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Deactivate EL Example</title>
</head>
<body>
    <h1>Expression Language (EL) Deactivation Example</h1>
    
    <!-- EL is deactivated, so ${message} will not be evaluated -->
    <p>Message: ${message}</p>
</body>
</html>

Explanation of JSP with example

  1. Page Directive:  The <%@ page %> directive at the top of the JSP page includes the isELIgnored=”true” attribute. This attribute tells the JSP engine to ignore EL expressions on this page.
  2. EL Syntax:  The EL expression ${message} will be displayed as plain text and not evaluated because EL is deactivated.

Homepage

Readmore