Java JSTL1.2 根据 TLD 或标签文件中的属性指令,属性 var 不接受任何表达式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21928366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 11:27:36  来源:igfitidea点击:

JSTL1.2 According to TLD or attribute directive in tag file, attribute var does not accept any expressions

javamavenjstljsp-tagstomcat8

提问by sethu

I have been searching all over google for an answer and it doesn't work.

我一直在谷歌上搜索答案,但没有用。

I am getting this error:

我收到此错误:

org.apache.jasper.JasperException: /WEB-INF/pages/calendarEntry.jsp (line: 5, column: 46) According to TLD or attribute directive in tag file, attribute var does not accept any expressions

org.apache.jasper.JasperException: /WEB-INF/pages/calendarEntry.jsp (line: 5, column: 46) 根据标记文件中的 TLD 或属性指令,属性 var 不接受任何表达式

Here's my jsp file

这是我的jsp文件

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <c:set var="eventDate" value="${calendarEntry.date}"/>
    <h1 class="page-header">Calendar Event on <fmt:formatDate value="date" var="${eventDate}" /></h1>

The error is happening at the last line. fmt

错误发生在最后一行。调剂

Web App declartion

网络应用声明

<web-app version="3.1"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd">

Maven Depedencies

Maven 依赖项

<dependency>
    <groupId>jstl</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>javax.servlet.jsp-api</artifactId>
    <version>2.3.0</version>
    <scope>provided</scope>
</dependency>

Deployment Environment - Tomcat 8

部署环境 - Tomcat 8

采纳答案by sethu

Thanks for helping everyone. I realised it was a stupid mistake from my side..

谢谢大家的帮助。我意识到这是我的一个愚蠢的错误..

Instead of

代替

<fmt:formatDate value="date" var="${eventDate}" />

It should be

它应该是

<fmt:formatDate type="date" value="${calendarEntry.date}"

回答by cbach

<fmt:formatDate value="date" var="${eventDate}" />

Switch value and var.

切换值和变量。

<fmt:formatDate var="date" value="${eventDate}" />

回答by lucumt

You should change attribute varto pattern,you can try as below:

您应该将属性var更改为pattern,您可以尝试如下:

<fmt:formatDate value="${eventDate}" pattern="yyyy-MM-dd HH:mm:ss"/>

<fmt:formatDate value="${eventDate}" pattern="yyyy-MM-dd HH:mm:ss"/>

You can change the value of patternbased on your own,and it has nothing to do with the order of valueand pattern

可以根据自己的情况更改pattern的值,与valuepattern的顺序无关

回答by Kimball Robinson

I had a similar problem, and this answer points to basically trying two different taglib declarations. Perhaps try both of them?

我有一个类似的问题,这个答案指向基本上尝试两个不同的 taglib 声明。也许两个都试试?

Format Date with fmt:formatDate JSP

使用 fmt:formatDate JSP 格式化日期

Switching to the taglib you have declared in your jsp file solved my problem, ironically.

具有讽刺意味的是,切换到您在 jsp 文件中声明的 taglib 解决了我的问题。

  <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

vs

对比

  <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>

回答by Hemantha

In netbeans it does not create a web.xml file automatically now.(previously in j2ee it was created. it is optional for some cases.I face the same issue with the jstl remove attribute and after I created the web.xml file the issue was gone.but corrected one is a new project

在 netbeans 中,它现在不会自动创建 web.xml 文件。(以前在 j2ee 中它是创建的。在某些情况下它是可选的。我遇到了与 jstl remove 属性相同的问题,并且在我创建了 web.xml 文件后问题不见了。但更正的是一个新项目

回答by Jayesh

I had similar issue. I changed Tomcat version to- apache-tomcat-7.0.39 instead of -apache-tomcat-7.0.54 from SERVER- Runtime Environment

我有类似的问题。我将 Tomcat 版本更改为 - apache-tomcat-7.0.39 而不是 SERVER- Runtime Environment 中的 -apache-tomcat-7.0.54