Search code examples
jspservletsel

How to evaluate EL expression in Tomcat servlet environment?


How to evaluate EL expression in Tomcat servlet?

Tomcat uses Jasper EL.

https://mvnrepository.com/artifact/org.apache.tomcat/tomcat-jasper-el

https://tomcat.apache.org/tomcat-9.0-doc/api/org/apache/jasper/el/package-summary.html

From the javadoc, it does not have ExpressionFactory impl to construct an ELContext object.

ELContext elContext = new ELContextImpl(expressionFactoryImpl);

Any examples on how to evaluate EL in Tomcat servlet?


Solution

  • The first link is for tomcat-jasper-el artifact which has a dependency on tomcat-el-api. This EL API can be used for evaluating EL expressions in Java servlets:

    EL in Stand-alone environment EL 3.0 includes APIs for using EL in a stand-alone environment.

    ELProcessor provides simple APIs for the direct evaluations of expressions. It also makes it easy to define functions, set variables, and define a beans locally.

    ELManager provides a lower level APIs for managing the EL parsing and evaluation environment. It contains a default ELContext StandardELContext.

    The examples you are looking is using old version of javax.el.