I am trying to access static fields presents in my java file from my JSP using EL in Tomcat 8 container but getting error (shown below).
Does Tomcat8 supports EL 3.0? If yes, then what am I missing?
AppConstants.java
package com.study.el;
public final class AppConstants {
public static final String NAME = "abc";
private AppConstants() {
}
}
AppContextListener.java
package com.study.el;
@WebListener
public class AppContextListener implements ServletContextListener {
private ServletContext appContext;
@Override
public void contextInitialized(ServletContextEvent event) {
JspFactory.getDefaultFactory().getJspApplicationContext(event.getServletContext()).addELContextListener(new ELContextListener() {
@Override
public void contextCreated(ELContextEvent event) {
event.getELContext().getImportHandler().importClass("com.study.el.AppConstants");
}
});
}
@Override
public void contextDestroyed(ServletContextEvent contextEvent) {
//nothing to implement
}
}
index.jsp
<!DOCTYPE html>
<html>
<head>
<title>Start Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>Hello World!</h1>
<h1>Hello ${AppConstants.NAME}</h1>
</body>
</html>
Error Log:
javax.el.ELException: The class [com.study.el.AppConstants] could not be imported as it could not be found
javax.el.ImportHandler.importClass(ImportHandler.java:114)