Brice Roncace Brice Roncace - 1 year ago 111
Java Question

Access static property or method in JSP via EL 3.0 (JEE7; Tomcat 8)

I'm using tomcat 8.0.9 (servlet 3.1, jsp 2.3, el 3.0) and trying to access a static property from a jsp page like so:


There is no error, but no output appears in the rendered result. What am I doing wrong?


The answer to this question (marked as duplicate question) claims that since EL 3.0 (JSR-341, part of Java EE 7), it is possible to reference constants for all java.lang.* classes as they are implicitly imported and available like so


This answer is NOT working for me, at least not with tomcat 8.


From Oracle's JEE7 Tutorial ( Referencing Object Properties or Collection Elements)

You can reference a static field or method using the syntax classname.field, as in the following example:


The classname is the name of the class without the package name. By default, all the java.lang packages are imported. You can import other packages, classes, and static fields as needed.

Answer Source


There is a bug in Tomcat's (at least as of 8.0.9) jsp-api.jar. According to the change log, it is fixed in Tomcat version 8.0.15.

As a workaround, in the apache-tomcat-8.0.9\lib folder replace jsp-api.jar with javax.servlet.jsp-api-2.3.2-b01.jar. Refresh the project in eclipse and you will see the output for

     Testing: ${Boolean.TRUE}


    Testing: true

This was identified as a bug in GLASSFISH as well here.

In order to access static fields or methods outside of the java.lang package, those specific packages or classes must be added to the EL context (also discussed by BalusC here).

Here's an example allowing static access to classes in the java.time package for all jsp files in your web application:

public class Config implements ServletContextListener {
  public void contextInitialized(ServletContextEvent event) {
    JspFactory.getDefaultFactory().getJspApplicationContext(event.getServletContext()).addELContextListener((ELContextEvent e) -> {

  public void contextDestroyed(ServletContextEvent event) {}

And now from the jsp, to return the current LocalDate, for example:


Note that ${} does not work.