2

I want to pass a variable in tag file. My code here:

layout.tag

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@tag description="My layout" pageEncoding="UTF-8"%>
<%@attribute name="title" type="java.lang.String" required="true" %>  
<!DOCTYPE html>
<html>
<head>
    <title>My site | <c:out value="${title}" /></title>
</head>
<body>
</body>
</html>

index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="mySite" tagdir="/WEB-INF/tags" %>
<mySite:layout title="home">
</mySite:layout>`

But <c:out value="${title} />" always return ${title}. I tried with ${title} and got the same result. I dont know why...

ducdhm
  • 1,954
  • 15
  • 26

1 Answers1

2

1.)add <%@ attribute name="greeting" required="true" %> in .tag file, change the name as per you convinence
2.) <tag:mytag greeting="Satish"> pass the values like this