JSP Expression Language (EL) is useful and is evaluated in JSP pages by default since Servlet 2.4. However, sometimes we would not want to evaluate EL, e.g. keep everything in the pattern ${..} looks as it is. In JSP, it’s possible to deactivate EL evaluation for a single JSP page for a group of JSPs.

 

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}

Set isELIgnored=”false” (or remove this attribute) to enable EL evaluation again, for example:

<%@ 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:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment