自上课以来:org.springframework.web.util.ExpressionEvaluationUtils 自Spring 3.x发布以来已被弃用,我正在寻找我的java代码中EL表达式评估的另一种选择。
阅读JSP 2.x文档后,我确实设法构建了另一种方法:
import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.servlet.jsp.JspApplicationContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspFactory;
import javax.servlet.jsp.PageContext;
public class ExpressionEvaluationUtils {
public static Object evaluate(String exp, Class<?> resultClass, PageContext pageContext)
throws JspException {
if (pageContext == null){
return exp;
}
ELContext elContext = pageContext.getELContext();
JspFactory jf = JspFactory.getDefaultFactory();
JspApplicationContext jac = jf
.getJspApplicationContext(pageContext.getServletContext());
ExpressionFactory ef = jac.getExpressionFactory();
ValueExpression val = ef.createValueExpression(elContext, exp, resultClass);
return val.getValue(elContext);
}
}
您能为我的实施建议更多替代方案吗?
答案 0 :(得分:0)
您可以使用以下任何项目: