【问题标题】:Why my jsp con't get the right data when using the jstl and spring mvc为什么我的jsp在使用jstl和spring mvc时不能得到正确的数据
【发布时间】:2016-01-18 09:48:15
【问题描述】:

当我使用spring-mvc从数据库中给出一个名为user的模型,然后尝试使用jstl标签将数据绑定到jsp时,它给我一个错误:

${userInfo..getName()}" contains invalid expression(s): javax.el.ELException: Failed to parse the expression [${userInfo..getName()}]] with root cause

数据绑定代码:

User user = userService.getUserByAccount(account);
        if (checkUser(user) && checkUserLogin(user.getAccount(), session)) {
            model.addAttribute("userInfo", user);
        } else {
            return "redirect:/login.html";
        }
        return "user/userInfo";

jsp:

<h3> <c:out value="${userInfo.getName()}"></c:out>Welcome </h3>
<dl><dt> Phone </dt> <dd>
<c:out value="${userInfo.getPhone()}"></c:out></dd></dl> 

【问题讨论】:

  • 抱歉问了这么愚蠢的问题。我发现我的代码错误。结果是我在上层代码中使用了 ${userInfo..getName()}。

标签: jsp spring-mvc jstl el


【解决方案1】:

您的表达式错误(在堆栈跟踪中报告)。它包含两个点:

${userInfo..getName()}

尝试将其更改为。

${userInfo.getName()}

【讨论】:

  • 我整合了这个答案:此外,您应该引用属性而不是方法。如果要检索 name 值,请执行以下操作:${userInfo.name}
【解决方案2】:

尝试使用 ${userInfo.name} 和 ${userInfo.phone}

【讨论】:

    猜你喜欢
    • 2018-03-20
    • 2010-11-04
    • 1970-01-01
    • 2020-08-31
    • 2023-04-03
    • 1970-01-01
    • 2017-08-22
    • 1970-01-01
    • 2011-11-27
    相关资源
    最近更新 更多