UPDATE:
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.9lib 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}
as:
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:
@WebListener
public class Config implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent event) {
JspFactory.getDefaultFactory().getJspApplicationContext(event.getServletContext()).addELContextListener((ELContextEvent e) -> {
e.getELContext().getImportHandler().importPackage("java.time");
});
}
@Override
public void contextDestroyed(ServletContextEvent event) {}
}
And now from the jsp, to return the current LocalDate, for example:
${LocalDate.now()}
Note that ${java.time.LocalDate.now()}
does not work.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…