0

I have a tag file which defines a bunch of attributes. I want to be able to access the attribute inside a script defined inside the custom tag.

sample.tag


<@tag language="java" pandeEncoding="UTF-8"%>
<%@ attribute name="dummy" required="false" type="java.lang.String" %>

<script>
 console.log(  "value:  " + dummy );
</script>

Not sure im asking something very obvious, but all the google result talks about retrieving an attribute from a tag but i want to get it within the tag definition. So do not have the tag id or name.

broun
  • 2,483
  • 5
  • 40
  • 55

1 Answers1

1

Try this:

<%@ tag language="java" pageEncoding="UTF-8" %>
<%@ attribute name="dummy" required="false" type="java.lang.String" %>

<script>
 console.log(  "value:  ${dummy}" );
</script>

If your attribute is user controlled input, it's better to escape your attribute. The JSTL core library can help:

<%@ tag language="java" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ attribute name="dummy" required="false" type="java.lang.String" %>

<script>
 console.log(  "value:  <c:out value="${dummy}" /> );
</script>
Community
  • 1
  • 1
Gummyball
  • 220
  • 3
  • 10