嵌套 EL 函数

发布于 2024-11-06 21:12:35 字数 2424 浏览 0 评论 0原文

在 JSP 中执行此操作时,我遇到 EL 解析异常:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page import="my.InternalConstants"%>

[...]

<c:set var="MYPREFIX"><%=InternalConstants.MYPREFIX%></c:set>

[...]

<c:forEach var="name" items="${data.names}" varStatus="status">
    <c:set var="reducedName" value="${fn:substring(name, fn:length(MYPREFIX), fn:length(name))}"/> <-- here is where the exception occurs

我做错了什么?

谢谢。

更新:

这是例外:

view.jsp(86,94) --> JSPG0122E: Unable to parse EL function ${fn:substring(name, fn:length(MYPREFIX), fn:length(name)}).

at com.ibm.ws.jsp.translator.visitor.validator.ELValidator.validateElFunction(ELValidator.java:500)
at com.ibm.ws.jsp.translator.visitor.validator.ELValidator.validateELExpression(ELValidator.java:122)
at com.ibm.ws.jsp.translator.visitor.validator.ELValidator.validateELExpression(ELValidator.java:149)
at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.validateCustomTagAttribute(ValidateVisitor.java:1752)
at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.validateCustomTagAttributeValues(ValidateVisitor.java:1400)
at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.visitCustomTagStart(ValidateVisitor.java:294)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:366)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:234)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.visit(JspVisitor.java:216)
at com.ibm.ws.jsp.translator.JspTranslator.processVisitors(JspTranslator.java:127)

I am getting EL parsing exceptions when doing this in my JSP:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@page import="my.InternalConstants"%>

[...]

<c:set var="MYPREFIX"><%=InternalConstants.MYPREFIX%></c:set>

[...]

<c:forEach var="name" items="${data.names}" varStatus="status">
    <c:set var="reducedName" value="${fn:substring(name, fn:length(MYPREFIX), fn:length(name))}"/> <-- here is where the exception occurs

What am I doing wrong?

Thanks.

Update:

This is the exception:

view.jsp(86,94) --> JSPG0122E: Unable to parse EL function ${fn:substring(name, fn:length(MYPREFIX), fn:length(name)}).

at com.ibm.ws.jsp.translator.visitor.validator.ELValidator.validateElFunction(ELValidator.java:500)
at com.ibm.ws.jsp.translator.visitor.validator.ELValidator.validateELExpression(ELValidator.java:122)
at com.ibm.ws.jsp.translator.visitor.validator.ELValidator.validateELExpression(ELValidator.java:149)
at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.validateCustomTagAttribute(ValidateVisitor.java:1752)
at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.validateCustomTagAttributeValues(ValidateVisitor.java:1400)
at com.ibm.ws.jsp.translator.visitor.validator.ValidateVisitor.visitCustomTagStart(ValidateVisitor.java:294)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:366)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:369)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processChildren(JspVisitor.java:419)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.processJspElement(JspVisitor.java:234)
at com.ibm.ws.jsp.translator.visitor.JspVisitor.visit(JspVisitor.java:216)
at com.ibm.ws.jsp.translator.JspTranslator.processVisitors(JspTranslator.java:127)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜`诱少女 2024-11-13 21:12:35

如果您一直在使用 WebSphere 8,您的问题似乎与 问题:17744158

If you have been using the WebSphere 8 your issue seems to be related with question:17744158

做个ˇ局外人 2024-11-13 21:12:35

我已经按照以下方式使用了您的代码。它工作正常。

JSP file

<%@page import="com.Utils"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<c:set var="MYPREFIX"><%=Utils.MYPREFIX%></c:set>
<c:forEach var="name" items="${names}" varStatus="status">
    <c:set var="reducedName"
        value="${fn:substring(name, fn:length(MYPREFIX), fn:length(name))}" />
        ${reducedName}
</c:forEach>



Controller File


@WebServlet("/HomeController")
public class HomeController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public HomeController() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");

        List<String> list = new ArrayList<>();
        list.add("Ahasdasdadas");
        list.add("Ah1213232");

        request.setAttribute("names", list);
        RequestDispatcher rd = request.getRequestDispatcher("one.jsp");
        rd.forward(request, response);
    }

}

Utils

package com;

public class Utils {
    public static String MYPREFIX = "AH";
}

I have used you code with following way.Its working fine.

JSP file

<%@page import="com.Utils"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<c:set var="MYPREFIX"><%=Utils.MYPREFIX%></c:set>
<c:forEach var="name" items="${names}" varStatus="status">
    <c:set var="reducedName"
        value="${fn:substring(name, fn:length(MYPREFIX), fn:length(name))}" />
        ${reducedName}
</c:forEach>



Controller File


@WebServlet("/HomeController")
public class HomeController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public HomeController() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");

        List<String> list = new ArrayList<>();
        list.add("Ahasdasdadas");
        list.add("Ah1213232");

        request.setAttribute("names", list);
        RequestDispatcher rd = request.getRequestDispatcher("one.jsp");
        rd.forward(request, response);
    }

}

Utils

package com;

public class Utils {
    public static String MYPREFIX = "AH";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文