0

I'm using Weblogic 12c, the webapp is of servlet version 3.1.

I struggle how to evaluate static fields by EL.

Java Class:

package com.example;

public class MyClass {
  public static final String MY_CONSTANT = "ABC";
}

JSP:

<%@ page import="com.example.MyClass" %>
<h1>Servlet Version: <%=pageContext.getServletContext().getEffectiveMajorVersion()%>.<%=pageContext.getServletContext().getEffectiveMinorVersion()%></h1>
<h1>Scriptlet: <%=MyClass.MY_CONSTANT%></h1>
<h1>EL Expression: ${MyClass.MY_CONSTANT}</h1>
<h1>Boolean.TRUE: ${Boolean.TRUE}</h1>

Result:

Servlet Version: 3.1
Scriptlet: ABC
EL Expression: 
Boolean.TRUE: true

The expression ${MyClass.MY_CONSTANT} is evaluated to empty.

According to this answer, static fields can be evaluated by EL 3.0. And EL 3.0 is supported by servlet version 3.1 AFAIK.

So why can't I access the static field using EL?

Abid
  • 403
  • 4
  • 10
  • 1
    I've had this problem before. As you say, the servlet version should support it but for some reason it doesn't come through. A workaround is to add the static variable as an attribute in the request in your controller class. – mohammedkhan Jun 02 '22 at 13:04

0 Answers0