anirvan
anirvan

Reputation: 4877

JSTL taglib issue

I have a simple maven web project. I simply can't figure out a way to have the JSTL tags work. For testing purposes, I've created a dummy project having no dependency except for:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>

in my JSP page, I have the following test code -

<c:set var="hello" value="see this?"/>
<c:out value="${hello}"></c:out>
<h2>${hello}</h2>
<br/>
<%=request.getAttribute("hello") %>

I have also included the jstl declaration on the top - <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

However, this does not seem to work. Surprisingly, the ${hello} doesn't show anything meaningful, but the request.getAttribute... does. This means that the c:set is actually working, and both the c:out and simple expression do NOT work. Am I missing out something here?

Any help is appreciated - been trying to get my head around this for 3 days now!

Upvotes: 1

Views: 2200

Answers (2)

anirvan
anirvan

Reputation: 4877

The solution lies in checking out the info document on JSTL provided within StackOverflow. It mentions almost everything there is to know about why your JSTL installation may not be working properly.

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691625

The JSTL jar only contains the standard classes and interfaces of the spec, but no implementation for the tags.

Add this dependency to your pom :

<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

BTW, always look at the generated HTML code to see what's going on. And the c:set tag sets a page scope attribute, not a request scope attribute, so the fact that request.getAttribute("hello") outputs something doesn't have anything to do with the c:set tag placed before.

Upvotes: 1

Related Questions