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

6

5

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

Here's my jsp file

<%@ 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

<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

Mielke answered 21/2, 2014 at 7:48 Comment(0)
M
3

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}"
Mielke answered 22/2, 2014 at 4:31 Comment(1)
Would sure help if you left comment before down voting.Mielke
S
16

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

Format Date with fmt:formatDate JSP

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

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

vs

  <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
Stramonium answered 23/2, 2016 at 23:28 Comment(0)
M
4
<fmt:formatDate value="date" var="${eventDate}" />

Switch value and var.

<fmt:formatDate var="date" value="${eventDate}" />
Maulstick answered 21/2, 2014 at 7:50 Comment(0)
M
3

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}"
Mielke answered 22/2, 2014 at 4:31 Comment(1)
Would sure help if you left comment before down voting.Mielke
A
0

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

Aeriel answered 20/12, 2016 at 11:10 Comment(0)
D
0
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

Change the above to:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
Discontented answered 7/8, 2020 at 5:50 Comment(0)
R
-1

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

Remainder answered 4/9, 2017 at 7:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.