javax.el.ELException: 无法解析表达式 [${fn:escapeXml(user.lastName) += ', ' += fn:escapeXml(user.firstName)}]

javax.el.ELException: Failed to parse the expression [${fn:escapeXml(user.lastName) += ', ' += fn:escapeXml(user.firstName)}]

我正在尝试通过 eclipse 在 tomcat7 上创建简单的项目。 这是我的 jsp 页面的代码:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
    <body>
        User ID: ${user.userId}<br />
        Username: ${user.username} (${user.username.length()} characters)<br />
        Full Name: ${fn:escapeXml(user.lastName) += ', '
            += fn:escapeXml(user.firstName)}
        <br /><br />
        <b>Permissions (${fn:length(user.permissions)})</b><br />
        User: ${user.permissions["user"]}<br />
        Moderator: ${user.permissions["moderator"]}<br />
        Administrator: ${user.permissions["admin"]}<br />
    </body>
</html>

这是浏览器的结果 window:

org.apache.jasper.JasperException: javax.el.ELException: Failed to parse the expression [${fn:escapeXml(user.lastName) += ', '
        += fn:escapeXml(user.firstName)}]
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:549)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
ProfileServlet.doGet(ProfileServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

 root cause

 javax.el.ELException: Failed to parse the expression [${fn:escapeXml(user.lastName) += ', '
        += fn:escapeXml(user.firstName)}]
org.apache.el.lang.ExpressionBuilder.createNodeInternal(ExpressionBuilder.java:145)
org.apache.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:171)
org.apache.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:216)
org.apache.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:66)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:943)
org.apache.jsp.WEB_002dINF.jsp.view.profile_jsp._jspService(profile_jsp.java:96)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
ProfileServlet.doGet(ProfileServlet.java:46)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)

  root cause

   org.apache.el.parser.ParseException: Encountered " <ILLEGAL_CHARACTER> "= "" at line 1, column 32.

目标运行时已设置(tomcat7)。 可能我的 tomcat7/lib 目录有问题? (jstl 1.2 jar 在文件夹中)

这里还有来自 base.jspf 的导入(这是所有 JSP 的 header)

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

"Regular" jstl 标签效果很好。功能问题

尝试像这样使用 core:out :

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    User ID: <c:out value="${user.userId}" />
    <br /> Username: <c:out value="${user.username}" /> (<c:out value="${user.username.length}" /> characters)
    <br /> Full Name: <c:out value="${user.lastName}" />, <c:out value="${user.firstName}" />
    <br />
    <br />
    <b>Permissions (${fn:length(user.permissions)})</b>
    <br /> User: <c:out value="${user.permissions.user}" />
    <br /> Moderator: <c:out value="${user.permissions.moderator}" />
    <br /> Administrator: <c:out value="${user.permissions.admin}" />
    <br />
</body>
</html>

它对我来说很好,它默认转义 XML。