I started following one tutorial about JSTL tags. The repositories tutorial used are too old, so I wanted to try it my way using some newer versions. Unfortunately, I am stuck now. I will tell you what I did, so I hope, you can help me out.
I downloaded 2 jar files from these two links: api, implementation.
Jar files I got, I copied inside WebContent/Web-INF/lib
. Now if I do this, I get an error:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<body>
<c:set var="varA" value="hello world" />
<%=varA %> //varA cannot be resolved to a variable
</body>
</html>
To be honest I have no idea why we need import statement when jar files are literally in my project's lib
folder. Also, does anyone know what is wrong here and why editor can't find my variable varA?
The variables set using JSTL tags can not be accessed directly with a scriptlet. There can be two ways to access varA
.
1. Using JSTL tags:
<c:set var="varA" value="hello world" />
<c:out value="${varA }"></c:out>
2. Using pageContext.getAttribute
:
<c:set var="varA" value="hello world" />
<%=pageContext.getAttribute("varA")%>