JSP pass var to css style

1k views Asked by At

Hi below is what I am trying to do:

<!DOCTYPE html>
<html lang="en">
    <c:if test="${!empty mainThemeSection}">
        <c:set var="mainTheme" value="${ mainThemeSection[0] }" />
    </c:if>
<head>
    <style>
        .text-primary {
            color: '${mainTheme.themeColour}';
        }
    </style>
</head>

<body>
..
</body>

</html>

the ${mainThemeSection.themeColour} value is red or #FFFFFF this type of string value. I am trying to pass a var generated in JSP to head style css so make this css bit more dynamic But it is not working ... (jsp and java code for themeColour definitely works) Any suggestion? Thanks

1

There are 1 answers

0
yılmaz On

Declare color on top of page:

<%String color=request.getAttribute("color");%>

And change

color: '${mainTheme.themeColour}';

to

color: '<%=color%>';