From d87465f9e9a802b6ad97fcc9a19d6d4e24c58082 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Wed, 6 Mar 2024 14:31:21 +0100 Subject: [PATCH] Use ELContext instead of VariableResolver in JspPropertyAccessor The JSP VariableResolver API has been deprecated since JSP 2.1 in favor of the newer ELContext API. This commit therefore refactors JspPropertyAccessor to use the ELContext API. Closes gh-32383 --- .../springframework/web/servlet/tags/EvalTag.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java index eca2ad9c38..7ba1e55681 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.web.servlet.tags; import java.io.IOException; +import jakarta.el.ELContext; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; @@ -96,6 +97,7 @@ import org.springframework.web.util.TagUtils; * * @author Keith Donald * @author Juergen Hoeller + * @author Sam Brannen * @since 3.0.1 */ @SuppressWarnings("serial") @@ -212,11 +214,12 @@ public class EvalTag extends HtmlEscapingAwareTag { private final PageContext pageContext; @Nullable - private final jakarta.servlet.jsp.el.VariableResolver variableResolver; + private final ELContext elContext; + public JspPropertyAccessor(PageContext pageContext) { this.pageContext = pageContext; - this.variableResolver = pageContext.getVariableResolver(); + this.elContext = pageContext.getELContext(); } @Override @@ -252,11 +255,11 @@ public class EvalTag extends HtmlEscapingAwareTag { @Nullable private Object resolveImplicitVariable(String name) throws AccessException { - if (this.variableResolver == null) { + if (this.elContext == null) { return null; } try { - return this.variableResolver.resolveVariable(name); + return this.elContext.getELResolver().getValue(this.elContext, name, null); } catch (Exception ex) { throw new AccessException(