Activating and Deactivating EL evaluation in JSP
- Details
- Written by Nam Ha Minh
- Last Updated on 21 July 2019   |   Print Email
1. Default EL Evaluation Mode
EL evaluation is enabled by default if the Servlet version specified in the web deployment descriptor file (web.xml) is 2.4 or later, for example:<web-app xmlns:xsi=….. version=”3.0”>
And EL expressions are ignored if the Servlet version is 2.3 or lower:<web-app xmlns:xsi=….. version=”2.3”>
Today the latest version of Servlet is 3.0, so it’s likely that every Java web application has EL evaluation enabled by default.2. Deactivating EL evaluation for a single JSP page
We can deactivate EL evaluation in a single JSP page by specifying the attribute isELIgnored=”true” in the page directive as follows:<%@ page isELIgnored="true" %>
For example, following JSP page disables EL evaluation:<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Deactivate EL Demo</title> </head> <body> EL expression result is: ${2 * 4 + 3 * 4} </body> </html>Output:
EL expression result is: ${2 * 4 + 3 * 4}
<%@ page isELIgnored="false" %>
Output of the above JSP page:EL expression result is: 20
3. Deactivating EL evaluation for a group of JSP pages
Add the following code block into the web.xml file to deactivate EL evaluation for all JSP pages that have .jsp extension in the application:<jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <el-ignored>true</el-ignored> </jsp-property-group> </jsp-config>And to activate EL evaluation for all .jsp pages:
<jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <el-ignored>false</el-ignored> </jsp-property-group> </jsp-config>What if a JSP page specifies attribute isELIgnored already? Then the isELIgnored attribute will override setting in the web.xml file.
Other JSP Tutorials:
- Summary of EL operators with examples
- Java Servlet and JSP Hello World Tutorial with Eclipse, Maven and Apache Tomcat
- How to handle exceptions in JSP
- How to list records in a database table using JSP and JSTL
- How to create dynamic drop down list in JSP from database
- Sending e-mail with JSP, Servlet and JavaMail
Comments